summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiDe Zhang <zhangjide@uniontech.com>2022-06-16 17:50:33 +0800
committerJiDe Zhang <zhangjide@uniontech.com>2022-08-17 21:14:52 +0800
commit90ad4d10efea131ad569b1350b8150bbd66c179d (patch)
treeb96c19fc389b2629221ebf75d0fb345fc42ac7e7
parent7594e8ca4d91935400f065e138ff1e4b4f212478 (diff)
xcb: Propagate a few theme hint changes to QGuiApplication
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ø <tor.arne.vestbo@qt.io>
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp28
1 files 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.