xcb: Get some style hints from xsettings

According to
https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/.
Added support for Net/CursorBlinkTime Net/DoubleClickTime
Net/DoubleClickDistance Net/DndDragThreshold.

Change-Id: Ief208736ed2938792d935bfd730fefdd745394b6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
JiDe Zhang 2022-06-16 13:14:12 +08:00
parent 2ed54dedf3
commit 8790da8988
4 changed files with 28 additions and 4 deletions

View File

@ -408,6 +408,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
return QPlatformTheme::defaultThemeHint(QPlatformTheme::WheelScrollLines);
case MouseQuickSelectionThreshold:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseQuickSelectionThreshold);
case MouseDoubleClickDistance:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseDoubleClickDistance);
}
return 0;

View File

@ -160,7 +160,8 @@ public:
UiEffects,
WheelScrollLines,
ShowShortcutsInContextMenus,
MouseQuickSelectionThreshold
MouseQuickSelectionThreshold,
MouseDoubleClickDistance
};
virtual QVariant styleHint(StyleHint hint) const;

View File

@ -122,7 +122,7 @@ int QStyleHints::mouseDoubleClickDistance() const
Q_D(const QStyleHints);
return d->m_mouseDoubleClickDistance >= 0 ?
d->m_mouseDoubleClickDistance :
themeableHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
themeableHint(QPlatformTheme::MouseDoubleClickDistance, QPlatformIntegration::MouseDoubleClickDistance).toInt();
}
/*!

View File

@ -20,6 +20,7 @@
#ifndef QT_NO_SESSIONMANAGER
#include "qxcbsessionmanager.h"
#endif
#include "qxcbxsettings.h"
#include <xcb/xcb.h>
@ -423,12 +424,30 @@ QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
return QGenericUnixTheme::createUnixTheme(name);
}
#define RETURN_VALID_XSETTINGS(key) { \
auto value = connection()->primaryScreen()->xSettings()->setting(key); \
if (value.isValid()) return value; \
}
QVariant QXcbIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
{
switch (hint) {
case QPlatformIntegration::CursorFlashTime:
case QPlatformIntegration::KeyboardInputInterval:
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)
return 0;
RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/CursorBlinkTime"));
break;
}
case QPlatformIntegration::MouseDoubleClickInterval:
RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/DoubleClickTime"));
break;
case QPlatformIntegration::MouseDoubleClickDistance:
RETURN_VALID_XSETTINGS(QByteArrayLiteral("Net/DoubleClickDistance"));
break;
case QPlatformIntegration::KeyboardInputInterval:
case QPlatformIntegration::StartDragTime:
case QPlatformIntegration::KeyboardAutoRepeatRate:
case QPlatformIntegration::PasswordMaskDelay:
@ -438,6 +457,8 @@ 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"));
// The default (in QPlatformTheme::defaultThemeHint) is 10 pixels, but
// on a high-resolution screen it makes sense to increase it.
qreal dpi = 100.0;