summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Eftevaag <[email protected]>2025-03-28 09:56:27 +0100
committerOliver Eftevaag <[email protected]>2025-03-28 17:44:50 +0100
commit49f05b043e382761dbf913677af5072f95d2df19 (patch)
treeccdfa1dc6d48517d53c364725f83c8230b9f58c0
parent4ac89dad78772ce90649b9846efa17319deba28f (diff)
GnomeTheme: read the initial color-scheme value from dbus
The initial color-scheme value was never initialized, and would thus, always be 'Unknown', until the user changes the color scheme in the system settings. The xdg settings portal method ReadAll is currently omitting the contrast setting from the reply. Because of this, two separate dbus calls are necessary to get both the initial color-scheme and contrast setting. Change-Id: Ie32371efd830e19727922efd2c9c32595395d11a Reviewed-by: Axel Spoerl <[email protected]>
-rw-r--r--src/gui/platform/unix/qgnometheme.cpp57
1 files changed, 39 insertions, 18 deletions
diff --git a/src/gui/platform/unix/qgnometheme.cpp b/src/gui/platform/unix/qgnometheme.cpp
index bce0eca0629..1095a665324 100644
--- a/src/gui/platform/unix/qgnometheme.cpp
+++ b/src/gui/platform/unix/qgnometheme.cpp
@@ -31,30 +31,51 @@ const char *QGnomeTheme::name = "gnome";
QGnomeThemePrivate::QGnomeThemePrivate()
{
#ifndef QT_NO_DBUS
- QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.portal.Desktop"),
- QLatin1String("/org/freedesktop/portal/desktop"),
- QLatin1String("org.freedesktop.portal.Settings"),
- QLatin1String("ReadOne"));
static constexpr QLatin1String appearanceNamespace("org.freedesktop.appearance");
+ static constexpr QLatin1String colorSchemeKey("color-scheme");
static constexpr QLatin1String contrastKey("contrast");
- message << appearanceNamespace << contrastKey;
-
QDBusConnection dbus = QDBusConnection::sessionBus();
- if (!dbus.isConnected())
- qCWarning(lcQpaThemeGnome) << "dbus connection failed. Last error: " << dbus.lastError();
+ if (dbus.isConnected()) {
+ // ReadAll appears to omit the contrast setting on Ubuntu.
+ QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.portal.Desktop"),
+ QLatin1String("/org/freedesktop/portal/desktop"),
+ QLatin1String("org.freedesktop.portal.Settings"),
+ QLatin1String("ReadOne"));
- QDBusPendingCall pendingCall = dbus.asyncCall(message);
- QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall);
- QObject::connect(watcher, &QDBusPendingCallWatcher::finished, watcher, [this](QDBusPendingCallWatcher *watcher) {
- if (!watcher->isError()) {
- QDBusPendingReply<QVariant> reply = *watcher;
- if (Q_LIKELY(reply.isValid()))
- m_contrast = static_cast<Qt::ContrastPreference>(reply.value().toUInt());
+ message << appearanceNamespace << colorSchemeKey;
+ QDBusReply<QVariant> reply = dbus.call(message);
+ if (Q_LIKELY(reply.isValid())) {
+ uint xdgColorSchemeValue = reply.value().toUInt();
+ switch (xdgColorSchemeValue) {
+ case 1:
+ m_colorScheme = Qt::ColorScheme::Dark;
+ QWindowSystemInterface::handleThemeChange();
+ break;
+ case 2:
+ m_colorScheme = Qt::ColorScheme::Light;
+ QWindowSystemInterface::handleThemeChange();
+ break;
+ default:
+ break;
+ }
}
- watcher->deleteLater();
- initDbus();
- });
+
+ message.setArguments({});
+ message << appearanceNamespace << contrastKey;
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(dbus.asyncCall(message));
+ QObject::connect(watcher, &QDBusPendingCallWatcher::finished, watcher, [this](QDBusPendingCallWatcher *watcher) {
+ if (!watcher->isError()) {
+ QDBusPendingReply<QVariant> reply = *watcher;
+ if (Q_LIKELY(reply.isValid()))
+ updateHighContrast(static_cast<Qt::ContrastPreference>(reply.value().toUInt()));
+ }
+ initDbus();
+ watcher->deleteLater();
+ });
+ } else {
+ qCWarning(lcQpaThemeGnome) << "dbus connection failed. Last error: " << dbus.lastError();
+ }
#endif // QT_NO_DBUS
}
QGnomeThemePrivate::~QGnomeThemePrivate()