From 878fe1287a4c73f67dd2b51d1d7c450097aeffa7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@googlemail.com>
Date: Thu, 20 Dec 2012 16:49:18 +0100
Subject: [PATCH 4/5] XfceXSettingsHelper gets a property
 "touchscreen-pointer"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When this property is set, it overrides overrides cursor theme to
"xfce-invisible" and sets /Gtk/TouchscreenMode.

Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>
Upstream-Status: Submitted [1]
[1] https://bugzilla.xfce.org/show_bug.cgi?id=9474
---
 xfsettingsd/xsettings.c   |  122 ++++++++++++++++++++++++++++++++++++++++++++-
 xfsettingsd/xsettings.xml |    1 +
 2 files changed, 122 insertions(+), 1 deletions(-)

diff --git a/xfsettingsd/xsettings.c b/xfsettingsd/xsettings.c
index 7657465..76bcea1 100644
--- a/xfsettingsd/xsettings.c
+++ b/xfsettingsd/xsettings.c
@@ -73,6 +73,15 @@ typedef struct _XfceXSettingsNotify XfceXSettingsNotify;
 
 
 
+/* Property identifiers */
+enum
+{
+    PROP_0,
+    PROP_TOUCHSCREEN_POINTER,
+};
+
+
+
 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 touchscreen cursor theme / last set */
+    GValue         *touchscreen_cursor_value;
+    GValue         *lastset_cursor_value;
+
+    /* properties */
+    gboolean       touchscreen_pointer;
 };
 
 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_TOUCHSCREEN_POINTER,
+                                     g_param_spec_boolean ("touchscreen-pointer",
+                                                           "touchscreen-pointer",
+                                                           "touchscreen-pointer",
+                                                           FALSE,
+                                                           G_PARAM_WRITABLE |
+                                                           G_PARAM_STATIC_STRINGS));
 }
 
 
@@ -169,6 +199,13 @@ 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->touchscreen_cursor_value = g_new0 (GValue, 1);
+    g_value_init(helper->touchscreen_cursor_value, G_TYPE_STRING);
+    g_value_set_string (helper->touchscreen_cursor_value, "xfce-invisible");
+
     xfce_xsettings_helper_load (helper);
 
     g_signal_connect (G_OBJECT (helper->channel), "property-changed",
@@ -202,6 +239,9 @@ xfce_xsettings_helper_finalize (GObject *object)
 
     g_hash_table_destroy (helper->settings);
 
+    g_free (helper->lastset_cursor_value);
+    g_free (helper->touchscreen_cursor_value);
+
     (*G_OBJECT_CLASS (xfce_xsettings_helper_parent_class)->finalize) (object);
 }
 
@@ -387,6 +427,61 @@ 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             touchscreen_pointer;
+  XfceXSetting        *setting_theme, *setting_touchscreen;
+  XfceXSettingsHelper *helper = XFCE_XSETTINGS_HELPER (object);
+  GtkSettings         *gtk_settings;
+  GValue               bool_val = { 0, };
+
+  switch (prop_id)
+  {
+      case PROP_TOUCHSCREEN_POINTER:
+          touchscreen_pointer = g_value_get_boolean (value);
+          if (helper->touchscreen_pointer != touchscreen_pointer)
+          {
+              helper->touchscreen_pointer = touchscreen_pointer;
+              /* Update touchscreen-mode */
+              xfconf_channel_set_bool (helper->channel, "/Gtk/TouchscreenMode", touchscreen_pointer);
+              /* Update cursor */
+              setting_theme = g_hash_table_lookup (helper->settings, "/Gtk/CursorThemeName");
+              if (G_LIKELY (setting_theme != NULL))
+              {
+                  /* update the serial */
+                  setting_theme->last_change_serial = helper->serial;
+                  /* update value */
+                  g_value_reset (setting_theme->value);
+                  g_value_copy (touchscreen_pointer ?
+                                    helper->touchscreen_cursor_value :
+                                    helper->lastset_cursor_value,
+                                setting_theme->value);
+              }
+              else
+                  g_critical("Setting not found for /Gtk/CursorThemeName");
+
+              if (G_LIKELY (setting_touchscreen != NULL || setting_theme != NULL))
+              {
+                  /* 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);
+              }
+          }
+      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 +508,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->touchscreen_pointer)
+        {
+            g_value_reset (value);
+            g_value_copy (helper->touchscreen_cursor_value, value);
+        }
+    }
+}
+
+
+
 static gboolean
 xfce_xsettings_helper_prop_load (gchar               *prop_name,
                                  GValue              *value,
@@ -426,6 +543,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 +580,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 +594,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 +769,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 +821,6 @@ xfce_xsettings_helper_notify_xft (XfceXSettingsHelper *helper)
                      PropModeReplace,
                      (guchar *) resource->str,
                      resource->len);
-
     XCloseDisplay (xdisplay);
 
     if (gdk_error_trap_pop () != 0)
--- a/xfsettingsd/xsettings.xml
+++ b/xfsettingsd/xsettings.xml
@@ -36,5 +36,6 @@
     <property name="MenuBarAccel" type="string" value="F10"/>
     <property name="CursorThemeName" type="string" value=""/>
     <property name="CursorThemeSize" type="int" value="0"/>
+    <property name="TouchscreenMode" type="bool" value="false"/>
   </property>
 </channel>
-- 
1.7.6.5

