summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-11-25 13:54:06 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-12-01 06:59:15 +0000
commit29e9766189b8672610ced528a35bfb85de0b1962 (patch)
tree589cf83f0cfe2bba264ef232b9b88a16e18d2395
parentc9837c84aaeebb6ef2420c576969fd7b46822d71 (diff)
Windows: Reevaluate dark frames if the application palette changes
Since 5ea7e3a8111b2939f0c91b750aa1c62ab16ab715 we are using dark window frames if the default palette is dark, unless applications explicitly override dark frame support. If the palette changes during runtime, we didn't reevaluate that setting. Do that by handling ApplicationPaletteChange events in QWindowsWindow. We still have to respect an explicit opt-out. Simplify the code at the call sites of setDarkBorder(), we don't need to check all the time whether the application has opted out of dark frame support. Task-number: QTBUG-72028 Change-Id: I94e7d33cd21f9656ca210b43e775f487abc25b54 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit f32aa06f4f925e9a14db1bf76918358480b98b6a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index dc7ecc2570..c996bb30de 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -851,8 +851,9 @@ static inline bool shouldApplyDarkFrame(const QWindow *w)
{
if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
return false;
- if (QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle))
- return true;
+ // the application has explicitly opted out of dark frames
+ if (!QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames))
+ return false;
// if the application supports a dark border, and the palette is dark (window background color
// is darker than the text), then turn dark-border support on, otherwise use a light border.
const QPalette defaultPalette;
@@ -927,11 +928,8 @@ QWindowsWindowData
return result;
}
- if (QWindowsContext::isDarkMode()
- && QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)
- && shouldApplyDarkFrame(w)) {
- QWindowsWindow::setDarkBorderToWindow(result.hwnd, true);
- }
+ QWindowsWindow::setDarkBorderToWindow(result.hwnd, QWindowsContext::isDarkMode()
+ && shouldApplyDarkFrame(w));
if (mirrorParentWidth != 0) {
context->obtainedPos.setX(mirrorParentWidth - context->obtainedSize.width()
@@ -2608,6 +2606,9 @@ void QWindowsWindow::setExStyle(unsigned s) const
bool QWindowsWindow::windowEvent(QEvent *event)
{
switch (event->type()) {
+ case QEvent::ApplicationPaletteChange:
+ setDarkBorder(QWindowsContext::isDarkMode());
+ break;
case QEvent::WindowBlocked: // Blocked by another modal window.
setEnabled(false);
setFlag(BlockedByModal);
@@ -3179,8 +3180,12 @@ bool QWindowsWindow::setDarkBorderToWindow(HWND hwnd, bool d)
void QWindowsWindow::setDarkBorder(bool d)
{
- if (shouldApplyDarkFrame(window()) && queryDarkBorder(m_data.hwnd) != d)
- setDarkBorderToWindow(m_data.hwnd, d);
+ // respect explicit opt-out and incompatible palettes or styles
+ d = d && shouldApplyDarkFrame(window());
+ if (queryDarkBorder(m_data.hwnd) == d)
+ return;
+
+ setDarkBorderToWindow(m_data.hwnd, d);
}
QWindowsMenuBar *QWindowsWindow::menuBar() const