Windows QPA: Move dark mode handling to the new interface
Move options to new interface, making them settable from code on this occasion. Task-number: QTBUG-83252 Change-Id: Idd80667c502a8cde5d7c66d7e597ea34c22738e7 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
f06dfb60b9
commit
6d4b3582ad
@ -390,6 +390,13 @@ struct Q_GUI_EXPORT QWindowsApplication
|
|||||||
|
|
||||||
Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
|
Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
|
||||||
|
|
||||||
|
enum DarkModeHandlingFlag {
|
||||||
|
DarkModeWindowFrames = 0x1,
|
||||||
|
DarkModeStyle = 0x2
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_FLAGS(DarkModeHandling, DarkModeHandlingFlag)
|
||||||
|
|
||||||
virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
|
virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
|
||||||
virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
|
virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
|
||||||
|
|
||||||
@ -400,6 +407,11 @@ struct Q_GUI_EXPORT QWindowsApplication
|
|||||||
|
|
||||||
virtual bool isWinTabEnabled() const = 0;
|
virtual bool isWinTabEnabled() const = 0;
|
||||||
virtual bool setWinTabEnabled(bool enabled) = 0;
|
virtual bool setWinTabEnabled(bool enabled) = 0;
|
||||||
|
|
||||||
|
virtual bool isDarkMode() const = 0;
|
||||||
|
|
||||||
|
virtual DarkModeHandling darkModeHandling() const = 0;
|
||||||
|
virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
|
||||||
};
|
};
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
|
|
||||||
@ -407,6 +419,7 @@ struct Q_GUI_EXPORT QWindowsApplication
|
|||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformInterface::Private::QWindowsApplication::DarkModeHandling)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -94,4 +94,19 @@ bool QWindowsApplication::setWinTabEnabled(bool enabled)
|
|||||||
return enabled ? ctx->initTablet() : ctx->disposeTablet();
|
return enabled ? ctx->initTablet() : ctx->disposeTablet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QWindowsApplication::isDarkMode() const
|
||||||
|
{
|
||||||
|
return QWindowsContext::isDarkMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWindowsApplication::DarkModeHandling QWindowsApplication::darkModeHandling() const
|
||||||
|
{
|
||||||
|
return m_darkModeHandling;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QWindowsApplication::setDarkModeHandling(QWindowsApplication::DarkModeHandling handling)
|
||||||
|
{
|
||||||
|
m_darkModeHandling = handling;
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -58,9 +58,14 @@ public:
|
|||||||
bool isWinTabEnabled() const override;
|
bool isWinTabEnabled() const override;
|
||||||
bool setWinTabEnabled(bool enabled) override;
|
bool setWinTabEnabled(bool enabled) override;
|
||||||
|
|
||||||
|
bool isDarkMode() const override;
|
||||||
|
DarkModeHandling darkModeHandling() const override;
|
||||||
|
void setDarkModeHandling(DarkModeHandling handling) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow;
|
WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow;
|
||||||
TouchWindowTouchTypes m_touchWindowTouchTypes = NormalTouch;
|
TouchWindowTouchTypes m_touchWindowTouchTypes = NormalTouch;
|
||||||
|
DarkModeHandling m_darkModeHandling;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -1244,15 +1244,12 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
|
|||||||
const bool darkMode = QWindowsTheme::queryDarkMode();
|
const bool darkMode = QWindowsTheme::queryDarkMode();
|
||||||
if (darkMode != QWindowsContextPrivate::m_darkMode) {
|
if (darkMode != QWindowsContextPrivate::m_darkMode) {
|
||||||
QWindowsContextPrivate::m_darkMode = darkMode;
|
QWindowsContextPrivate::m_darkMode = darkMode;
|
||||||
auto nativeInterface =
|
auto integration = QWindowsIntegration::instance();
|
||||||
static_cast<QWindowsNativeInterface *>(QWindowsIntegration::instance()->nativeInterface());
|
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) {
|
||||||
emit nativeInterface->darkModeChanged(darkMode);
|
|
||||||
const auto options = QWindowsIntegration::instance()->options();
|
|
||||||
if ((options & QWindowsIntegration::DarkModeWindowFrames) != 0) {
|
|
||||||
for (QWindowsWindow *w : d->m_windows)
|
for (QWindowsWindow *w : d->m_windows)
|
||||||
w->setDarkBorder(QWindowsContextPrivate::m_darkMode);
|
w->setDarkBorder(QWindowsContextPrivate::m_darkMode);
|
||||||
}
|
}
|
||||||
if ((options & QWindowsIntegration::DarkModeStyle) != 0) {
|
if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) {
|
||||||
QWindowsTheme::instance()->refresh();
|
QWindowsTheme::instance()->refresh();
|
||||||
for (QWindowsWindow *w : d->m_windows)
|
for (QWindowsWindow *w : d->m_windows)
|
||||||
QWindowSystemInterface::handleThemeChange(w->window());
|
QWindowSystemInterface::handleThemeChange(w->window());
|
||||||
|
@ -135,9 +135,11 @@ QT_BEGIN_NAMESPACE
|
|||||||
struct QWindowsIntegrationPrivate
|
struct QWindowsIntegrationPrivate
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY_MOVE(QWindowsIntegrationPrivate)
|
Q_DISABLE_COPY_MOVE(QWindowsIntegrationPrivate)
|
||||||
explicit QWindowsIntegrationPrivate(const QStringList ¶mList);
|
explicit QWindowsIntegrationPrivate() = default;
|
||||||
~QWindowsIntegrationPrivate();
|
~QWindowsIntegrationPrivate();
|
||||||
|
|
||||||
|
void parseOptions(QWindowsIntegration *q, const QStringList ¶mList);
|
||||||
|
|
||||||
unsigned m_options = 0;
|
unsigned m_options = 0;
|
||||||
QWindowsContext m_context;
|
QWindowsContext m_context;
|
||||||
QPlatformFontDatabase *m_fontDatabase = nullptr;
|
QPlatformFontDatabase *m_fontDatabase = nullptr;
|
||||||
@ -181,9 +183,13 @@ bool parseIntOption(const QString ¶meter,const QLatin1String &option,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using DarkModeHandlingFlag = QPlatformInterface::Private::QWindowsApplication::DarkModeHandlingFlag;
|
||||||
|
using DarkModeHandling = QPlatformInterface::Private::QWindowsApplication::DarkModeHandling;
|
||||||
|
|
||||||
static inline unsigned parseOptions(const QStringList ¶mList,
|
static inline unsigned parseOptions(const QStringList ¶mList,
|
||||||
int *tabletAbsoluteRange,
|
int *tabletAbsoluteRange,
|
||||||
QtWindows::ProcessDpiAwareness *dpiAwareness)
|
QtWindows::ProcessDpiAwareness *dpiAwareness,
|
||||||
|
DarkModeHandling *darkModeHandling)
|
||||||
{
|
{
|
||||||
unsigned options = 0;
|
unsigned options = 0;
|
||||||
for (const QString ¶m : paramList) {
|
for (const QString ¶m : paramList) {
|
||||||
@ -223,9 +229,10 @@ static inline unsigned parseOptions(const QStringList ¶mList,
|
|||||||
} else if (param == u"reverse") {
|
} else if (param == u"reverse") {
|
||||||
options |= QWindowsIntegration::RtlEnabled;
|
options |= QWindowsIntegration::RtlEnabled;
|
||||||
} else if (param == u"darkmode=1") {
|
} else if (param == u"darkmode=1") {
|
||||||
options |= QWindowsIntegration::DarkModeWindowFrames;
|
darkModeHandling->setFlag(DarkModeHandlingFlag::DarkModeWindowFrames);
|
||||||
} else if (param == u"darkmode=2") {
|
} else if (param == u"darkmode=2") {
|
||||||
options |= QWindowsIntegration::DarkModeWindowFrames | QWindowsIntegration::DarkModeStyle;
|
darkModeHandling->setFlag(DarkModeHandlingFlag::DarkModeWindowFrames);
|
||||||
|
darkModeHandling->setFlag(DarkModeHandlingFlag::DarkModeStyle);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Unknown option" << param;
|
qWarning() << "Unknown option" << param;
|
||||||
}
|
}
|
||||||
@ -233,7 +240,7 @@ static inline unsigned parseOptions(const QStringList ¶mList,
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList ¶mList)
|
void QWindowsIntegrationPrivate::parseOptions(QWindowsIntegration *q, const QStringList ¶mList)
|
||||||
{
|
{
|
||||||
initOpenGlBlacklistResources();
|
initOpenGlBlacklistResources();
|
||||||
|
|
||||||
@ -242,7 +249,9 @@ QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList ¶mL
|
|||||||
// are connected to Windows 8.1
|
// are connected to Windows 8.1
|
||||||
QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorDpiAware;
|
QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorDpiAware;
|
||||||
int tabletAbsoluteRange = -1;
|
int tabletAbsoluteRange = -1;
|
||||||
m_options = parseOptions(paramList, &tabletAbsoluteRange, &dpiAwareness);
|
DarkModeHandling darkModeHandling;
|
||||||
|
m_options = ::parseOptions(paramList, &tabletAbsoluteRange, &dpiAwareness, &darkModeHandling);
|
||||||
|
q->setDarkModeHandling(darkModeHandling);
|
||||||
QWindowsFontDatabase::setFontOptions(m_options);
|
QWindowsFontDatabase::setFontOptions(m_options);
|
||||||
if (tabletAbsoluteRange >= 0)
|
if (tabletAbsoluteRange >= 0)
|
||||||
QWindowsContext::setTabletAbsoluteRange(tabletAbsoluteRange);
|
QWindowsContext::setTabletAbsoluteRange(tabletAbsoluteRange);
|
||||||
@ -276,9 +285,10 @@ QWindowsIntegrationPrivate::~QWindowsIntegrationPrivate()
|
|||||||
QWindowsIntegration *QWindowsIntegration::m_instance = nullptr;
|
QWindowsIntegration *QWindowsIntegration::m_instance = nullptr;
|
||||||
|
|
||||||
QWindowsIntegration::QWindowsIntegration(const QStringList ¶mList) :
|
QWindowsIntegration::QWindowsIntegration(const QStringList ¶mList) :
|
||||||
d(new QWindowsIntegrationPrivate(paramList))
|
d(new QWindowsIntegrationPrivate)
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
|
d->parseOptions(this, paramList);
|
||||||
#if QT_CONFIG(clipboard)
|
#if QT_CONFIG(clipboard)
|
||||||
d->m_clipboard.registerViewer();
|
d->m_clipboard.registerViewer();
|
||||||
#endif
|
#endif
|
||||||
|
@ -79,9 +79,7 @@ public:
|
|||||||
DontUseWMPointer = 0x400,
|
DontUseWMPointer = 0x400,
|
||||||
DetectAltGrModifier = 0x800,
|
DetectAltGrModifier = 0x800,
|
||||||
RtlEnabled = 0x1000,
|
RtlEnabled = 0x1000,
|
||||||
DarkModeWindowFrames = 0x2000,
|
FontDatabaseDirectWrite = 0x2000
|
||||||
DarkModeStyle = 0x4000,
|
|
||||||
FontDatabaseDirectWrite = 0x8000
|
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit QWindowsIntegration(const QStringList ¶mList);
|
explicit QWindowsIntegration(const QStringList ¶mList);
|
||||||
|
@ -239,15 +239,4 @@ QVariant QWindowsNativeInterface::gpuList() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QWindowsNativeInterface::isDarkMode() const
|
|
||||||
{
|
|
||||||
return QWindowsContext::isDarkMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dark mode support level 2 (style)
|
|
||||||
bool QWindowsNativeInterface::isDarkModeStyle() const
|
|
||||||
{
|
|
||||||
return (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeStyle) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -63,8 +63,6 @@ class QWindowsNativeInterface : public QPlatformNativeInterface
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool asyncExpose READ asyncExpose WRITE setAsyncExpose)
|
Q_PROPERTY(bool asyncExpose READ asyncExpose WRITE setAsyncExpose)
|
||||||
Q_PROPERTY(bool darkMode READ isDarkMode STORED false NOTIFY darkModeChanged)
|
|
||||||
Q_PROPERTY(bool darkModeStyle READ isDarkModeStyle STORED false)
|
|
||||||
Q_PROPERTY(QVariant gpu READ gpu STORED false)
|
Q_PROPERTY(QVariant gpu READ gpu STORED false)
|
||||||
Q_PROPERTY(QVariant gpuList READ gpuList STORED false)
|
Q_PROPERTY(QVariant gpuList READ gpuList STORED false)
|
||||||
|
|
||||||
@ -92,14 +90,8 @@ public:
|
|||||||
bool asyncExpose() const;
|
bool asyncExpose() const;
|
||||||
void setAsyncExpose(bool value);
|
void setAsyncExpose(bool value);
|
||||||
|
|
||||||
bool isDarkMode() const;
|
|
||||||
bool isDarkModeStyle() const;
|
|
||||||
|
|
||||||
QVariant gpu() const;
|
QVariant gpu() const;
|
||||||
QVariant gpuList() const;
|
QVariant gpuList() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void darkModeChanged(bool);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -533,7 +533,7 @@ void QWindowsTheme::refreshPalettes()
|
|||||||
return;
|
return;
|
||||||
const bool light =
|
const bool light =
|
||||||
!QWindowsContext::isDarkMode()
|
!QWindowsContext::isDarkMode()
|
||||||
|| (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeStyle) == 0;
|
|| !QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle);
|
||||||
m_palettes[SystemPalette] = new QPalette(systemPalette(light));
|
m_palettes[SystemPalette] = new QPalette(systemPalette(light));
|
||||||
m_palettes[ToolTipPalette] = new QPalette(toolTipPalette(*m_palettes[SystemPalette], light));
|
m_palettes[ToolTipPalette] = new QPalette(toolTipPalette(*m_palettes[SystemPalette], light));
|
||||||
m_palettes[MenuPalette] = new QPalette(menuPalette(*m_palettes[SystemPalette], light));
|
m_palettes[MenuPalette] = new QPalette(menuPalette(*m_palettes[SystemPalette], light));
|
||||||
|
@ -821,7 +821,7 @@ QWindowsWindowData
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QWindowsContext::isDarkMode()
|
if (QWindowsContext::isDarkMode()
|
||||||
&& (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeWindowFrames) != 0
|
&& QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)
|
||||||
&& shouldApplyDarkFrame(w)) {
|
&& shouldApplyDarkFrame(w)) {
|
||||||
QWindowsWindow::setDarkBorderToWindow(result.hwnd, true);
|
QWindowsWindow::setDarkBorderToWindow(result.hwnd, true);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
#include <qpa/qplatformscreen.h>
|
#include <qpa/qplatformscreen.h>
|
||||||
#include <private/qguiapplication_p.h>
|
#include <private/qguiapplication_p.h>
|
||||||
#include <private/qhighdpiscaling_p.h>
|
#include <private/qhighdpiscaling_p.h>
|
||||||
#include <qpa/qplatformnativeinterface.h>
|
#include <qpa/qplatformintegration.h>
|
||||||
#include <private/qwidget_p.h>
|
#include <private/qwidget_p.h>
|
||||||
|
|
||||||
#include <private/qstylehelper_p.h>
|
#include <private/qstylehelper_p.h>
|
||||||
@ -133,13 +133,12 @@ bool QWindowsStylePrivate::isDarkMode()
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
using QWindowsApplication = QPlatformInterface::Private::QWindowsApplication;
|
||||||
// Windows only: Return whether dark mode style support is desired and
|
// Windows only: Return whether dark mode style support is desired and
|
||||||
// dark mode is in effect.
|
// dark mode is in effect.
|
||||||
if (auto ni = QGuiApplication::platformNativeInterface()) {
|
if (auto windowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration())) {
|
||||||
const QVariant darkModeStyleP = ni->property("darkModeStyle");
|
result = windowsApp->isDarkMode()
|
||||||
result = darkModeStyleP.type() == QVariant::Bool
|
&& windowsApp->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle);
|
||||||
&& darkModeStyleP.value<bool>()
|
|
||||||
&& ni->property("darkMode").value<bool>();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user