Commit 2b12ceb1 authored by Mikhail Zolotukhin's avatar Mikhail Zolotukhin
Browse files

Synchronize decorations buttons order in GTK headerbars

Summary:
Window decorations button order was applied only for window headers that was controlled by KWin, but not for GTK applications with CSD.  Now it is no longer true - button order in CSD applications are in sync with the one used by KWin.

Only Close, Maximize, Minimize and Icon buttons are synchronized, because GTK supports only them.

Depends on D25695

Test Plan:
# Open two windows alongside each other: window decorations button order settings and any gtk3 app with CSD (for example, Lutris)
# Restart kded5
# Apply any WD button order, apply settings
# The app should change its buttons order in headerbar (if xsettingsd is not installed, on X11 only after restart)
{F7794441}

Reviewers: #vdg, cblack, #plasma, apol

Reviewed By: apol

Subscribers: apol, GB_2, broulik, plasma-devel

Tags: #plasma

Maniphest Tasks: T10611

Differential Revision: https://phabricator.kde.org/D25670
parent 99c72b4b
......@@ -45,9 +45,9 @@ static QString readFileContents(QFile &gtkrc);
static pid_t pidOfXSettingsd();
void ConfigEditor::setGtk3ConfigValueDconf(const QString &paramName, const QString &paramValue)
void ConfigEditor::setGtk3ConfigValueDconf(const QString &paramName, const QString &paramValue, 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());
}
......
......@@ -20,14 +20,14 @@
#pragma once
#include <unistd.h>
#include <QString>
class QString;
class QFile;
namespace ConfigEditor
{
void setGtk2ConfigValue(const QString &paramName, const QString &paramValue);
void setGtk3ConfigValueDconf(const QString &paramName, const QString &paramValue);
void setGtk3ConfigValueDconf(const QString &paramName, const QString &paramValue, const QString &category = QStringLiteral("org.gnome.desktop.interface"));
void setGtk3ConfigValueSettingsIni(const QString &paramName, const QString &paramValue);
void setGtk3ConfigValueXSettingsd(const QString &paramName, const QString &paramValue);
};
......@@ -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::preferDarkTheme() const
}
}
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 @@ QString ConfigValueProvider::toolbarStyleInDesiredNotation(const QString &kdeCon
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;
}
......@@ -44,10 +44,13 @@ public:
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;
};
......@@ -26,6 +26,7 @@
#include <KIconLoader>
#include <KPluginFactory>
#include <KConfigWatcher>
#include "gtkconfig.h"
#include "configvalueprovider.h"
......@@ -34,17 +35,18 @@ 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 @@ void GtkConfig::setDarkThemePreference() const
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 @@ void GtkConfig::applyAllSettings() const
setToolbarStyle();
setScrollbarBehavior();
setDarkThemePreference();
setWindowDecorationsButtonsOrder();
}
void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const
......@@ -151,4 +162,12 @@ void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const
}
}
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"
......@@ -22,6 +22,7 @@
#pragma once
#include <KDEDModule>
#include <KConfigWatcher>
#include "configeditor.h"
#include "configvalueprovider.h"
......@@ -64,12 +65,15 @@ public:
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> configValueProvider;
KConfigWatcher::Ptr kwinConfigWatcher;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment