diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-03 16:10:40 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-25 20:33:25 +0100 |
commit | eb26563dd5483ab83a7a5addf8f98a4921d1edc1 (patch) | |
tree | 198736cbc2159fa4c66f7dd175195926e1815e07 /src/plugins | |
parent | 12f085e538a1e3060fc5be3e21cefbb6d4c492b5 (diff) |
Windows QPA: Add setting of dark window borders
Implement dark mode support level 1: change the
window borders to dark and back, tracking the
activation of dark mode.
Task-number: QTBUG-72028
Change-Id: I6e8b31e7ee574f4d90438405f361cd940faee7fd
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 5 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 44 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.h | 3 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index d322b0e92b..5578259399 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1221,6 +1221,11 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, auto nativeInterface = static_cast<QWindowsNativeInterface *>(QWindowsIntegration::instance()->nativeInterface()); emit nativeInterface->darkModeChanged(darkMode); + const auto options = QWindowsIntegration::instance()->options(); + if ((options & QWindowsIntegration::DarkModeWindowFrames) != 0) { + for (QWindowsWindow *w : d->m_windows) + w->setDarkBorder(QWindowsContextPrivate::m_darkMode); + } } return d->m_screenManager.handleScreenChanges(); } diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index a7aad15749..b7536066d0 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -749,6 +749,11 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag } } +static inline bool shouldApplyDarkFrame(const QWindow *w) +{ + return w->isTopLevel() && !w->flags().testFlag(Qt::FramelessWindowHint); +} + QWindowsWindowData WindowCreationData::create(const QWindow *w, const WindowData &data, QString title) const { @@ -816,6 +821,12 @@ QWindowsWindowData return result; } + if (QWindowsContext::isDarkMode() + && (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeWindowFrames) != 0 + && shouldApplyDarkFrame(w)) { + QWindowsWindow::setDarkBorderToWindow(result.hwnd, true); + } + if (mirrorParentWidth != 0) { context->obtainedPos.setX(mirrorParentWidth - context->obtainedSize.width() - context->obtainedPos.x()); @@ -2892,6 +2903,39 @@ bool QWindowsWindow::isTopLevel() const return window()->isTopLevel() && !m_data.embedded; } +enum : WORD { + DwmwaUseImmersiveDarkMode = 20, + DwmwaUseImmersiveDarkModeBefore20h1 = 19 +}; + +static bool queryDarkBorder(HWND hwnd) +{ + BOOL result = FALSE; + const bool ok = + SUCCEEDED(DwmGetWindowAttribute(hwnd, DwmwaUseImmersiveDarkMode, &result, sizeof(result))) + || SUCCEEDED(DwmGetWindowAttribute(hwnd, DwmwaUseImmersiveDarkModeBefore20h1, &result, sizeof(result))); + if (!ok) + qWarning("%s: Unable to retrieve dark window border setting.", __FUNCTION__); + return result == TRUE; +} + +bool QWindowsWindow::setDarkBorderToWindow(HWND hwnd, bool d) +{ + const BOOL darkBorder = d ? TRUE : FALSE; + const bool ok = + SUCCEEDED(DwmSetWindowAttribute(hwnd, DwmwaUseImmersiveDarkMode, &darkBorder, sizeof(darkBorder))) + || SUCCEEDED(DwmSetWindowAttribute(hwnd, DwmwaUseImmersiveDarkModeBefore20h1, &darkBorder, sizeof(darkBorder))); + if (!ok) + qWarning("%s: Unable to set dark window border.", __FUNCTION__); + return ok; +} + +void QWindowsWindow::setDarkBorder(bool d) +{ + if (shouldApplyDarkFrame(window()) && queryDarkBorder(m_data.hwnd) != d) + setDarkBorderToWindow(m_data.hwnd, d); +} + QWindowsMenuBar *QWindowsWindow::menuBar() const { return m_menuBar.data(); diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 1f8800272b..7c37c6b115 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -287,6 +287,9 @@ public: HWND handle() const override { return m_data.hwnd; } bool isTopLevel() const override; + static bool setDarkBorderToWindow(HWND hwnd, bool d); + void setDarkBorder(bool d); + QWindowsMenuBar *menuBar() const; void setMenuBar(QWindowsMenuBar *mb); |