diff --git a/kded/configeditor.cpp b/kded/configeditor.cpp index ec6f2cd..0c1cdd3 100644 --- a/kded/configeditor.cpp +++ b/kded/configeditor.cpp @@ -1,180 +1,180 @@ /* * Copyright (C) 2019 Mikhail Zolotukhin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include "configeditor.h" static void replaceValueInGtkrcContents(QString >krcContents, const QString ¶mName, const QString ¶mValue); static void replaceValueInXSettingsdContents(QString &xSettingsdContents, const QString ¶mName, const QString ¶mValue); static void reloadGtk2Apps(); static void reloadXSettingsd(); static QString readFileContents(QFile >krc); 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()); } void ConfigEditor::setGtk3ConfigValueSettingsIni(const QString ¶mName, const QString ¶mValue) { QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); QString gtk3ConfigPath = configLocation + QStringLiteral("/gtk-3.0/settings.ini"); KSharedConfig::Ptr gtk3Config = KSharedConfig::openConfig(gtk3ConfigPath, KConfig::NoGlobals); KConfigGroup group = gtk3Config->group(QStringLiteral("Settings")); group.writeEntry(paramName, paramValue); group.sync(); } void ConfigEditor::setGtk3ConfigValueXSettingsd(const QString ¶mName, const QString ¶mValue) { using qsp = QStandardPaths; QString configLocation = qsp::writableLocation(qsp::GenericConfigLocation); QDir xsettingsdPath = configLocation + QStringLiteral("/xsettingsd"); if (!xsettingsdPath.exists()) { xsettingsdPath.mkpath(QStringLiteral(".")); } QString xSettingsdConfigPath = xsettingsdPath.path() + QStringLiteral("/xsettingsd.conf"); QFile xSettingsdConfig(xSettingsdConfigPath); QString xSettingsdConfigContents = readFileContents(xSettingsdConfig); replaceValueInXSettingsdContents(xSettingsdConfigContents, paramName, paramValue); xSettingsdConfig.remove(); xSettingsdConfig.open(QIODevice::WriteOnly | QIODevice::Text); xSettingsdConfig.write(xSettingsdConfigContents.toUtf8()); reloadXSettingsd(); } void ConfigEditor::setGtk2ConfigValue(const QString ¶mName, const QString ¶mValue) { QString gtkrcPath = QDir::homePath() + QStringLiteral("/.gtkrc-2.0"); QFile gtkrc(gtkrcPath); QString gtkrcContents = readFileContents(gtkrc); replaceValueInGtkrcContents(gtkrcContents, paramName, paramValue); gtkrc.remove(); gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); gtkrc.write(gtkrcContents.toUtf8()); reloadGtk2Apps(); } static QString readFileContents(QFile &file) { if (file.open(QIODevice::ReadWrite | QIODevice::Text)) { return file.readAll(); } else { return QString(); } } static void replaceValueInGtkrcContents(QString >krcContents, const QString ¶mName, const QString ¶mValue) { const QRegularExpression regExp(paramName + QStringLiteral("=[^\n]*($|\n)")); static const QStringList nonStringProperties{ QStringLiteral("gtk-toolbar-style"), QStringLiteral("gtk-menu-images"), QStringLiteral("gtk-button-images"), QStringLiteral("gtk-primary-button-warps-slider"), }; QString newConfigString; if (nonStringProperties.contains(paramName)) { newConfigString = paramName + QStringLiteral("=") + paramValue + QStringLiteral("\n"); } else { newConfigString = paramName + QStringLiteral("=\"") + paramValue + QStringLiteral("\"\n"); } if (gtkrcContents.contains(regExp)) { gtkrcContents.replace(regExp, newConfigString); } else { gtkrcContents = newConfigString + QStringLiteral("\n") + gtkrcContents; } } static void replaceValueInXSettingsdContents(QString &xSettingsdContents, const QString ¶mName, const QString ¶mValue) { const QRegularExpression regExp(paramName + QStringLiteral(" [^\n]*($|\n)")); static const QStringList nonStringProperties{ QStringLiteral("Gtk/ButtonImages"), QStringLiteral("Gtk/MenuImages"), QStringLiteral("Gtk/ToolbarStyle"), QStringLiteral("Gtk/PrimaryButtonWarpsSlider"), }; QString newConfigString; if (nonStringProperties.contains(paramName)) { newConfigString = paramName + QStringLiteral(" ") + paramValue + QStringLiteral("\n"); } else { newConfigString = paramName + QStringLiteral(" \"") + paramValue + QStringLiteral("\"\n"); } if (xSettingsdContents.contains(regExp)) { xSettingsdContents.replace(regExp, newConfigString); } else { xSettingsdContents = newConfigString + QStringLiteral("\n") + xSettingsdContents; } } static void reloadGtk2Apps() { QProcess::startDetached(QStandardPaths::findExecutable(QStringLiteral("reload_gtk_apps"))); } static void reloadXSettingsd() { pid_t xSettingsdPid = pidOfXSettingsd(); if (xSettingsdPid == 0) { QProcess::startDetached(QStandardPaths::findExecutable(QStringLiteral("xsettingsd"))); } else { kill(xSettingsdPid, SIGHUP); } } static pid_t pidOfXSettingsd() { QProcess pidof; pidof.start(QStringLiteral("pidof"), QStringList() << QStringLiteral("-s") << QStringLiteral("xsettingsd")); pidof.waitForFinished(); QString xsettingsdPid = QString(pidof.readAllStandardOutput()).remove('\n'); return xsettingsdPid.toInt(); } diff --git a/kded/configeditor.h b/kded/configeditor.h index d24ccc2..fb6319d 100644 --- a/kded/configeditor.h +++ b/kded/configeditor.h @@ -1,33 +1,33 @@ /* * Copyright (C) 2019 Mikhail Zolotukhin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #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/configvalueprovider.cpp b/kded/configvalueprovider.cpp index 5e29a7a..6641029 100644 --- a/kded/configvalueprovider.cpp +++ b/kded/configvalueprovider.cpp @@ -1,164 +1,198 @@ /* * Copyright (C) 2019 Mikhail Zolotukhin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include "configvalueprovider.h" ConfigValueProvider::ConfigValueProvider() : kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), - inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))) + inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))), + kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc"))) { } QString ConfigValueProvider::fontName() const { static const QFont defaultFont(QStringLiteral("Noto Sans"), 10); kdeglobalsConfig->reparseConfiguration(); KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("General")); QString fontAsString = configGroup.readEntry(QStringLiteral("font"), defaultFont.toString()); static QFont font; font.fromString(fontAsString); return font.family() + ' ' + font.styleName() + ' ' + QString::number(font.pointSize()); } QString ConfigValueProvider::iconThemeName() const { KIconTheme *newIconTheme = KIconLoader::global()->theme(); if (newIconTheme) { return newIconTheme->internalName(); } else { return QStringLiteral("breeze"); } } QString ConfigValueProvider::cursorThemeName() const { inputConfig->reparseConfiguration(); KConfigGroup configGroup = inputConfig->group(QStringLiteral("Mouse")); return configGroup.readEntry(QStringLiteral("cursorTheme"), QStringLiteral("breeze_cursors")); } QString ConfigValueProvider::iconsOnButtons() const { kdeglobalsConfig->reparseConfiguration(); KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ShowIconsOnPushButtons"), true); if (kdeConfigValue) { return QStringLiteral("1"); } else { return QStringLiteral("0"); } } QString ConfigValueProvider::iconsInMenus() const { kdeglobalsConfig->reparseConfiguration(); KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ShowIconsInMenuItems"), true); if (kdeConfigValue) { return QStringLiteral("1"); } else { return QStringLiteral("0"); } } QString ConfigValueProvider::toolbarStyle(ConfigValueProvider::ToolbarStyleNotation notation) const { kdeglobalsConfig->reparseConfiguration(); KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("Toolbar style")); QString kdeConfigValue = configGroup.readEntry(QStringLiteral("ToolButtonStyle"), "TextBesideIcon"); return toolbarStyleInDesiredNotation(kdeConfigValue, notation); } QString ConfigValueProvider::scrollbarBehavior() const { kdeglobalsConfig->reparseConfiguration(); KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ScrollbarLeftClickNavigatesByPage"), true); if (kdeConfigValue) { // GTK setting is inverted return QStringLiteral("0"); } else { return QStringLiteral("1"); } } QString ConfigValueProvider::preferDarkTheme() const { kdeglobalsConfig->reparseConfiguration(); KConfigGroup colorsConfigGroup = kdeglobalsConfig->group(QStringLiteral("Colors:Window")); QColor windowBackgroundColor = colorsConfigGroup.readEntry(QStringLiteral("BackgroundNormal"), QColor(239, 240, 241)); const int windowBackgroundGray = qGray(windowBackgroundColor.rgb()); // We use heuristic to determine if current color scheme is dark or not if (windowBackgroundGray >= 192) { return QStringLiteral("0"); } else { return QStringLiteral("1"); } } +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 {}; if (notation == ToolbarStyleNotation::SettingsIni) { toolbarStyles.append({ QStringLiteral("GTK_TOOLBAR_ICONS"), QStringLiteral("GTK_TOOLBAR_TEXT"), QStringLiteral("GTK_TOOLBAR_BOTH_HORIZ"), QStringLiteral("GTK_TOOLBAR_BOTH") }); } else if (notation == ToolbarStyleNotation::Xsettingsd) { toolbarStyles.append({ QStringLiteral("0"), QStringLiteral("1"), QStringLiteral("3"), QStringLiteral("2") }); } else { toolbarStyles.append({ QStringLiteral("icons"), QStringLiteral("text"), QStringLiteral("both-horiz"), QStringLiteral("both") }); } if (kdeConfigValue == QStringLiteral("NoText")) { return toolbarStyles[0]; } else if (kdeConfigValue == QStringLiteral("TextOnly")) { return toolbarStyles[1]; } else if (kdeConfigValue == QStringLiteral("TextBesideIcon")) { return toolbarStyles[2]; } else { 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/configvalueprovider.h b/kded/configvalueprovider.h index d398c3c..c202c6c 100644 --- a/kded/configvalueprovider.h +++ b/kded/configvalueprovider.h @@ -1,53 +1,56 @@ /* * Copyright (C) 2019 Mikhail Zolotukhin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include class QString; class QFont; class ConfigValueProvider { public: enum class ToolbarStyleNotation { Xsettingsd = 0, SettingsIni, Dconf }; ConfigValueProvider(); QString fontName() const; QString iconThemeName() const; QString cursorThemeName() const; QString iconsOnButtons() const; QString iconsInMenus() const; 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/gtkconfig.cpp b/kded/gtkconfig.cpp index 3b4a366..76980b4 100644 --- a/kded/gtkconfig.cpp +++ b/kded/gtkconfig.cpp @@ -1,154 +1,173 @@ /* * Copyright (C) 2019 Mikhail Zolotukhin * Copyright (C) 2019 Nicolas Fella * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #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(); } void GtkConfig::setFont() const { const QString configFontName = configValueProvider->fontName(); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("font-name"), configFontName); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-font-name"), configFontName); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/FontName"), configFontName); } void GtkConfig::setIconTheme(int iconGroup) const { if (iconGroup == KIconLoader::Group::Desktop) { // This is needed to update icons only once const QString iconThemeName = configValueProvider->iconThemeName(); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-icon-theme-name"), iconThemeName); ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("icon-theme"), iconThemeName); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-icon-theme-name"), iconThemeName); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/IconThemeName"), iconThemeName); } } void GtkConfig::setCursorTheme() const { const QString cursorThemeName = configValueProvider->cursorThemeName(); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("cursor-theme"), cursorThemeName); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/CursorThemeName"), cursorThemeName); } void GtkConfig::setIconsOnButtons() const { const QString iconsOnButtonsConfigValue = configValueProvider->iconsOnButtons(); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ButtonImages"), iconsOnButtonsConfigValue); } void GtkConfig::setIconsInMenus() const { const QString iconsInMenusConfigValue = configValueProvider->iconsInMenus(); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/MenuImages"), iconsInMenusConfigValue); } void GtkConfig::setToolbarStyle() const { using ToolbarStyleNotation = ConfigValueProvider::ToolbarStyleNotation; QString toolbarStyleSettingsIni = configValueProvider->toolbarStyle(ToolbarStyleNotation::SettingsIni); QString toolbarStyleDConf = configValueProvider->toolbarStyle(ToolbarStyleNotation::Dconf); QString toolbarStyleXSettingsd = configValueProvider->toolbarStyle(ToolbarStyleNotation::Xsettingsd); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsIni); ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("toolbar-style"), toolbarStyleDConf); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsIni); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ToolbarStyle"), toolbarStyleXSettingsd); } void GtkConfig::setScrollbarBehavior() const { const QString scrollbarBehavior = configValueProvider->scrollbarBehavior(); ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-primary-button-warps-slider"), scrollbarBehavior); ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-primary-button-warps-slider"), scrollbarBehavior); ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/PrimaryButtonWarpsSlider"), scrollbarBehavior); } void GtkConfig::setDarkThemePreference() const { const QString preferDarkTheme = configValueProvider->preferDarkTheme(); 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(); setIconTheme(KIconLoader::Group::Desktop); setCursorTheme(); setIconsOnButtons(); setIconsInMenus(); setToolbarStyle(); setScrollbarBehavior(); setDarkThemePreference(); + setWindowDecorationsButtonsOrder(); } void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const { SettingsChangeType changeType = static_cast(settingsChangeType); SettingsCategory settingsCategory = static_cast(arg); if (changeType == SettingsChangeType::Cursor) { setCursorTheme(); } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Style) { setIconsOnButtons(); setIconsInMenus(); setToolbarStyle(); } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Mouse) { setScrollbarBehavior(); } else if (changeType == SettingsChangeType::Palette) { setDarkThemePreference(); } } +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" diff --git a/kded/gtkconfig.h b/kded/gtkconfig.h index 8cabfab..61807b3 100644 --- a/kded/gtkconfig.h +++ b/kded/gtkconfig.h @@ -1,75 +1,79 @@ /* * Copyright (C) 2019 Mikhail Zolotukhin * Copyright (C) 2019 Nicolas Fella * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include +#include #include "configeditor.h" #include "configvalueprovider.h" class Q_DECL_EXPORT GtkConfig : public KDEDModule { Q_OBJECT enum class SettingsChangeType { Palette = 0, Font, Style, Settings, Icon, Cursor, ToolbarStyle, BlockShortcuts, NaturalSorting }; enum class SettingsCategory { Mouse, Completion, Paths, Popupmenu, Qt, Shortcuts, Locale, Style }; public: GtkConfig(QObject *parent, const QVariantList& args); void setFont() const; void setIconTheme(int iconGroup) const; void setCursorTheme() const; void setIconsOnButtons() const; void setIconsInMenus() const; 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; };