Windows: simplify setting the dark border

A round trip through querying the window attribute to avoid a
call to the setter is overkill, we can assume that the setter won't
do anything if the value of the attribute doesn't change.

Also, don't check whether QWindowsIntegration::darkModeHandling
is overridden before calling setDarkMode, which checks that flag
already. The flag will be very rarely cleared (and we might want
to remove support for this obscure mechanism soon).

Task-number: QTBUG-124490
Change-Id: I7e027fd53f556200edfd127eaf5f2b97f027528e
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
bb10
Volker Hilsheimer 2024-05-02 17:16:58 +02:00
parent a1371783ac
commit 2c5f5bf2e8
2 changed files with 2 additions and 17 deletions

View File

@ -564,10 +564,8 @@ void QWindowsTheme::handleSettingsChanged()
QWindowSystemInterface::handleThemeChange();
}
if (colorSchemeChanged) {
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) {
for (QWindowsWindow *w : std::as_const(QWindowsContext::instance()->windows()))
w->setDarkBorder(s_colorScheme == Qt::ColorScheme::Dark);
}
for (QWindowsWindow *w : std::as_const(QWindowsContext::instance()->windows()))
w->setDarkBorder(s_colorScheme == Qt::ColorScheme::Dark);
}
}

View File

@ -3286,17 +3286,6 @@ enum : WORD {
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)
qCWarning(lcQpaWindow, "%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;
@ -3312,8 +3301,6 @@ void QWindowsWindow::setDarkBorder(bool 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);
}