From 90ad4d10efea131ad569b1350b8150bbd66c179d Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Thu, 16 Jun 2022 17:50:33 +0800 Subject: [PATCH] xcb: Propagate a few theme hint changes to QGuiApplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the xsettings value of relevant style hints is changed we propagate it to QGuiApplication via handleThemeChange. Change-Id: I316c90e776f52e92c1249aa4e1fcb3ced331f8f5 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/xcb/qxcbintegration.cpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 8b49fb73ca..e32891e814 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -325,6 +325,13 @@ QAbstractEventDispatcher *QXcbIntegration::createEventDispatcher() const return QXcbEventDispatcher::createEventDispatcher(connection()); } +using namespace Qt::Literals::StringLiterals; +static const auto xsNetCursorBlink = "Net/CursorBlink"_ba; +static const auto xsNetCursorBlinkTime = "Net/CursorBlinkTime"_ba; +static const auto xsNetDoubleClickTime = "Net/DoubleClickTime"_ba; +static const auto xsNetDoubleClickDistance = "Net/DoubleClickDistance"_ba; +static const auto xsNetDndDragThreshold = "Net/DndDragThreshold"_ba; + void QXcbIntegration::initialize() { const auto defaultInputContext = "compose"_L1; @@ -338,6 +345,17 @@ void QXcbIntegration::initialize() m_inputContext.reset(QPlatformInputContextFactory::create(defaultInputContext)); connection()->keyboard()->initialize(); + + auto notifyThemeChanged = [](QXcbVirtualDesktop *, const QByteArray &, const QVariant &, void *) { + QWindowSystemInterface::handleThemeChange(); + }; + + auto *xsettings = connection()->primaryScreen()->xSettings(); + xsettings->registerCallbackForProperty(xsNetCursorBlink, notifyThemeChanged, this); + xsettings->registerCallbackForProperty(xsNetCursorBlinkTime, notifyThemeChanged, this); + xsettings->registerCallbackForProperty(xsNetDoubleClickTime, notifyThemeChanged, this); + xsettings->registerCallbackForProperty(xsNetDoubleClickDistance, notifyThemeChanged, this); + xsettings->registerCallbackForProperty(xsNetDndDragThreshold, notifyThemeChanged, this); } void QXcbIntegration::moveToScreen(QWindow *window, int screen) @@ -435,17 +453,17 @@ QVariant QXcbIntegration::styleHint(QPlatformIntegration::StyleHint hint) const case QPlatformIntegration::CursorFlashTime: { bool ok = false; // If cursor blinking is off, returns 0 to keep the cursor awlays display. - if (connection()->primaryScreen()->xSettings()->setting(QByteArrayLiteral("Net/CursorBlink")).toInt(&ok) == 0 && ok) + if (connection()->primaryScreen()->xSettings()->setting(xsNetCursorBlink).toInt(&ok) == 0 && ok) return 0; - RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/CursorBlinkTime")); + RETURN_VALID_XSETTINGS(xsNetCursorBlinkTime); break; } case QPlatformIntegration::MouseDoubleClickInterval: - RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/DoubleClickTime")); + RETURN_VALID_XSETTINGS(xsNetDoubleClickTime); break; case QPlatformIntegration::MouseDoubleClickDistance: - RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/DoubleClickDistance")); + RETURN_VALID_XSETTINGS(xsNetDoubleClickDistance); break; case QPlatformIntegration::KeyboardInputInterval: case QPlatformIntegration::StartDragTime: @@ -457,7 +475,7 @@ QVariant QXcbIntegration::styleHint(QPlatformIntegration::StyleHint hint) const // TODO using various xcb, gnome or KDE settings break; // Not implemented, use defaults case QPlatformIntegration::StartDragDistance: { - RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/DndDragThreshold")); + RETURN_VALID_XSETTINGS(xsNetDndDragThreshold); // The default (in QPlatformTheme::defaultThemeHint) is 10 pixels, but // on a high-resolution screen it makes sense to increase it.