[gnome-control-center/gnome-3-6] wacom: Update from gnome-settings-daemon



commit 600ad0176bf4b20eaef8cbe78ecfee85c0ee0d19
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Fri Oct 19 15:41:43 2012 +0200

    wacom: Update from gnome-settings-daemon

 panels/wacom/gsd-wacom-device.c |   61 ++++++++++++++++++++++++++++++++-------
 panels/wacom/gsd-wacom-device.h |    2 +
 2 files changed, 52 insertions(+), 11 deletions(-)
---
diff --git a/panels/wacom/gsd-wacom-device.c b/panels/wacom/gsd-wacom-device.c
index c1de506..7b9a3e1 100644
--- a/panels/wacom/gsd-wacom-device.c
+++ b/panels/wacom/gsd-wacom-device.c
@@ -335,6 +335,8 @@ struct GsdWacomDevicePrivate
 	GList *styli;
 	GsdWacomStylus *last_stylus;
 	GList *buttons;
+	gint num_rings;
+	gint num_strips;
 	GHashTable *modes; /* key = int (group), value = int (index) */
 	GHashTable *num_modes; /* key = int (group), value = int (index) */
 	GSettings *wacom_settings;
@@ -1005,7 +1007,8 @@ gsd_wacom_device_add_ring_modes (WacomDevice      *wacom_device,
 	l = NULL;
 
 	if ((direction & WACOM_BUTTON_POSITION_LEFT) && libwacom_has_ring (wacom_device)) {
-		num_modes = libwacom_get_ring_num_modes (wacom_device);
+		/* There is a ring so there must be at least one mode */
+		num_modes = MAX (1, libwacom_get_ring_num_modes (wacom_device));
 		for (i = 1; i <= num_modes; i++) {
 			name = g_strdup_printf (_("Left Ring Mode #%d"), i);
 			id = g_strdup_printf ("left-ring-mode-%d", i);
@@ -1014,7 +1017,8 @@ gsd_wacom_device_add_ring_modes (WacomDevice      *wacom_device,
 			g_free (id);
 		}
 	} else if ((direction & WACOM_BUTTON_POSITION_RIGHT) && libwacom_has_ring2 (wacom_device)) {
-		num_modes = libwacom_get_ring2_num_modes (wacom_device);
+		/* There is a ring so there must be at least one mode */
+		num_modes = MAX (1, libwacom_get_ring2_num_modes (wacom_device));
 		for (i = 1; i <= num_modes; i++) {
 			name = g_strdup_printf (_("Right Ring Mode #%d"), i);
 			id = g_strdup_printf ("right-ring-mode-%d", i);
@@ -1044,7 +1048,8 @@ gsd_wacom_device_add_strip_modes (WacomDevice      *wacom_device,
 		g_warning ("Unhandled number of touchstrips: %d", num_strips);
 
 	if ((direction & WACOM_BUTTON_POSITION_LEFT) && num_strips >= 1) {
-		num_modes = libwacom_get_strips_num_modes (wacom_device);
+		/* There is a strip so there must be at least one mode */
+		num_modes = MAX (1, libwacom_get_strips_num_modes (wacom_device));
 		for (i = 1; i <= num_modes; i++) {
 			name = g_strdup_printf (_("Left Touchstrip Mode #%d"), i);
 			id = g_strdup_printf ("left-strip-mode-%d", i);
@@ -1053,7 +1058,8 @@ gsd_wacom_device_add_strip_modes (WacomDevice      *wacom_device,
 			g_free (id);
 		}
 	} else if ((direction & WACOM_BUTTON_POSITION_RIGHT) && num_strips >= 2) {
-		num_modes = libwacom_get_strips_num_modes (wacom_device);
+		/* There is a strip so there must be at least one mode */
+		num_modes = MAX (1, libwacom_get_strips_num_modes (wacom_device));
 		for (i = 1; i <= num_modes; i++) {
 			name = g_strdup_printf (_("Right Touchstrip Mode #%d"), i);
 			id = g_strdup_printf ("right-strip-mode-%d", i);
@@ -1135,15 +1141,14 @@ gsd_wacom_device_add_buttons_dir (WacomDevice      *wacom_device,
 		l = g_list_append (l, gsd_wacom_tablet_button_new (name, id, settings_path, WACOM_TABLET_BUTTON_TYPE_HARDCODED, flags_to_group (flags), -1));
 		g_free (name);
 		g_free (id);
-
-		if (flags & WACOM_BUTTON_RINGS_MODESWITCH)
-			l = g_list_concat (l, gsd_wacom_device_add_ring_modes (wacom_device, settings_path, direction));
-		else if (flags & WACOM_BUTTON_TOUCHSTRIPS_MODESWITCH)
-			l = g_list_concat (l, gsd_wacom_device_add_strip_modes (wacom_device, settings_path, direction));
-		else
-			g_warning ("Unhandled modeswitches");
 	}
 
+	/* Handle touch{strips,rings} */
+	if (libwacom_has_ring2 (wacom_device) || libwacom_has_ring (wacom_device))
+		l = g_list_concat (l, gsd_wacom_device_add_ring_modes (wacom_device, settings_path, direction));
+	if  (libwacom_get_num_strips (wacom_device) > 0)
+		l = g_list_concat (l, gsd_wacom_device_add_strip_modes (wacom_device, settings_path, direction));
+
 	return l;
 }
 
@@ -1173,6 +1178,21 @@ gsd_wacom_device_add_buttons (GsdWacomDevice *device,
 }
 
 static void
+gsd_wacom_device_get_modeswitches (WacomDevice      *wacom_device,
+				   gint             *num_rings,
+				   gint             *num_strips)
+{
+	*num_strips = libwacom_get_num_strips (wacom_device);
+
+	if (libwacom_has_ring2 (wacom_device))
+		*num_rings = 2;
+	else if  (libwacom_has_ring (wacom_device))
+		*num_rings = 1;
+	else
+		*num_rings = 0;
+}
+
+static void
 gsd_wacom_device_add_modes (GsdWacomDevice *device,
 			    WacomDevice    *wacom_device)
 {
@@ -1230,6 +1250,9 @@ gsd_wacom_device_update_from_db (GsdWacomDevice *device,
 	}
 
 	if (device->priv->type == WACOM_TYPE_PAD) {
+		gsd_wacom_device_get_modeswitches (wacom_device,
+						   &device->priv->num_rings,
+						   &device->priv->num_strips);
 		gsd_wacom_device_add_buttons (device, wacom_device, settings_path);
 		gsd_wacom_device_add_modes (device, wacom_device);
 	}
@@ -1558,6 +1581,22 @@ gsd_wacom_device_is_fallback (GsdWacomDevice *device)
 	return device->priv->is_fallback;
 }
 
+gint
+gsd_wacom_device_get_num_strips (GsdWacomDevice *device)
+{
+	g_return_val_if_fail (GSD_IS_WACOM_DEVICE (device), 0);
+
+	return device->priv->num_strips;
+}
+
+gint
+gsd_wacom_device_get_num_rings (GsdWacomDevice *device)
+{
+	g_return_val_if_fail (GSD_IS_WACOM_DEVICE (device), 0);
+
+	return device->priv->num_rings;
+}
+
 GSettings *
 gsd_wacom_device_get_settings (GsdWacomDevice *device)
 {
diff --git a/panels/wacom/gsd-wacom-device.h b/panels/wacom/gsd-wacom-device.h
index 8604ee4..24e6e06 100644
--- a/panels/wacom/gsd-wacom-device.h
+++ b/panels/wacom/gsd-wacom-device.h
@@ -143,6 +143,8 @@ const char     * gsd_wacom_device_get_tool_name    (GsdWacomDevice *device);
 gboolean         gsd_wacom_device_reversible       (GsdWacomDevice *device);
 gboolean         gsd_wacom_device_is_screen_tablet (GsdWacomDevice *device);
 gboolean         gsd_wacom_device_is_fallback      (GsdWacomDevice *device);
+gint             gsd_wacom_device_get_num_strips   (GsdWacomDevice *device);
+gint             gsd_wacom_device_get_num_rings    (GsdWacomDevice *device);
 GSettings      * gsd_wacom_device_get_settings     (GsdWacomDevice *device);
 void             gsd_wacom_device_set_current_stylus (GsdWacomDevice *device,
 						      int             stylus_id);



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