[xfce4-settings 4/5] XfceXSettingsHelper gets a property "cursor-hide"

Andreas Müller schnitzeltony at googlemail.com
Mon Nov 5 01:27:07 CET 2012


This property set overrides overrides cursor theme to "xfce-invisible".

Signed-off-by: Andreas Müller <schnitzeltony at googlemail.com>
---
 xfsettingsd/xsettings.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 114 insertions(+), 1 deletions(-)

diff --git a/xfsettingsd/xsettings.c b/xfsettingsd/xsettings.c
index 7657465..a6278df 100644
--- a/xfsettingsd/xsettings.c
+++ b/xfsettingsd/xsettings.c
@@ -73,6 +73,15 @@ typedef struct _XfceXSettingsNotify XfceXSettingsNotify;
 
 
 
+/* Property identifiers */
+enum
+{
+    PROP_0,
+    PROP_CURSOR_HIDE,
+};
+
+
+
 static void     xfce_xsettings_helper_finalize     (GObject             *object);
 static void     xfce_xsettings_helper_fc_free      (XfceXSettingsHelper *helper);
 static gboolean xfce_xsettings_helper_fc_init      (gpointer             data);
@@ -86,6 +95,10 @@ static void     xfce_xsettings_helper_load         (XfceXSettingsHelper *helper)
 static void     xfce_xsettings_helper_screen_free  (XfceXSettingsScreen *screen);
 static void     xfce_xsettings_helper_notify_xft   (XfceXSettingsHelper *helper);
 static void     xfce_xsettings_helper_notify       (XfceXSettingsHelper *helper);
+static void     xfce_xsettings_helper_set_property (GObject              *object,
+                                                    guint                 prop_id,
+                                                    const GValue         *value,
+                                                    GParamSpec           *pspec);
 
 
 
@@ -120,6 +133,13 @@ struct _XfceXSettingsHelper
     GPtrArray     *fc_monitors;
     guint          fc_notify_timeout_id;
     guint          fc_init_id;
+
+    /* keeper for invisible cursor theme / last set */
+    GValue         *invisib_cursor_value;
+    GValue         *lastset_cursor_value;
+
+    /* properties */
+    gboolean       cursor_hide;
 };
 
 struct _XfceXSetting
@@ -157,6 +177,16 @@ xfce_xsettings_helper_class_init (XfceXSettingsHelperClass *klass)
 
     gobject_class = G_OBJECT_CLASS (klass);
     gobject_class->finalize = xfce_xsettings_helper_finalize;
+    gobject_class->set_property = xfce_xsettings_helper_set_property;
+
+    g_object_class_install_property (gobject_class,
+                                     PROP_CURSOR_HIDE,
+                                     g_param_spec_boolean ("cursor-hide",
+                                                           "cursor-hide",
+                                                           "cursor-hide",
+                                                           FALSE,
+                                                           G_PARAM_WRITABLE |
+                                                           G_PARAM_STATIC_STRINGS));
 }
 
 
@@ -169,6 +199,14 @@ xfce_xsettings_helper_init (XfceXSettingsHelper *helper)
     helper->settings = g_hash_table_new_full (g_str_hash, g_str_equal,
         g_free, xfce_xsettings_helper_setting_free);
 
+    helper->lastset_cursor_value = g_new0 (GValue, 1);
+    g_value_init(helper->lastset_cursor_value, G_TYPE_STRING);
+    g_value_set_string (helper->lastset_cursor_value, "default");
+
+    helper->invisib_cursor_value = g_new0 (GValue, 1);
+    g_value_init(helper->invisib_cursor_value, G_TYPE_STRING);
+    g_value_set_string (helper->invisib_cursor_value, "xfce-invisible");
+
     xfce_xsettings_helper_load (helper);
 
     g_signal_connect (G_OBJECT (helper->channel), "property-changed",
@@ -202,6 +240,9 @@ xfce_xsettings_helper_finalize (GObject *object)
 
     g_hash_table_destroy (helper->settings);
 
+    g_free (helper->lastset_cursor_value);
+    g_free (helper->invisib_cursor_value);
+
     (*G_OBJECT_CLASS (xfce_xsettings_helper_parent_class)->finalize) (object);
 }
 
@@ -387,6 +428,53 @@ xfce_xsettings_helper_notify_xft_idle (gpointer data)
 
 
 
+static void
+xfce_xsettings_helper_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  gboolean             hide;
+  XfceXSetting        *setting;
+  XfceXSettingsHelper *helper = XFCE_XSETTINGS_HELPER (object);
+
+  switch (prop_id)
+  {
+      case PROP_CURSOR_HIDE:
+          hide = g_value_get_boolean (value);
+          if (helper->cursor_hide != hide)
+          {
+              helper->cursor_hide = hide;
+              setting = g_hash_table_lookup (helper->settings, "/Gtk/CursorThemeName");
+              if (G_LIKELY (setting != NULL))
+              {
+                  /* update the serial */
+                  setting->last_change_serial = helper->serial;
+                  /* update value */
+                  g_value_reset (setting->value);
+                  g_value_copy (hide ?
+                                    helper->invisib_cursor_value :
+                                    helper->lastset_cursor_value,
+                                setting->value);
+
+                  /* schedule xsettings update */
+                  if (helper->notify_idle_id == 0)
+                      helper->notify_idle_id = g_idle_add (xfce_xsettings_helper_notify_idle, helper);
+                  if (helper->notify_xft_idle_id == 0)
+                      helper->notify_xft_idle_id = g_idle_add (xfce_xsettings_helper_notify_xft_idle, helper);
+              }
+              else
+                  g_critical("Setting not found for /Gtk/CursorThemeName");
+          }
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+
 static gboolean
 xfce_xsettings_helper_prop_valid (const gchar  *prop_name,
                                   const GValue *value)
@@ -413,6 +501,28 @@ xfce_xsettings_helper_prop_valid (const gchar  *prop_name,
 
 
 
+static void
+xfce_xsettings_helper_check_cursor (const gchar         *prop_name,
+                                    GValue              *value,
+                                    XfceXSettingsHelper *helper)
+{
+    if (g_strcmp0 (prop_name, "/Gtk/CursorThemeName") == 0)
+    {
+        /* Keep last cursor theme set */
+        g_value_reset (helper->lastset_cursor_value);
+        g_value_copy (value, helper->lastset_cursor_value);
+
+        /* invisible replacement required ? */
+        if (helper->cursor_hide)
+        {
+            g_value_reset (value);
+            g_value_copy (helper->invisib_cursor_value, value);
+        }
+    }
+}
+
+
+
 static gboolean
 xfce_xsettings_helper_prop_load (gchar               *prop_name,
                                  GValue              *value,
@@ -426,6 +536,7 @@ xfce_xsettings_helper_prop_load (gchar               *prop_name,
 
     setting = g_slice_new0 (XfceXSetting);
     setting->value = value;
+    xfce_xsettings_helper_check_cursor (prop_name, setting->value, helper);
     setting->last_change_serial = helper->serial;
 
     xfsettings_dbg_filtered (XFSD_DEBUG_XSETTINGS, "prop \"%s\" loaded (type=%s)",
@@ -462,6 +573,7 @@ xfce_xsettings_helper_prop_changed (XfconfChannel       *channel,
              * it first */
             g_value_reset (setting->value);
             g_value_copy (value, setting->value);
+            xfce_xsettings_helper_check_cursor (prop_name, setting->value, helper);
 
             /* update the serial */
             setting->last_change_serial = helper->serial;
@@ -475,6 +587,7 @@ xfce_xsettings_helper_prop_changed (XfconfChannel       *channel,
 
             g_value_init (setting->value, G_VALUE_TYPE (value));
             g_value_copy (value, setting->value);
+            xfce_xsettings_helper_check_cursor (prop_name, setting->value, helper);
 
             g_hash_table_insert (helper->settings, g_strdup (prop_name), setting);
         }
@@ -649,6 +762,7 @@ xfce_xsettings_helper_notify_xft (XfceXSettingsHelper *helper)
     XfceXSetting *setting;
     guint         i;
     GValue        bool_val = { 0, };
+
     const gchar  *props[][2] =
     {
         /* { xfconf name}, { xft name } */
@@ -700,7 +814,6 @@ xfce_xsettings_helper_notify_xft (XfceXSettingsHelper *helper)
                      PropModeReplace,
                      (guchar *) resource->str,
                      resource->len);
-
     XCloseDisplay (xdisplay);
 
     if (gdk_error_trap_pop () != 0)
-- 
1.7.4.4



More information about the Xfce4-dev mailing list