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>
This commit is contained in:
JiDe Zhang 2022-06-16 17:50:33 +08:00
parent 7594e8ca4d
commit 90ad4d10ef

View File

@ -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.