Commit 07a01254 authored by Jan Blackquill's avatar Jan Blackquill 🌈 Committed by Jan Blackquill
Browse files

Begin writing out settings to GTK4

GTK4 seems to be coming out later this year (Plasma 5.21 should release after GTK4 releases), and there doesn't seem to be any major changes coming up in regards to how configuration will be handled.

As such, this patch begins writing out to GTK4 configuration files.

Code has been refactored to reduce duplication of similar code between GTK3 and GTK4, and elements shared between both have dropped the GTK3 prefix.
parent 65187087
......@@ -39,7 +39,7 @@ void upgradeGtk3Theme() {
|| currentGtk3Theme == QStringLiteral("BreezyGTK")
|| currentGtk3Theme == QStringLiteral("Orion")
) {
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("gtk-theme"), QStringLiteral("Breeze"));
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("gtk-theme"), QStringLiteral("Breeze"));
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name"), QStringLiteral("Breeze"));
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/ThemeName"), QStringLiteral("Breeze"));
}
......
......@@ -27,7 +27,7 @@
#include "configeditor.h"
void ConfigEditor::setGtk3ConfigValueGSettings(const QString &paramName, const QVariant &paramValue, const QString &category)
void ConfigEditor::setGtkConfigValueGSettings(const QString &paramName, const QVariant &paramValue, const QString &category)
{
g_autoptr(GSettings) gsettings = g_settings_new(category.toUtf8().constData());
......@@ -40,16 +40,16 @@ void ConfigEditor::setGtk3ConfigValueGSettings(const QString &paramName, const Q
}
}
void ConfigEditor::setGtk3ConfigValueGSettingsAsEnum(const QString& paramName, int paramValue, const QString& category)
void ConfigEditor::setGtkConfigValueGSettingsAsEnum(const QString& paramName, int paramValue, const QString& category)
{
g_autoptr(GSettings) gsettings = g_settings_new(category.toUtf8().constData());
g_settings_set_enum(gsettings, paramName.toUtf8().constData(), paramValue);
}
void ConfigEditor::setGtk3ConfigValueSettingsIni(const QString &paramName, const QVariant &paramValue)
void ConfigEditor::setGtkConfigValueSettingsIni(const QString &versionString, const QString &paramName, const QVariant &paramValue)
{
QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
QString gtk3ConfigPath = configLocation + QStringLiteral("/gtk-3.0/settings.ini");
QString gtk3ConfigPath = configLocation + QStringLiteral("/") + versionString + QStringLiteral("/settings.ini");
KSharedConfig::Ptr gtk3Config = KSharedConfig::openConfig(gtk3ConfigPath, KConfig::NoGlobals);
KConfigGroup group = gtk3Config->group(QStringLiteral("Settings"));
......@@ -58,6 +58,17 @@ void ConfigEditor::setGtk3ConfigValueSettingsIni(const QString &paramName, const
group.sync();
}
QString ConfigEditor::gtkConfigValueSettingsIni(const QString &versionString, const QString &paramName)
{
QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
QString gtk3ConfigPath = configLocation + QStringLiteral("/") + versionString + QStringLiteral("/settings.ini");
KSharedConfig::Ptr gtk3Config = KSharedConfig::openConfig(gtk3ConfigPath, KConfig::NoGlobals);
KConfigGroup group = gtk3Config->group(QStringLiteral("Settings"));
return group.readEntry(paramName);
}
void ConfigEditor::setGtk3ConfigValueXSettingsd(const QString &paramName, const QVariant &paramValue)
{
QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
......@@ -112,17 +123,6 @@ void ConfigEditor::setGtk3Colors(const QMap<QString, QColor> &colorsDefinitions)
addGtkModule(QStringLiteral("colorreload-gtk-module"));
}
QString ConfigEditor::gtk3ConfigValueSettingsIni(const QString& paramName)
{
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"));
return group.readEntry(paramName);
}
void ConfigEditor::removeLegacyGtk2Strings()
{
......
......@@ -7,6 +7,7 @@
#include <unistd.h>
#include <QString>
#include <functional>
class QColor;
class QFile;
......@@ -14,19 +15,26 @@ class QVariant;
namespace ConfigEditor
{
using namespace std::placeholders;
void setGtk2ConfigValue(const QString &paramName, const QVariant &paramValue);
void setGtk3ConfigValueGSettings(const QString &paramName, const QVariant &paramValue, const QString &category = QStringLiteral("org.gnome.desktop.interface"));
void setGtk3ConfigValueGSettingsAsEnum(const QString &paramName, int paramValue, const QString &category = QStringLiteral("org.gnome.desktop.interface"));
void setGtk3ConfigValueSettingsIni(const QString &paramName, const QVariant &paramValue);
void setGtkConfigValueGSettings(const QString &paramName, const QVariant &paramValue, const QString &category = QStringLiteral("org.gnome.desktop.interface"));
void setGtkConfigValueGSettingsAsEnum(const QString &paramName, int paramValue, const QString &category = QStringLiteral("org.gnome.desktop.interface"));
void setGtk3ConfigValueXSettingsd(const QString &paramName, const QVariant &paramValue);
void setGtkConfigValueSettingsIni(const QString &versionString, const QString &paramName, const QVariant &paramValue);
static auto setGtk4ConfigValueSettingsIni = std::bind(setGtkConfigValueSettingsIni, QStringLiteral("gtk-4.0"), _1, _2);
static auto setGtk3ConfigValueSettingsIni = std::bind(setGtkConfigValueSettingsIni, QStringLiteral("gtk-3.0"), _1, _2);
QString gtkConfigValueSettingsIni(const QString &versionString, const QString &paramName);
static auto gtk4ConfigValueSettingsIni = std::bind(gtkConfigValueSettingsIni, QStringLiteral("gtk-4.0"), _1);
static auto gtk3ConfigValueSettingsIni = std::bind(gtkConfigValueSettingsIni, QStringLiteral("gtk-3.0"), _1);
void setCustomClientSideDecorations(const QStringList &windowDecorationsButtonsImages);
void disableCustomClientSideDecorations();
void setGtk3Colors(const QMap<QString, QColor> &colorsDefinitions);
QString gtk3ConfigValueSettingsIni(const QString& paramName);
void removeLegacyGtk2Strings();
......
......@@ -52,8 +52,9 @@ GtkConfig::~GtkConfig()
void GtkConfig::setGtkTheme(const QString &themeName) const
{
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-theme-name"), themeName);
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("gtk-theme"), themeName);
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("gtk-theme"), themeName);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-theme-name"), themeName);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-theme-name"), themeName);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/ThemeName"), themeName);
// Window decorations are part of the theme, in case of Breeze we inject custom ones from KWin
......@@ -74,8 +75,9 @@ void GtkConfig::setFont() const
{
const QString configFontName = configValueProvider->fontName();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName);
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("font-name"), configFontName);
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("font-name"), configFontName);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-font-name"), configFontName);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-font-name"), configFontName);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/FontName"), configFontName);
}
......@@ -83,8 +85,9 @@ void GtkConfig::setIconTheme() const
{
const QString iconThemeName = configValueProvider->iconThemeName();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-icon-theme-name"), iconThemeName);
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("icon-theme"), iconThemeName);
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("icon-theme"), iconThemeName);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-icon-theme-name"), iconThemeName);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-icon-theme-name"), iconThemeName);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/IconThemeName"), iconThemeName);
}
......@@ -92,8 +95,9 @@ void GtkConfig::setCursorTheme() const
{
const QString cursorThemeName = configValueProvider->cursorThemeName();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName);
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("cursor-theme"), cursorThemeName);
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("cursor-theme"), cursorThemeName);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/CursorThemeName"), cursorThemeName);
}
......@@ -101,8 +105,9 @@ void GtkConfig::setCursorSize() const
{
const int cursorSize = configValueProvider->cursorSize();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-cursor-theme-size"), cursorSize);
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("cursor-size"), cursorSize);
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("cursor-size"), cursorSize);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-size"), cursorSize);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-size"), cursorSize);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/CursorThemeSize"), cursorSize);
}
......@@ -111,6 +116,7 @@ void GtkConfig::setIconsOnButtons() const
const bool iconsOnButtonsConfigValue = configValueProvider->iconsOnButtons();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ButtonImages"), iconsOnButtonsConfigValue);
}
......@@ -119,6 +125,7 @@ void GtkConfig::setIconsInMenus() const
const bool iconsInMenusConfigValue = configValueProvider->iconsInMenus();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/MenuImages"), iconsInMenusConfigValue);
}
......@@ -126,8 +133,9 @@ void GtkConfig::setToolbarStyle() const
{
const int toolbarStyle = configValueProvider->toolbarStyle();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-toolbar-style"), toolbarStyle);
ConfigEditor::setGtk3ConfigValueGSettingsAsEnum(QStringLiteral("toolbar-style"), toolbarStyle);
ConfigEditor::setGtkConfigValueGSettingsAsEnum(QStringLiteral("toolbar-style"), toolbarStyle);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-toolbar-style"), toolbarStyle);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-toolbar-style"), toolbarStyle);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ToolbarStyle"), toolbarStyle);
}
......@@ -136,6 +144,7 @@ void GtkConfig::setScrollbarBehavior() const
const bool scrollbarBehavior = configValueProvider->scrollbarBehavior();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-primary-button-warps-slider"), scrollbarBehavior);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-primary-button-warps-slider"), scrollbarBehavior);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-primary-button-warps-slider"), scrollbarBehavior);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/PrimaryButtonWarpsSlider"), scrollbarBehavior);
}
......@@ -143,6 +152,7 @@ void GtkConfig::setDarkThemePreference() const
{
const bool preferDarkTheme = configValueProvider->preferDarkTheme();
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-application-prefer-dark-theme"), preferDarkTheme);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-application-prefer-dark-theme"), preferDarkTheme);
}
void GtkConfig::setWindowDecorationsAppearance() const
......@@ -158,8 +168,9 @@ void GtkConfig::setWindowDecorationsAppearance() const
void GtkConfig::setWindowDecorationsButtonsOrder() const
{
const QString windowDecorationsButtonOrder = configValueProvider->windowDecorationsButtonsOrder();
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("button-layout"), windowDecorationsButtonOrder, QStringLiteral("org.gnome.desktop.wm.preferences"));
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("button-layout"), windowDecorationsButtonOrder, QStringLiteral("org.gnome.desktop.wm.preferences"));
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-decoration-layout"), windowDecorationsButtonOrder);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-decoration-layout"), windowDecorationsButtonOrder);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/DecorationLayout"), windowDecorationsButtonOrder);
}
......@@ -167,8 +178,9 @@ void GtkConfig::setEnableAnimations() const
{
const bool enableAnimations = configValueProvider->enableAnimations();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-enable-animations"), enableAnimations);
ConfigEditor::setGtk3ConfigValueGSettings(QStringLiteral("enable-animations"), enableAnimations);
ConfigEditor::setGtkConfigValueGSettings(QStringLiteral("enable-animations"), enableAnimations);
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-enable-animations"), enableAnimations);
ConfigEditor::setGtk4ConfigValueSettingsIni(QStringLiteral("gtk-enable-animations"), enableAnimations);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/EnableAnimations"), enableAnimations);
}
......
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