Skip to content

Commit

Permalink
Windows: better handling of darkmode support
Browse files Browse the repository at this point in the history
43ef220 turned dark mode support on for
both styling and window frames. However, the default palette and style
support in Qt is too incomplete, resulting in unreadable UIs when using
certain styles (e.g. fusion). Also the vista style is not supporting
dark mode.

If we don't turn on dark style support, then dark frame support doesn't
look good either. However, many application developers have implement a
dark theme themselves, and we should have a dark frame for those
applications.

So partially revert 43ef220 so that
dark style support is disabled by default, and leave dark frame support
on. However, only activate dark frames if the palette is dark, i.e. if
the window background color in the default palette is darker than the
text color (or if DarkModeStyle is explicitly turned on by running the
application with -platform windows:darkmode=2).

This way, dark-themed applications get a dark frame on dark Windows, and
a light frame on light Windows; and light-themed applications (including
default Qt applications) get a light frame all the time.

Fixes: QTBUG-72028
Pick-to: 6.4
Change-Id: I61f1b1e43b2a4ba69848d5d8bec921c0790fe511
Reviewed-by: Marius Kittler <[email protected]>
Reviewed-by: Oliver Wolff <[email protected]>
  • Loading branch information
vohi committed Jul 19, 2022
1 parent 0d91f85 commit 5ea7e3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/plugins/platforms/windows/qwindowscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,14 +1103,14 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
if (darkMode != QWindowsContextPrivate::m_darkMode) {
QWindowsContextPrivate::m_darkMode = darkMode;
auto integration = QWindowsIntegration::instance();
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) {
for (QWindowsWindow *w : d->m_windows)
w->setDarkBorder(QWindowsContextPrivate::m_darkMode);
}
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) {
QWindowsTheme::instance()->refresh();
QWindowSystemInterface::handleThemeChange();
}
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) {
for (QWindowsWindow *w : d->m_windows)
w->setDarkBorder(QWindowsContextPrivate::m_darkMode);
}
}
}
return d->m_screenManager.handleScreenChanges();
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/platforms/windows/qwindowsintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ void QWindowsIntegrationPrivate::parseOptions(QWindowsIntegration *q, const QStr
QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorV2DpiAware;

int tabletAbsoluteRange = -1;
DarkModeHandling darkModeHandling = DarkModeHandlingFlag::DarkModeWindowFrames
| DarkModeHandlingFlag::DarkModeStyle;
DarkModeHandling darkModeHandling = DarkModeHandlingFlag::DarkModeWindowFrames;
m_options = ::parseOptions(paramList, &tabletAbsoluteRange, &dpiAwareness, &darkModeHandling);
q->setDarkModeHandling(darkModeHandling);
QWindowsFontDatabase::setFontOptions(m_options);
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/platforms/windows/qwindowswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,15 @@ 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);
if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
return false;
if (QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle))
return true;
// 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;
return defaultPalette.color(QPalette::WindowText).lightness()
> defaultPalette.color(QPalette::Window).lightness();
}

QWindowsWindowData
Expand Down

0 comments on commit 5ea7e3a

Please sign in to comment.