From fee0c64a8f8d6237f94457b608cc09614514f9b5 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周六, 23 12月 2023 15:00:35 +0800 Subject: [PATCH] Fix window overflow --- src/core/contexts/abstractwindowcontext.cpp | 4 ++-- examples/mainwindow/dark-style.qss | 4 ++-- examples/mainwindow/mainwindow.cpp | 17 +++++++++++++---- src/core/contexts/win32windowcontext.cpp | 20 ++++++++++++++------ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/examples/mainwindow/dark-style.qss b/examples/mainwindow/dark-style.qss index e3820a0..e01c0dc 100644 --- a/examples/mainwindow/dark-style.qss +++ b/examples/mainwindow/dark-style.qss @@ -37,7 +37,7 @@ QWK--WindowBar>QAbstractButton#min-button:hover, QWK--WindowBar>QAbstractButton#min-button:pressed { - background-color: rgba(0, 0, 0, 15%); + background-color: rgba(255, 255, 255, 15%); } QWK--WindowBar>QAbstractButton#max-button { @@ -47,7 +47,7 @@ QWK--WindowBar>QAbstractButton#max-button:hover, QWK--WindowBar>QAbstractButton#max-button:pressed { - background-color: rgba(0, 0, 0, 15%); + background-color: rgba(255, 255, 255, 15%); } QWK--WindowBar>QAbstractButton#close-button { diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp index e693228..86420ac 100644 --- a/examples/mainwindow/mainwindow.cpp +++ b/examples/mainwindow/mainwindow.cpp @@ -143,7 +143,9 @@ auto dwmBlurAction = new QAction(tr("Enable DWM blur"), menuBar); dwmBlurAction->setCheckable(true); connect(dwmBlurAction, &QAction::triggered, this, [this](bool checked) { - windowAgent->setWindowAttribute(QStringLiteral("dwm-blur"), checked); + if (!windowAgent->setWindowAttribute(QStringLiteral("dwm-blur"), checked)) { + return; + } setProperty("custom-style", checked); style()->polish(this); }); @@ -151,7 +153,10 @@ auto acrylicAction = new QAction(tr("Enable acrylic material"), menuBar); acrylicAction->setCheckable(true); connect(acrylicAction, &QAction::triggered, this, [this](bool checked) { - windowAgent->setWindowAttribute(QStringLiteral("acrylic-material"), QColor::fromRgbF(1.f, 1.f, 1.f, 0.6f)); + if (!windowAgent->setWindowAttribute(QStringLiteral("acrylic-material"), + QColor::fromRgbF(1.f, 1.f, 1.f, 0.6f))) { + return; + } setProperty("custom-style", checked); style()->polish(this); }); @@ -159,7 +164,9 @@ auto micaAction = new QAction(tr("Enable mica"), menuBar); micaAction->setCheckable(true); connect(micaAction, &QAction::triggered, this, [this](bool checked) { - windowAgent->setWindowAttribute(QStringLiteral("mica"), checked); + if (!windowAgent->setWindowAttribute(QStringLiteral("mica"), checked)) { + return; + } setProperty("custom-style", checked); style()->polish(this); }); @@ -167,7 +174,9 @@ auto micaAltAction = new QAction(tr("Enable mica alt"), menuBar); micaAltAction->setCheckable(true); connect(micaAltAction, &QAction::triggered, this, [this](bool checked) { - windowAgent->setWindowAttribute(QStringLiteral("mica-alt"), checked); + if (!windowAgent->setWindowAttribute(QStringLiteral("mica-alt"), checked)) { + return; + } setProperty("custom-style", checked); style()->polish(this); }); diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp index d2da16f..de9674c 100644 --- a/src/core/contexts/abstractwindowcontext.cpp +++ b/src/core/contexts/abstractwindowcontext.cpp @@ -54,7 +54,7 @@ if (!attribute.isValid()) { return true; } - if (m_windowHandle && !windowAttributeChanged(key, attribute, {})) { + if (!m_windowHandle || !windowAttributeChanged(key, attribute, {})) { return false; } m_windowAttributes.insert(key, attribute); @@ -63,7 +63,7 @@ if (it.value() == attribute) return true; - if (m_windowHandle && !windowAttributeChanged(key, attribute, it.value())) { + if (!m_windowHandle || !windowAttributeChanged(key, attribute, it.value())) { return false; } diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index 19f1864..27450d9 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -722,12 +722,15 @@ DynamicApis::instance().pDwmExtendFrameIntoClientArea(hWnd, &margins); } -#if !QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER) { auto style = ::GetWindowLongPtrW(hWnd, GWL_STYLE); - ::SetWindowLongPtrW(hWnd, GWL_STYLE, (style | WS_THICKFRAME) & (~WS_CAPTION)); - } +#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER) + ::SetWindowLongPtrW(hWnd, GWL_STYLE, style & (~WS_SYSMENU)); +#else + ::SetWindowLongPtrW(hWnd, GWL_STYLE, + (style | WS_THICKFRAME | WS_CAPTION) & (~WS_SYSMENU)); #endif + } // Add managed window addManagedWindow(m_windowHandle, hWnd, this); @@ -947,9 +950,9 @@ } for (const auto attr : { - _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, - _DWMWA_USE_IMMERSIVE_DARK_MODE, - }) { + _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1, + _DWMWA_USE_IMMERSIVE_DARK_MODE, + }) { apis.pDwmSetWindowAttribute(hwnd, attr, &enable, sizeof(enable)); } @@ -1810,11 +1813,16 @@ // a window when it's maximized unless you restore it). const quint32 frameSize = getResizeBorderThickness(hWnd); clientRect->top += frameSize; + +#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER) if (!isWin10OrGreater()) { +#endif clientRect->bottom -= frameSize; clientRect->left += frameSize; clientRect->right -= frameSize; +#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER) } +#endif } // Attempt to detect if there's an autohide taskbar, and if // there is, reduce our size a bit on the side with the taskbar, -- Gitblit v1.9.1