[Xfce4-commits] <xfce4-settings:nick/pointers> Add daemon support to launch syndaemon.
Nick Schermer
noreply at xfce.org
Sun May 22 12:50:02 CEST 2011
Updating branch refs/heads/nick/pointers
to 1c4d72c76635be8f5ff15561498247ea83319c93 (commit)
from 73974f24dd6115fa40278a123acac7125897a7d6 (commit)
commit 1c4d72c76635be8f5ff15561498247ea83319c93
Author: Nick Schermer <nick at xfce.org>
Date: Sun May 22 12:44:08 2011 +0200
Add daemon support to launch syndaemon.
Code to detect synaptics touchpads and handle the syndaemon
process. This is handled through the /DisableTouchpadWhileTyping
xfconf property.
The syndaemon commands used is "syndaemon -i 2.0 -K -R", the 2 second
timeout is used in Gnome and also the default of the daemon.
xfsettingsd/pointers.c | 176 +++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 160 insertions(+), 16 deletions(-)
diff --git a/xfsettingsd/pointers.c b/xfsettingsd/pointers.c
index 26f4feb..077382c 100644
--- a/xfsettingsd/pointers.c
+++ b/xfsettingsd/pointers.c
@@ -20,10 +20,17 @@
#include <config.h>
#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
+
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/extensions/XI.h>
@@ -63,15 +70,19 @@
-static void xfce_pointers_helper_restore_devices (XfcePointersHelper *helper,
- XID *xid);
-static void xfce_pointers_helper_channel_property_changed (XfconfChannel *channel,
- const gchar *property_name,
- const GValue *value);
+static void xfce_pointers_helper_finalize (GObject *object);
+static void xfce_pointers_helper_syndaemon_stop (XfcePointersHelper *helper);
+static void xfce_pointers_helper_syndaemon_check (XfcePointersHelper *helper);
+static void xfce_pointers_helper_restore_devices (XfcePointersHelper *helper,
+ XID *xid);
+static void xfce_pointers_helper_channel_property_changed (XfconfChannel *channel,
+ const gchar *property_name,
+ const GValue *value,
+ XfcePointersHelper *helper);
#ifdef HAS_DEVICE_HOTPLUGGING
-static GdkFilterReturn xfce_pointers_helper_event_filter (GdkXEvent *xevent,
- GdkEvent *gdk_event,
- gpointer user_data);
+static GdkFilterReturn xfce_pointers_helper_event_filter (GdkXEvent *xevent,
+ GdkEvent *gdk_event,
+ gpointer user_data);
#endif
@@ -88,6 +99,8 @@ struct _XfcePointersHelper
/* xfconf channel */
XfconfChannel *channel;
+ GPid syndaemon_pid;
+
#ifdef HAS_DEVICE_HOTPLUGGING
/* device presence event type */
gint device_presence_event_type;
@@ -112,7 +125,9 @@ G_DEFINE_TYPE (XfcePointersHelper, xfce_pointers_helper, G_TYPE_OBJECT);
static void
xfce_pointers_helper_class_init (XfcePointersHelperClass *klass)
{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = xfce_pointers_helper_finalize;
}
@@ -126,6 +141,8 @@ xfce_pointers_helper_init (XfcePointersHelper *helper)
XEventClass event_class;
#endif
+ helper->syndaemon_pid = 0;
+
/* get the default display */
xdisplay = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
@@ -158,7 +175,10 @@ xfce_pointers_helper_init (XfcePointersHelper *helper)
/* monitor the channel */
g_signal_connect (G_OBJECT (helper->channel), "property-changed",
- G_CALLBACK (xfce_pointers_helper_channel_property_changed), NULL);
+ G_CALLBACK (xfce_pointers_helper_channel_property_changed), helper);
+
+ /* launch syndaemon if required */
+ xfce_pointers_helper_syndaemon_check (helper);
#ifdef HAS_DEVICE_HOTPLUGGING
if (G_LIKELY (xdisplay != NULL))
@@ -180,6 +200,119 @@ xfce_pointers_helper_init (XfcePointersHelper *helper)
+static void
+xfce_pointers_helper_finalize (GObject *object)
+{
+ xfce_pointers_helper_syndaemon_stop (XFCE_POINTERS_HELPER (object));
+
+ (*G_OBJECT_CLASS (xfce_pointers_helper_parent_class)->finalize) (object);
+}
+
+
+
+static void
+xfce_pointers_helper_syndaemon_stop (XfcePointersHelper *helper)
+{
+ if (helper->syndaemon_pid != 0)
+ {
+ xfsettings_dbg (XFSD_DEBUG_POINTERS, "Killed syndaemon with pid %d",
+ helper->syndaemon_pid);
+
+ kill (helper->syndaemon_pid, SIGHUP);
+ g_spawn_close_pid (helper->syndaemon_pid);
+ helper->syndaemon_pid = 0;
+ }
+}
+
+
+
+static void
+xfce_pointers_helper_syndaemon_check (XfcePointersHelper *helper)
+{
+ Display *xdisplay = GDK_DISPLAY ();
+ XDeviceInfo *device_list;
+ XDevice *device;
+ gint n, ndevices;
+ Atom touchpad_type;
+ Atom touchpad_off_prop;
+ Atom *props;
+ gint i, nprops;
+ gboolean have_synaptics = FALSE;
+ gchar *args[] = { "syndaemon", "-i", "2.0", "-K", "-R", NULL };
+ GError *error = NULL;
+
+ /* only stop a running daemon */
+ if (!xfconf_channel_get_bool (helper->channel, "/DisableTouchpadWhileTyping", FALSE))
+ goto start_stop_daemon;
+
+ gdk_error_trap_push ();
+ device_list = XListInputDevices (xdisplay, &ndevices);
+ if (gdk_error_trap_pop () != 0 || device_list == NULL)
+ goto start_stop_daemon;
+
+ touchpad_type = XInternAtom (xdisplay, XI_TOUCHPAD, True);
+ touchpad_off_prop = XInternAtom (xdisplay, "Synaptics Off", True);
+
+ for (n = 0; n < ndevices; n++)
+ {
+ /* search for a touchpad */
+ if (device_list[n].type != touchpad_type)
+ continue;
+
+ gdk_error_trap_push ();
+ device = XOpenDevice (xdisplay, device_list[n].id);
+ if (gdk_error_trap_pop () != 0 || device == NULL)
+ {
+ g_critical ("Unable to open device %s", device_list[n].name);
+ break;
+ }
+
+ /* look for the Synaptics Off property */
+ gdk_error_trap_push ();
+ props = XListDeviceProperties (xdisplay, device, &nprops);
+ if (gdk_error_trap_pop () == 0
+ && props != NULL)
+ {
+ for (i = 0; !have_synaptics && i < nprops; i++)
+ have_synaptics = props[i] == touchpad_off_prop;
+
+ XFree (props);
+ }
+
+ XCloseDevice (xdisplay, device);
+
+ if (have_synaptics)
+ break;
+ }
+
+ XFreeDeviceList (device_list);
+
+ start_stop_daemon:
+
+ if (have_synaptics)
+ {
+ if (helper->syndaemon_pid == 0)
+ {
+ if (!g_spawn_async (NULL, args, NULL, G_SPAWN_SEARCH_PATH,
+ NULL, NULL, &helper->syndaemon_pid, &error))
+ {
+ g_critical ("Spawning syndaemon failed: %s", error->message);
+ g_error_free (error);
+ }
+
+ xfsettings_dbg (XFSD_DEBUG_POINTERS, "Started syndaemon with pid %d",
+ helper->syndaemon_pid);
+ }
+ }
+ else
+ {
+ /* stop the daemon */
+ xfce_pointers_helper_syndaemon_stop (helper);
+ }
+}
+
+
+
static gboolean
xfce_pointers_helper_change_button_mapping_swap (guchar *buttonmap,
gshort num_buttons,
@@ -778,9 +911,10 @@ xfce_pointers_helper_restore_devices (XfcePointersHelper *helper,
static void
-xfce_pointers_helper_channel_property_changed (XfconfChannel *channel,
- const gchar *property_name,
- const GValue *value)
+xfce_pointers_helper_channel_property_changed (XfconfChannel *channel,
+ const gchar *property_name,
+ const GValue *value,
+ XfcePointersHelper *helper)
{
Display *xdisplay = GDK_DISPLAY ();
XDeviceInfo *device_list, *device_info;
@@ -792,6 +926,13 @@ xfce_pointers_helper_channel_property_changed (XfconfChannel *channel,
if (G_UNLIKELY (property_name == NULL))
return;
+ /* check the daemon status */
+ if (strcmp (property_name, "/DisableTouchpadWhileTyping") == 0)
+ {
+ xfce_pointers_helper_syndaemon_check (helper);
+ return;
+ }
+
/* split the property name (+1 so skip the first slash in the name) */
names = g_strsplit (property_name + 1, "/", -1);
@@ -890,11 +1031,14 @@ xfce_pointers_helper_event_filter (GdkXEvent *xevent,
XDevicePresenceNotifyEvent *dpn_event = xevent;
XfcePointersHelper *helper = XFCE_POINTERS_HELPER (user_data);
- /* update on device changes */
- if (event->type == helper->device_presence_event_type
- && dpn_event->devchange == DeviceAdded)
+ if (event->type == helper->device_presence_event_type)
{
- xfce_pointers_helper_restore_devices (helper, &dpn_event->deviceid);
+ /* restore device settings */
+ if (dpn_event->devchange == DeviceAdded)
+ xfce_pointers_helper_restore_devices (helper, &dpn_event->deviceid);
+
+ /* check if we need to launch syndaemon */
+ xfce_pointers_helper_syndaemon_check (helper)
}
return GDK_FILTER_CONTINUE;
More information about the Xfce4-commits
mailing list