diff options
author | Victor Kareh <[email protected]> | 2025-08-20 18:56:30 -0400 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2025-08-20 18:56:30 -0400 |
commit | 3f24a3f7d2fbf211255b5f6afd02faf92b763525 (patch) | |
tree | ebf8e98865146dd89f9b4d9a72be763c3f685a73 | |
parent | e57d532ac69fc3f6f5a34d9ce648bbdfb6a81185 (diff) | |
download | mate-settings-daemon-xsettings-overrides.tar.bz2 mate-settings-daemon-xsettings-overrides.tar.xz |
xsettings: Add gsettings for custom XSettings overridesxsettings-overrides
Add XSettings override gsettings to allow changing arbitrary XSettings
on GSettings without requiring code changes. This enables third-party
tools (like unity-gtk-module extensions) to integrate with MATE by
setting custom XSettings values at runtime.
The implementation adds an 'overrides' key to the xsettings plugin
schema which accepts a dictionary mapping XSetting names to values.
The complete list of XSettings is over at
https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/
Backported mostly from:
- https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/commit/c6e9079d
- https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/commit/35764838
Fixes: https://github.com/mate-desktop/mate-settings-daemon/issues/158
-rw-r--r-- | data/org.mate.SettingsDaemon.plugins.xsettings.gschema.xml.in | 5 | ||||
-rw-r--r-- | plugins/xsettings/msd-xsettings-manager.c | 50 | ||||
-rw-r--r-- | plugins/xsettings/xsettings-manager.c | 75 | ||||
-rw-r--r-- | plugins/xsettings/xsettings-manager.h | 3 |
4 files changed, 133 insertions, 0 deletions
diff --git a/data/org.mate.SettingsDaemon.plugins.xsettings.gschema.xml.in b/data/org.mate.SettingsDaemon.plugins.xsettings.gschema.xml.in index ae4721a..bdba044 100644 --- a/data/org.mate.SettingsDaemon.plugins.xsettings.gschema.xml.in +++ b/data/org.mate.SettingsDaemon.plugins.xsettings.gschema.xml.in @@ -10,5 +10,10 @@ <summary>Priority to use for this plugin</summary> <description>Priority to use for this plugin in mate-settings-daemon startup queue</description> </key> + <key type="a{sv}" name="overrides"> + <default>{}</default> + <summary>A dictionary of XSETTINGS to override</summary> + <description>This dictionary maps XSETTINGS names to overrides values. The values must be either strings, signed int32s or (in the case of colors), 4-tuples of uint16 (red, green, blue, alpha; 65535 is fully opaque).</description> + </key> </schema> </schemalist> diff --git a/plugins/xsettings/msd-xsettings-manager.c b/plugins/xsettings/msd-xsettings-manager.c index c8199da..ad9bf82 100644 --- a/plugins/xsettings/msd-xsettings-manager.c +++ b/plugins/xsettings/msd-xsettings-manager.c @@ -56,6 +56,10 @@ #define SCALING_FACTOR_QT_KEY "window-scaling-factor-qt-sync" #define FONT_RENDER_SCHEMA "org.mate.font-rendering" + +#define XSETTINGS_PLUGIN_SCHEMA "org.mate.SettingsDaemon.plugins.xsettings" +#define XSETTINGS_OVERRIDE_KEY "overrides" + #define FONT_ANTIALIASING_KEY "antialiasing" #define FONT_HINTING_KEY "hinting" #define FONT_RGBA_ORDER_KEY "rgba-order" @@ -106,6 +110,7 @@ struct MateXSettingsManagerPrivate XSettingsManager **managers; GHashTable *gsettings; GSettings *gsettings_font; + GSettings *plugin_settings; fontconfig_monitor_handle_t *fontconfig_handle; gint window_scale; }; @@ -744,6 +749,34 @@ xft_callback (GSettings *gsettings G_GNUC_UNUSED, } static void +override_callback (GSettings *settings, + const gchar *key, + MateXSettingsManager *manager) +{ + GVariant *value; + int i; + + value = g_settings_get_value (settings, XSETTINGS_OVERRIDE_KEY); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_overrides (manager->priv->managers [i], value); + xsettings_manager_notify (manager->priv->managers [i]); + } + + g_variant_unref (value); +} + +static void +plugin_callback (GSettings *settings, + const char *key, + MateXSettingsManager *manager) +{ + if (g_str_equal (key, XSETTINGS_OVERRIDE_KEY)) { + override_callback (settings, key, manager); + } +} + +static void fontconfig_callback (fontconfig_monitor_handle_t *handle, MateXSettingsManager *manager) { @@ -972,6 +1005,10 @@ mate_xsettings_manager_start (MateXSettingsManager *manager, g_signal_connect (manager->priv->gsettings_font, "changed", G_CALLBACK (xft_callback), manager); update_xft_settings (manager); + /* Plugin settings (overrides) */ + manager->priv->plugin_settings = g_settings_new (XSETTINGS_PLUGIN_SCHEMA); + g_signal_connect (manager->priv->plugin_settings, "changed", G_CALLBACK (plugin_callback), manager); + start_fontconfig_monitor (manager); for (i = 0; manager->priv->managers [i]; i++) @@ -983,6 +1020,14 @@ mate_xsettings_manager_start (MateXSettingsManager *manager, xsettings_manager_notify (manager->priv->managers [i]); } + /* Load initial overrides */ + GVariant *overrides = g_settings_get_value (manager->priv->plugin_settings, XSETTINGS_OVERRIDE_KEY); + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_overrides (manager->priv->managers [i], overrides); + xsettings_manager_notify (manager->priv->managers [i]); + } + g_variant_unref (overrides); + mate_settings_profile_end (NULL); return TRUE; @@ -1014,6 +1059,11 @@ mate_xsettings_manager_stop (MateXSettingsManager *manager) p->gsettings_font = NULL; } + if (p->plugin_settings != NULL) { + g_object_unref (p->plugin_settings); + p->plugin_settings = NULL; + } + stop_fontconfig_monitor (manager); } diff --git a/plugins/xsettings/xsettings-manager.c b/plugins/xsettings/xsettings-manager.c index 8bf4187..d8f5dd5 100644 --- a/plugins/xsettings/xsettings-manager.c +++ b/plugins/xsettings/xsettings-manager.c @@ -26,6 +26,7 @@ #include <string.h> #include <X11/Xmd.h> /* For CARD16 */ +#include <glib.h> #include "xsettings-manager.h" @@ -44,6 +45,8 @@ struct _XSettingsManager XSettingsList *settings; unsigned long serial; + + GVariant *overrides; }; static XSettingsList *settings; @@ -146,6 +149,7 @@ xsettings_manager_new (Display *display, manager->settings = NULL; manager->serial = 0; + manager->overrides = NULL; manager->window = XCreateSimpleWindow (display, RootWindow (display, screen), @@ -193,6 +197,10 @@ xsettings_manager_destroy (XSettingsManager *manager) XDestroyWindow (manager->display, manager->window); xsettings_list_free (manager->settings); + + if (manager->overrides) + g_variant_unref (manager->overrides); + free (manager); } @@ -423,3 +431,70 @@ xsettings_manager_notify (XSettingsManager *manager) return XSETTINGS_SUCCESS; } +#define XSETTINGS_VARIANT_TYPE_COLOR (G_VARIANT_TYPE ("(qqqq)")) + +void +xsettings_manager_set_overrides (XSettingsManager *manager, + GVariant *overrides) +{ + GVariantIter iter; + const gchar *key; + GVariant *value; + + g_return_if_fail (overrides != NULL && g_variant_is_of_type (overrides, G_VARIANT_TYPE_VARDICT)); + + if (manager->overrides) + { + /* unset the existing overrides */ + + g_variant_iter_init (&iter, manager->overrides); + while (g_variant_iter_next (&iter, "{&sv}", &key, NULL)) + /* only unset it at this point if it's not in the new list */ + if (!g_variant_lookup (overrides, key, "*", NULL)) + xsettings_manager_delete_setting (manager, key); + g_variant_unref (manager->overrides); + } + + /* save this so we can do the unsets next time */ + manager->overrides = g_variant_ref_sink (overrides); + + /* set the new values */ + g_variant_iter_init (&iter, overrides); + while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) + { + XSettingsSetting *setting; + + /* only accept recognised types... */ + if (!g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) && + !g_variant_is_of_type (value, G_VARIANT_TYPE_INT32) && + !g_variant_is_of_type (value, XSETTINGS_VARIANT_TYPE_COLOR)) + continue; + + setting = g_new0 (XSettingsSetting, 1); + setting->name = g_strdup (key); + + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) + { + setting->type = XSETTINGS_TYPE_STRING; + setting->data.v_string = g_strdup (g_variant_get_string (value, NULL)); + } + else if (g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)) + { + setting->type = XSETTINGS_TYPE_INT; + setting->data.v_int = g_variant_get_int32 (value); + } + else if (g_variant_is_of_type (value, XSETTINGS_VARIANT_TYPE_COLOR)) + { + guint16 red, green, blue, alpha; + + g_variant_get (value, "(qqqq)", &red, &green, &blue, &alpha); + setting->type = XSETTINGS_TYPE_COLOR; + setting->data.v_color.red = red; + setting->data.v_color.green = green; + setting->data.v_color.blue = blue; + setting->data.v_color.alpha = alpha; + } + + xsettings_manager_set_setting (manager, setting); + } +} diff --git a/plugins/xsettings/xsettings-manager.h b/plugins/xsettings/xsettings-manager.h index 55f674b..ebd7740 100644 --- a/plugins/xsettings/xsettings-manager.h +++ b/plugins/xsettings/xsettings-manager.h @@ -25,6 +25,7 @@ #define XSETTINGS_MANAGER_H #include <X11/Xlib.h> +#include <glib.h> #include "xsettings-common.h" #ifdef __cplusplus @@ -62,6 +63,8 @@ XSettingsResult xsettings_manager_set_color (XSettingsManager *manage const char *name, const XSettingsColor *value); XSettingsResult xsettings_manager_notify (XSettingsManager *manager); +void xsettings_manager_set_overrides (XSettingsManager *manager, + GVariant *overrides); #ifdef __cplusplus } |