Commit 66ab37df authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Bind gtk-enable-animations setting to global animation speed slider

When it is set to "Instant", turn off GTK animations.

Differential Revision: https://phabricator.kde.org/D26825
parent aa90a08b
......@@ -35,6 +35,12 @@
#include "configeditor.h"
void ConfigEditor::setGtk3ConfigValueDconf(const QString &paramName, bool paramValue, const QString &category)
{
g_autoptr(GSettings) gsettings = g_settings_new(category.toUtf8().constData());
g_settings_set_boolean(gsettings, paramName.toUtf8().constData(), paramValue);
}
void ConfigEditor::setGtk3ConfigValueDconf(const QString &paramName, const QString &paramValue, const QString &category)
{
g_autoptr(GSettings) gsettings = g_settings_new(category.toUtf8().constData());
......@@ -164,6 +170,7 @@ void ConfigEditor::replaceValueInGtkrcContents(QString &gtkrcContents, const QSt
QStringLiteral("gtk-menu-images"),
QStringLiteral("gtk-button-images"),
QStringLiteral("gtk-primary-button-warps-slider"),
QStringLiteral("gtk-enable-animations"),
};
QString newConfigString;
......@@ -189,6 +196,7 @@ void ConfigEditor::replaceValueInXSettingsdContents(QString &xSettingsdContents,
QStringLiteral("Gtk/MenuImages"),
QStringLiteral("Gtk/ToolbarStyle"),
QStringLiteral("Gtk/PrimaryButtonWarpsSlider"),
QStringLiteral("Gtk/EnableAnimations"),
};
QString newConfigString;
......
......@@ -28,6 +28,7 @@ class QString;
namespace ConfigEditor
{
void setGtk2ConfigValue(const QString &paramName, const QString &paramValue);
void setGtk3ConfigValueDconf(const QString &paramName, bool paramValue, const QString &category = QStringLiteral("org.gnome.desktop.interface"));
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);
......
......@@ -140,6 +140,20 @@ QString ConfigValueProvider::windowDecorationsButtonsOrder() const
return buttonsOnLeftInGtkNotation + QStringLiteral(":") + buttonsOnRightInGtkNotation;
}
QString ConfigValueProvider::enableAnimations() const
{
KConfigGroup generalCfg = kdeglobalsConfig->group(QStringLiteral("KDE"));
const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0));
const bool enableAnimations = !qFuzzyIsNull(animationSpeedModifier);
if (enableAnimations) {
return QStringLiteral("1");
} else {
return QStringLiteral("0");
}
}
QString ConfigValueProvider::toolbarStyleInDesiredNotation(const QString &kdeConfigValue, ConfigValueProvider::ToolbarStyleNotation notation) const
{
QStringList toolbarStyles {};
......
......@@ -45,6 +45,7 @@ public:
QString scrollbarBehavior() const;
QString preferDarkTheme() const;
QString windowDecorationsButtonsOrder() const;
QString enableAnimations() const;
private:
QString toolbarStyleInDesiredNotation(const QString &kdeConfigValue, ToolbarStyleNotation notation) const;
......
......@@ -38,6 +38,7 @@ GtkConfig::GtkConfig(QObject *parent, const QVariantList&) :
KDEDModule(parent),
configValueProvider(new ConfigValueProvider()),
themePreviewer(new ThemePreviewer(this)),
kdeglobalsConfigWatcher(KConfigWatcher::create(KSharedConfig::openConfig(QStringLiteral("kdeglobals")))),
kwinConfigWatcher(KConfigWatcher::create(KSharedConfig::openConfig(QStringLiteral("kwinrc"))))
{
QDBusConnection dbus = QDBusConnection::sessionBus();
......@@ -46,6 +47,7 @@ GtkConfig::GtkConfig(QObject *parent, const QVariantList&) :
connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont);
connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &GtkConfig::setIconTheme);
connect(kdeglobalsConfigWatcher.data(), &KConfigWatcher::configChanged, this, &GtkConfig::onKdeglobalsSettingsChange);
connect(kwinConfigWatcher.data(), &KConfigWatcher::configChanged, this, &GtkConfig::onKWinSettingsChange);
dbus.connect(
QString(),
......@@ -180,6 +182,16 @@ void GtkConfig::setWindowDecorationsButtonsOrder() const
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/DecorationLayout"), windowDecorationsButtonOrder);
}
void GtkConfig::setEnableAnimations() const
{
const QString enableAnimations = configValueProvider->enableAnimations();
ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-enable-animations"), enableAnimations);
// FIXME work with booleans in configValueProvider...
ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("enable-animations"), enableAnimations == QLatin1String("1"));
ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-enable-animations"), enableAnimations);
ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/EnableAnimations"), enableAnimations);
}
void GtkConfig::applyAllSettings() const
{
setFont();
......@@ -191,6 +203,7 @@ void GtkConfig::applyAllSettings() const
setScrollbarBehavior();
setDarkThemePreference();
setWindowDecorationsButtonsOrder();
setEnableAnimations();
}
void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const
......@@ -211,6 +224,14 @@ void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const
}
}
void GtkConfig::onKdeglobalsSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const
{
if (group.name() == QLatin1String("KDE")
&& names.contains(QByteArrayLiteral("AnimationDurationFactor"))) {
setEnableAnimations();
}
}
void GtkConfig::onKWinSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const
{
if (group.name() == QStringLiteral("org.kde.kdecoration2")
......
......@@ -69,6 +69,7 @@ public:
void setScrollbarBehavior() const;
void setDarkThemePreference() const;
void setWindowDecorationsButtonsOrder() const;
void setEnableAnimations() const;
void applyAllSettings() const;
......@@ -83,10 +84,12 @@ public Q_SLOTS:
Q_SCRIPTABLE void showGtk3ThemePreview(const QString &themeName) const;
void onGlobalSettingsChange(int settingsChangeType, int arg) const;
void onKdeglobalsSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const;
void onKWinSettingsChange(const KConfigGroup &group, const QByteArrayList &names) const;
private:
QScopedPointer<ConfigValueProvider> configValueProvider;
QScopedPointer<ThemePreviewer> themePreviewer;
KConfigWatcher::Ptr kdeglobalsConfigWatcher;
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