Changeset View
Changeset View
Standalone View
Standalone View
kded/gtkconfig.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include <QDebug> | 22 | #include <QDebug> | ||
23 | #include <QFont> | 23 | #include <QFont> | ||
24 | #include <QDBusConnection> | 24 | #include <QDBusConnection> | ||
25 | #include <QGuiApplication> | 25 | #include <QGuiApplication> | ||
26 | 26 | | |||
27 | #include <KIconLoader> | 27 | #include <KIconLoader> | ||
28 | #include <KPluginFactory> | 28 | #include <KPluginFactory> | ||
29 | #include <KConfigWatcher> | ||||
29 | 30 | | |||
30 | #include "gtkconfig.h" | 31 | #include "gtkconfig.h" | ||
31 | #include "configvalueprovider.h" | 32 | #include "configvalueprovider.h" | ||
32 | 33 | | |||
33 | K_PLUGIN_CLASS_WITH_JSON(GtkConfig, "gtkconfig.json") | 34 | K_PLUGIN_CLASS_WITH_JSON(GtkConfig, "gtkconfig.json") | ||
34 | 35 | | |||
35 | GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : | 36 | GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : | ||
36 | KDEDModule(parent), | 37 | KDEDModule(parent), | ||
37 | configValueProvider(new ConfigValueProvider()) | 38 | configValueProvider(new ConfigValueProvider()), | ||
39 | kwinConfigWatcher(KConfigWatcher::create(KSharedConfig::openConfig(QStringLiteral("kwinrc")))) | ||||
38 | { | 40 | { | ||
39 | connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont); | 41 | connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont); | ||
40 | connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &GtkConfig::setIconTheme); | 42 | connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &GtkConfig::setIconTheme); | ||
43 | connect(kwinConfigWatcher.data(), &KConfigWatcher::configChanged, this, &GtkConfig::onKWinSettingsChange); | ||||
41 | QDBusConnection::sessionBus().connect(QString(), | 44 | QDBusConnection::sessionBus().connect(QString(), | ||
42 | QStringLiteral("/KGlobalSettings"), | 45 | QStringLiteral("/KGlobalSettings"), | ||
43 | QStringLiteral("org.kde.KGlobalSettings"), | 46 | QStringLiteral("org.kde.KGlobalSettings"), | ||
44 | QStringLiteral("notifyChange"), | 47 | QStringLiteral("notifyChange"), | ||
45 | this, | 48 | this, | ||
46 | SLOT(onGlobalSettingsChange(int,int))); | 49 | SLOT(onGlobalSettingsChange(int,int))); | ||
47 | | ||||
48 | applyAllSettings(); | 50 | applyAllSettings(); | ||
49 | } | 51 | } | ||
50 | 52 | | |||
51 | void GtkConfig::setFont() const | 53 | void GtkConfig::setFont() const | ||
52 | { | 54 | { | ||
53 | const QString configFontName = configValueProvider->fontName(); | 55 | const QString configFontName = configValueProvider->fontName(); | ||
54 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); | 56 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); | ||
55 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("font-name"), configFontName); | 57 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("font-name"), configFontName); | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
116 | } | 118 | } | ||
117 | 119 | | |||
118 | void GtkConfig::setDarkThemePreference() const | 120 | void GtkConfig::setDarkThemePreference() const | ||
119 | { | 121 | { | ||
120 | const QString preferDarkTheme = configValueProvider->preferDarkTheme(); | 122 | const QString preferDarkTheme = configValueProvider->preferDarkTheme(); | ||
121 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-application-prefer-dark-theme"), preferDarkTheme); | 123 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-application-prefer-dark-theme"), preferDarkTheme); | ||
122 | } | 124 | } | ||
123 | 125 | | |||
126 | void GtkConfig::setWindowDecorationsButtonsOrder() const | ||||
127 | { | ||||
128 | const QString windowDecorationsButtonOrder = configValueProvider->windowDecorationsButtonsOrder(); | ||||
129 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("button-layout"), windowDecorationsButtonOrder, QStringLiteral("org.gnome.desktop.wm.preferences")); | ||||
130 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-decoration-layout"), windowDecorationsButtonOrder); | ||||
131 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/DecorationLayout"), windowDecorationsButtonOrder); | ||||
132 | } | ||||
133 | | ||||
124 | void GtkConfig::applyAllSettings() const | 134 | void GtkConfig::applyAllSettings() const | ||
125 | { | 135 | { | ||
126 | setFont(); | 136 | setFont(); | ||
127 | setIconTheme(KIconLoader::Group::Desktop); | 137 | setIconTheme(KIconLoader::Group::Desktop); | ||
128 | setCursorTheme(); | 138 | setCursorTheme(); | ||
129 | setIconsOnButtons(); | 139 | setIconsOnButtons(); | ||
130 | setIconsInMenus(); | 140 | setIconsInMenus(); | ||
131 | setToolbarStyle(); | 141 | setToolbarStyle(); | ||
132 | setScrollbarBehavior(); | 142 | setScrollbarBehavior(); | ||
133 | setDarkThemePreference(); | 143 | setDarkThemePreference(); | ||
144 | setWindowDecorationsButtonsOrder(); | ||||
134 | } | 145 | } | ||
135 | 146 | | |||
136 | void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const | 147 | void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const | ||
137 | { | 148 | { | ||
138 | SettingsChangeType changeType = static_cast<SettingsChangeType>(settingsChangeType); | 149 | SettingsChangeType changeType = static_cast<SettingsChangeType>(settingsChangeType); | ||
139 | SettingsCategory settingsCategory = static_cast<SettingsCategory>(arg); | 150 | SettingsCategory settingsCategory = static_cast<SettingsCategory>(arg); | ||
140 | 151 | | |||
141 | if (changeType == SettingsChangeType::Cursor) { | 152 | if (changeType == SettingsChangeType::Cursor) { | ||
142 | setCursorTheme(); | 153 | setCursorTheme(); | ||
143 | } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Style) { | 154 | } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Style) { | ||
144 | setIconsOnButtons(); | 155 | setIconsOnButtons(); | ||
145 | setIconsInMenus(); | 156 | setIconsInMenus(); | ||
146 | setToolbarStyle(); | 157 | setToolbarStyle(); | ||
147 | } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Mouse) { | 158 | } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Mouse) { | ||
148 | setScrollbarBehavior(); | 159 | setScrollbarBehavior(); | ||
149 | } else if (changeType == SettingsChangeType::Palette) { | 160 | } else if (changeType == SettingsChangeType::Palette) { | ||
150 | setDarkThemePreference(); | 161 | setDarkThemePreference(); | ||
151 | } | 162 | } | ||
152 | } | 163 | } | ||
153 | 164 | | |||
165 | void GtkConfig::onKWinSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const | ||||
166 | { | ||||
167 | if (group.name() == QStringLiteral("org.kde.kdecoration2") | ||||
168 | && (names.contains("ButtonsOnRight") || names.contains("ButtonsOnLeft"))) { | ||||
169 | setWindowDecorationsButtonsOrder(); | ||||
170 | } | ||||
171 | } | ||||
172 | | ||||
154 | #include "gtkconfig.moc" | 173 | #include "gtkconfig.moc" |