diff --git a/kded/configeditor.h b/kded/configeditor.h --- a/kded/configeditor.h +++ b/kded/configeditor.h @@ -20,14 +20,14 @@ #pragma once #include +#include -class QString; class QFile; namespace ConfigEditor { void setGtk2ConfigValue(const QString ¶mName, const QString ¶mValue); - void setGtk3ConfigValueDconf(const QString ¶mName, const QString ¶mValue); + void setGtk3ConfigValueDconf(const QString ¶mName, const QString ¶mValue, const QString &category = QStringLiteral("org.gnome.desktop.interface")); void setGtk3ConfigValueSettingsIni(const QString ¶mName, const QString ¶mValue); void setGtk3ConfigValueXSettingsd(const QString ¶mName, const QString ¶mValue); }; diff --git a/kded/configeditor.cpp b/kded/configeditor.cpp --- a/kded/configeditor.cpp +++ b/kded/configeditor.cpp @@ -45,9 +45,9 @@ static pid_t pidOfXSettingsd(); -void ConfigEditor::setGtk3ConfigValueDconf(const QString ¶mName, const QString ¶mValue) +void ConfigEditor::setGtk3ConfigValueDconf(const QString ¶mName, const QString ¶mValue, const QString &category) { - g_autoptr(GSettings) gsettings = g_settings_new("org.gnome.desktop.interface"); + g_autoptr(GSettings) gsettings = g_settings_new(category.toUtf8().constData()); g_settings_set_string(gsettings, paramName.toUtf8().constData(), paramValue.toUtf8().constData()); } diff --git a/kded/configvalueprovider.h b/kded/configvalueprovider.h --- a/kded/configvalueprovider.h +++ b/kded/configvalueprovider.h @@ -44,10 +44,13 @@ QString toolbarStyle(ToolbarStyleNotation notation) const; QString scrollbarBehavior() const; QString preferDarkTheme() const; + QString windowDecorationsButtonsOrder() const; private: QString toolbarStyleInDesiredNotation(const QString &kdeConfigValue, ToolbarStyleNotation notation) const; + QString windowDecorationButtonsOrderInGtkNotation(const QString &kdeConfigValue) const; KSharedConfigPtr kdeglobalsConfig; KSharedConfigPtr inputConfig; + KSharedConfigPtr kwinConfig; }; diff --git a/kded/configvalueprovider.cpp b/kded/configvalueprovider.cpp --- a/kded/configvalueprovider.cpp +++ b/kded/configvalueprovider.cpp @@ -31,7 +31,8 @@ ConfigValueProvider::ConfigValueProvider() : kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), - inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))) + inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))), + kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc"))) { } @@ -126,6 +127,19 @@ } } +QString ConfigValueProvider::windowDecorationsButtonsOrder() const +{ + kwinConfig->reparseConfiguration(); + KConfigGroup configGroup = kwinConfig->group(QStringLiteral("org.kde.kdecoration2")); + QString buttonsOnLeftKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnLeft"), "MS"); + QString buttonsOnRightKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnRight"), "HIAX"); + + QString buttonsOnLeftInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnLeftKdeConfigValue); + QString buttonsOnRightInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnRightKdeConfigValue); + + return buttonsOnLeftInGtkNotation + QStringLiteral(":") + buttonsOnRightInGtkNotation; +} + QString ConfigValueProvider::toolbarStyleInDesiredNotation(const QString &kdeConfigValue, ConfigValueProvider::ToolbarStyleNotation notation) const { QStringList toolbarStyles {}; @@ -162,3 +176,23 @@ return toolbarStyles[3]; } } + +QString ConfigValueProvider::windowDecorationButtonsOrderInGtkNotation(const QString &kdeConfigValue) const +{ + QString gtkNotation; + + for (const QChar &buttonAbbreviation : kdeConfigValue) { + if (buttonAbbreviation == 'X') { + gtkNotation += QStringLiteral("close,"); + } else if (buttonAbbreviation == 'I') { + gtkNotation += QStringLiteral("minimize,"); + } else if (buttonAbbreviation == 'A') { + gtkNotation += QStringLiteral("maximize,"); + } else if (buttonAbbreviation == 'M') { + gtkNotation += QStringLiteral("icon,"); + } + } + gtkNotation.chop(1); + + return gtkNotation; +} diff --git a/kded/gtkconfig.h b/kded/gtkconfig.h --- a/kded/gtkconfig.h +++ b/kded/gtkconfig.h @@ -22,6 +22,7 @@ #pragma once #include +#include #include "configeditor.h" #include "configvalueprovider.h" @@ -64,12 +65,15 @@ void setToolbarStyle() const; void setScrollbarBehavior() const; void setDarkThemePreference() const; + void setWindowDecorationsButtonsOrder() const; void applyAllSettings() const; public Q_SLOTS: void onGlobalSettingsChange(int settingsChangeType, int arg) const; + void onKWinSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const; private: QScopedPointer configValueProvider; + KConfigWatcher::Ptr kwinConfigWatcher; }; diff --git a/kded/gtkconfig.cpp b/kded/gtkconfig.cpp --- a/kded/gtkconfig.cpp +++ b/kded/gtkconfig.cpp @@ -26,25 +26,27 @@ #include #include +#include #include "gtkconfig.h" #include "configvalueprovider.h" K_PLUGIN_CLASS_WITH_JSON(GtkConfig, "gtkconfig.json") GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : KDEDModule(parent), - configValueProvider(new ConfigValueProvider()) + configValueProvider(new ConfigValueProvider()), + kwinConfigWatcher(KConfigWatcher::create(KSharedConfig::openConfig(QStringLiteral("kwinrc")))) { connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont); connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &GtkConfig::setIconTheme); + connect(kwinConfigWatcher.data(), &KConfigWatcher::configChanged, this, &GtkConfig::onKWinSettingsChange); QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange"), this, SLOT(onGlobalSettingsChange(int,int))); - applyAllSettings(); } @@ -121,6 +123,14 @@ ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-application-prefer-dark-theme"), preferDarkTheme); } +void GtkConfig::setWindowDecorationsButtonsOrder() const +{ + const QString windowDecorationsButtonOrder = configValueProvider->windowDecorationsButtonsOrder(); + ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("button-layout"), windowDecorationsButtonOrder, QStringLiteral("org.gnome.desktop.wm.preferences")); + ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-decoration-layout"), windowDecorationsButtonOrder); + ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/DecorationLayout"), windowDecorationsButtonOrder); +} + void GtkConfig::applyAllSettings() const { setFont(); @@ -131,6 +141,7 @@ setToolbarStyle(); setScrollbarBehavior(); setDarkThemePreference(); + setWindowDecorationsButtonsOrder(); } void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const @@ -151,4 +162,12 @@ } } +void GtkConfig::onKWinSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const +{ + if (group.name() == QStringLiteral("org.kde.kdecoration2") + && (names.contains("ButtonsOnRight") || names.contains("ButtonsOnLeft"))) { + setWindowDecorationsButtonsOrder(); + } +} + #include "gtkconfig.moc"