[gnome-settings-daemon] wacom: use libwacom status LED functions



commit b203b4dff5fa0e24753f7b8c9bba0bb821a4804e
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Mon Dec 3 17:31:53 2012 +0100

    wacom: use libwacom status LED functions
    
    Use the new API libwacom 0.7 provides to retrieve the
    status LED group from the modeswitch button.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676558

 plugins/wacom/gsd-wacom-device.c  |   34 +++++++++++-----
 plugins/wacom/gsd-wacom-device.h  |    3 +
 plugins/wacom/gsd-wacom-manager.c |   75 +++++++++----------------------------
 3 files changed, 44 insertions(+), 68 deletions(-)
---
diff --git a/plugins/wacom/gsd-wacom-device.c b/plugins/wacom/gsd-wacom-device.c
index c92f153..ba1f83e 100644
--- a/plugins/wacom/gsd-wacom-device.c
+++ b/plugins/wacom/gsd-wacom-device.c
@@ -256,7 +256,8 @@ gsd_wacom_tablet_button_new (const char               *name,
 			     const char               *settings_path,
 			     GsdWacomTabletButtonType  type,
 			     int                       group_id,
-			     int                       idx)
+			     int                       idx,
+			     int                       status_led)
 {
 	GsdWacomTabletButton *ret;
 
@@ -273,6 +274,7 @@ gsd_wacom_tablet_button_new (const char               *name,
 	ret->group_id = group_id;
 	ret->idx = idx;
 	ret->type = type;
+	ret->status_led = status_led;
 
 	return ret;
 }
@@ -1047,7 +1049,8 @@ gsd_wacom_device_add_ring_modes (WacomDevice      *wacom_device,
 									   settings_path,
 									   WACOM_TABLET_BUTTON_TYPE_RING,
 									   group,
-									   0));
+									   0,
+									   GSD_WACOM_NO_LED));
 		} else {
 			for (i = 1; i <= num_modes; i++) {
 				name = g_strdup_printf (_("Left Ring Mode #%d"), i);
@@ -1057,7 +1060,8 @@ gsd_wacom_device_add_ring_modes (WacomDevice      *wacom_device,
 				                                                   settings_path,
 				                                                   WACOM_TABLET_BUTTON_TYPE_RING,
 				                                                   group,
-				                                                   i - 1));
+				                                                   i - 1,
+										   GSD_WACOM_NO_LED));
 				g_free (name);
 				g_free (id);
 			}
@@ -1072,7 +1076,8 @@ gsd_wacom_device_add_ring_modes (WacomDevice      *wacom_device,
 									   settings_path,
 									   WACOM_TABLET_BUTTON_TYPE_RING,
 									   group,
-									   0));
+									   0,
+									   GSD_WACOM_NO_LED));
 		} else {
 			for (i = 1; i <= num_modes; i++) {
 				name = g_strdup_printf (_("Right Ring Mode #%d"), i);
@@ -1082,7 +1087,8 @@ gsd_wacom_device_add_ring_modes (WacomDevice      *wacom_device,
 				                                                   settings_path,
 				                                                   WACOM_TABLET_BUTTON_TYPE_RING,
 				                                                   group,
-				                                                   i - 1));
+				                                                   i - 1,
+										   GSD_WACOM_NO_LED));
 				g_free (name);
 				g_free (id);
 			}
@@ -1119,7 +1125,8 @@ gsd_wacom_device_add_strip_modes (WacomDevice      *wacom_device,
 									   settings_path,
 									   WACOM_TABLET_BUTTON_TYPE_STRIP,
 									   group,
-									   0));
+									   0,
+									   GSD_WACOM_NO_LED));
 		} else {
 			for (i = 1; i <= num_modes; i++) {
 				name = g_strdup_printf (_("Left Touchstrip Mode #%d"), i);
@@ -1129,7 +1136,8 @@ gsd_wacom_device_add_strip_modes (WacomDevice      *wacom_device,
 				                                                   settings_path,
 				                                                   WACOM_TABLET_BUTTON_TYPE_STRIP,
 				                                                   group,
-				                                                   i - 1));
+				                                                   i - 1,
+										   GSD_WACOM_NO_LED));
 				g_free (name);
 				g_free (id);
 			}
@@ -1144,7 +1152,8 @@ gsd_wacom_device_add_strip_modes (WacomDevice      *wacom_device,
 									   settings_path,
 									   WACOM_TABLET_BUTTON_TYPE_STRIP,
 									   group,
-									   0));
+									   0,
+									   GSD_WACOM_NO_LED));
 		} else {
 			for (i = 1; i <= num_modes; i++) {
 				name = g_strdup_printf (_("Right Touchstrip Mode #%d"), i);
@@ -1154,7 +1163,8 @@ gsd_wacom_device_add_strip_modes (WacomDevice      *wacom_device,
 				                                                   settings_path,
 				                                                   WACOM_TABLET_BUTTON_TYPE_STRIP,
 				                                                   group,
-				                                                   i - 1));
+				                                                   i - 1,
+										   GSD_WACOM_NO_LED));
 				g_free (name);
 				g_free (id);
 			}
@@ -1211,7 +1221,7 @@ gsd_wacom_device_add_buttons_dir (WacomDevice      *wacom_device,
 
 		name = g_strdup_printf (button_str, button_num++);
 		id = g_strdup_printf ("%s%c", button_str_id, i);
-		l = g_list_append (l, gsd_wacom_tablet_button_new (name, id, settings_path, WACOM_TABLET_BUTTON_TYPE_NORMAL, flags_to_group (flags), -1));
+		l = g_list_append (l, gsd_wacom_tablet_button_new (name, id, settings_path, WACOM_TABLET_BUTTON_TYPE_NORMAL, flags_to_group (flags), -1, GSD_WACOM_NO_LED));
 		g_free (name);
 		g_free (id);
 	}
@@ -1220,6 +1230,7 @@ gsd_wacom_device_add_buttons_dir (WacomDevice      *wacom_device,
 	for (i = 'A'; i < 'A' + num_buttons; i++) {
 		WacomButtonFlags flags;
 		char *name, *id;
+		int status_led;
 
 		flags = libwacom_get_button_flag (wacom_device, i);
 		if (!(flags & direction))
@@ -1230,7 +1241,8 @@ gsd_wacom_device_add_buttons_dir (WacomDevice      *wacom_device,
 
 		name = gsd_wacom_device_modeswitch_name (flags, button_num++);
 		id = g_strdup_printf ("%s%c", button_str_id, i);
-		l = g_list_append (l, gsd_wacom_tablet_button_new (name, id, settings_path, WACOM_TABLET_BUTTON_TYPE_HARDCODED, flags_to_group (flags), -1));
+		status_led = libwacom_get_button_led_group (wacom_device, i);
+		l = g_list_append (l, gsd_wacom_tablet_button_new (name, id, settings_path, WACOM_TABLET_BUTTON_TYPE_HARDCODED, flags_to_group (flags), -1, status_led));
 		g_free (name);
 		g_free (id);
 	}
diff --git a/plugins/wacom/gsd-wacom-device.h b/plugins/wacom/gsd-wacom-device.h
index 1c20c6c..c593e66 100644
--- a/plugins/wacom/gsd-wacom-device.h
+++ b/plugins/wacom/gsd-wacom-device.h
@@ -100,6 +100,8 @@ typedef enum {
 
 #define MAX_GROUP_ID 4
 
+#define GSD_WACOM_NO_LED -1
+
 typedef struct
 {
 	char                     *name;
@@ -107,6 +109,7 @@ typedef struct
 	GSettings                *settings;
 	GsdWacomTabletButtonType  type;
 	int                       group_id, idx;
+	int                       status_led;
 } GsdWacomTabletButton;
 
 void                  gsd_wacom_tablet_button_free (GsdWacomTabletButton *button);
diff --git a/plugins/wacom/gsd-wacom-manager.c b/plugins/wacom/gsd-wacom-manager.c
index 2497a9f..3da39ea 100644
--- a/plugins/wacom/gsd-wacom-manager.c
+++ b/plugins/wacom/gsd-wacom-manager.c
@@ -540,56 +540,10 @@ apply_stylus_settings (GsdWacomDevice *device)
 	set_pressurethreshold (device, threshold);
 }
 
-/*
- * The rule to determine the status LED to use is as follow:
- *
- * "[...] if a device has only one ring/strip, use status_led0_select;
- *  otherwise the left ring/strip is controlled by status_led1_select and
- *  the right ring/strip by status_led0_select."
- *
- * http://sourceforge.net/mailarchive/message.php?msg_id=29898591
- */
-static int
-get_led_group_id(GsdWacomDevice *device,
-		 int             group_id)
-{
-	gint num_rings;
-	gint num_strips;
-
-	num_rings = gsd_wacom_device_get_num_rings (device);
-	num_strips = gsd_wacom_device_get_num_strips (device);
-
-	/* Given group_id is in {1..4} as follow
-	 * WACOM_BUTTON_RING_MODESWITCH        => group_id == 1
-	 * WACOM_BUTTON_RING2_MODESWITCH       => group_id == 2
-	 * WACOM_BUTTON_TOUCHSTRIP_MODESWITCH  => group_id == 3
-	 * WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH => group_id == 4
-	 *
-	 * see function flags_to_group() in gsd-wacom-device.c
-	 */
-
-	if ((num_rings == 1) && (group_id == 1))
-		return 0;
-
-	if ((num_strips == 1) && (group_id == 3))
-		return 0;
-
-	if ((num_rings == 2) && (group_id == 1 ||  group_id == 2))
-		return (group_id & 1);
-
-	if ((num_strips == 2) && (group_id == 3 ||  group_id == 4))
-		return (group_id & 1);
-
-	g_debug ("Unhandled number of rings/strips setup (%d ring(s), %d strip(s), mode=%d",
-		 num_rings, num_strips, group_id);
-
-	return -1;
-}
-
 static void
-set_led (GsdWacomDevice *device,
-	 int             group_id,
-	 int             index)
+set_led (GsdWacomDevice       *device,
+	 GsdWacomTabletButton *button,
+	 int                   index)
 {
 	GError *error = NULL;
 	const char *path;
@@ -604,14 +558,14 @@ set_led (GsdWacomDevice *device,
 	g_return_if_fail (index >= 1);
 
 	path = gsd_wacom_device_get_path (device);
-	status_led = get_led_group_id (device, group_id);
+	status_led = button->status_led;
 
-	if (status_led < 0) {
+	if (status_led == GSD_WACOM_NO_LED) {
 		g_debug ("Ignoring unhandled group ID %d for device %s",
-		         group_id, gsd_wacom_device_get_name (device));
+		         button->group_id, gsd_wacom_device_get_name (device));
 		return;
 	}
-	g_debug ("Switching group ID %d to index %d for device %s", group_id, index, path);
+	g_debug ("Switching group ID %d to index %d for device %s", button->group_id, index, path);
 
 	command = g_strdup_printf ("pkexec " LIBEXECDIR "/gsd-wacom-led-helper --path %s --group %d --led %d",
 				   path, status_led, index - 1);
@@ -700,6 +654,7 @@ reset_pad_buttons (GsdWacomDevice *device)
 	int nmap;
 	unsigned char *map;
 	int i, j, rc;
+	GList *buttons, *l;
 
 	/* Normal buttons */
 	xdev = open_device (device);
@@ -733,9 +688,15 @@ reset_pad_buttons (GsdWacomDevice *device)
 	XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdev);
 
 	/* Reset all the LEDs */
-	/* FIXME, get the number of modes somewhere else */
-	for (i = 1; i <= 4; i++)
-		set_led (device, i, 1);
+	buttons = gsd_wacom_device_get_buttons (device);
+	for (l = buttons; l != NULL; l = l->next) {
+		GsdWacomTabletButton *button = l->data;
+                if (button->type == WACOM_TABLET_BUTTON_TYPE_HARDCODED &&
+                    button->status_led != GSD_WACOM_NO_LED) {
+                        set_led (device, button, 1);
+                }
+        }
+        g_list_free (buttons);
 }
 
 static void
@@ -1206,7 +1167,7 @@ filter_button_events (XEvent          *xevent,
 			return GDK_FILTER_REMOVE;
 
 		new_mode = gsd_wacom_device_set_next_mode (device, wbutton);
-		set_led (device, wbutton->group_id, new_mode);
+		set_led (device, wbutton, new_mode);
 		return GDK_FILTER_REMOVE;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]