Blob Blame History Raw
From 9257ef03d3ae0be9a588016121ee8adc5e9a85b7 Mon Sep 17 00:00:00 2001
From: Aaron Skomra <skomra@gmail.com>
Date: Tue, 10 Nov 2015 11:31:53 -0800
Subject: [PATCH] add Wacom panel support for the ExpressKey Remote

---
 configure.ac                     |  2 +-
 panels/wacom/cc-wacom-page.c     | 60 ++++++++++++++++++++-------
 panels/wacom/cc-wacom-panel.c    |  9 ++++-
 panels/wacom/gsd-wacom-device.c  | 22 ++++++++++
 panels/wacom/gsd-wacom-device.h  |  2 +
 panels/wacom/wacom-remote.svg    | 87 ++++++++++++++++++++++++++++++++++++++++
 panels/wacom/wacom.gresource.xml |  1 +
 7 files changed, 167 insertions(+), 16 deletions(-)
 create mode 100644 panels/wacom/wacom-remote.svg

diff --git a/configure.ac b/configure.ac
index 4f6c59e..2dffcac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,7 +98,7 @@ MODEM_MANAGER_REQUIRED_VERSION=0.7
 LIBNOTIFY_REQUIRED_VERSION=0.7.3
 GNOME_DESKTOP_REQUIRED_VERSION=3.21.2
 SCHEMAS_REQUIRED_VERSION=3.21.4
-LIBWACOM_REQUIRED_VERSION=0.7
+LIBWACOM_REQUIRED_VERSION=0.17
 CLUTTER_REQUIRED_VERSION=1.11.3
 GOA_REQUIRED_VERSION=3.21.5
 ACCOUNTSSERVICE_REQUIRED_VERSION=0.6.39
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c
index fc31328..b8644e2 100644
--- a/panels/wacom/cc-wacom-page.c
+++ b/panels/wacom/cc-wacom-page.c
@@ -104,7 +104,8 @@ enum {
 enum {
 	LAYOUT_NORMAL,        /* tracking mode, button mapping */
 	LAYOUT_REVERSIBLE,    /* tracking mode, button mapping, left-hand orientation */
-	LAYOUT_SCREEN        /* button mapping, calibration, display resolution */
+	LAYOUT_SCREEN,        /* button mapping, calibration, display resolution */
+	LAYOUT_REMOTE,        /* button mapping */
 };
 
 static void
@@ -120,6 +121,8 @@ get_layout_type (GsdWacomDevice *device)
 		layout = LAYOUT_SCREEN;
 	else if (gsd_wacom_device_reversible (device))
 		layout = LAYOUT_REVERSIBLE;
+	else if (gsd_wacom_device_is_remote (device))
+		layout = LAYOUT_REMOTE;
 	else
 		layout = LAYOUT_NORMAL;
 
@@ -893,6 +896,14 @@ remove_mouse_link (CcWacomPagePrivate *priv)
                                  "top_attach", 2, NULL);
 }
 
+static void
+remove_for_remote (CcWacomPagePrivate *priv)
+{
+	gtk_widget_destroy (WID ("label-trackingmode"));
+	gtk_widget_destroy (WID ("combo-tabletmode"));
+	gtk_widget_destroy (WID ("display-mapping-button"));
+}
+
 static gboolean
 has_monitor (CcWacomPage *page)
 {
@@ -907,7 +918,8 @@ update_tablet_ui (CcWacomPage *page,
 	GsdWacomStylus *puck;
 
 	priv = page->priv;
-	puck = gsd_wacom_device_get_stylus_for_type (priv->stylus, WACOM_STYLUS_TYPE_PUCK);
+	if (priv->stylus != NULL)
+		puck = gsd_wacom_device_get_stylus_for_type (priv->stylus, WACOM_STYLUS_TYPE_PUCK);
 	if (puck == NULL)
 		remove_mouse_link (priv);
 
@@ -940,6 +952,11 @@ update_tablet_ui (CcWacomPage *page,
 					 WID ("display-link"),
 					 "top_attach", 2, NULL);
 		break;
+	case LAYOUT_REMOTE:
+		remove_for_remote (priv);
+		remove_left_handed (priv);
+		remove_display_link (priv);
+		break;
 	default:
 		g_assert_not_reached ();
 	}
@@ -955,7 +972,10 @@ cc_wacom_page_update_tools (CcWacomPage    *page,
 	gboolean changed;
 
 	/* Type of layout */
-	layout = get_layout_type (stylus);
+	if (pad != NULL && stylus == NULL)
+		layout = get_layout_type (pad);
+	else
+		layout = get_layout_type (stylus);
 
 	priv = page->priv;
 	changed = (priv->stylus != stylus || priv->pad != pad);
@@ -978,8 +998,10 @@ cc_wacom_page_new (CcWacomPanel   *panel,
 	CcWacomPage *page;
 	CcWacomPagePrivate *priv;
 
-	g_return_val_if_fail (GSD_IS_WACOM_DEVICE (stylus), NULL);
-	g_return_val_if_fail (gsd_wacom_device_get_device_type (stylus) == WACOM_TYPE_STYLUS, NULL);
+	if (stylus != NULL) {
+		g_return_val_if_fail (GSD_IS_WACOM_DEVICE (stylus), NULL);
+		g_return_val_if_fail (gsd_wacom_device_get_device_type (stylus) == WACOM_TYPE_STYLUS, NULL);
+	}
 
 	if (pad != NULL)
 		g_return_val_if_fail (gsd_wacom_device_get_device_type (pad) == WACOM_TYPE_PAD, NULL);
@@ -992,26 +1014,36 @@ cc_wacom_page_new (CcWacomPanel   *panel,
 	cc_wacom_page_update_tools (page, stylus, pad);
 
 	/* FIXME move this to construct */
-	priv->wacom_settings  = gsd_wacom_device_get_settings (stylus);
-	set_mode_from_gsettings (GTK_COMBO_BOX (WID ("combo-tabletmode")), page);
+	if (stylus != NULL) {
+		priv->wacom_settings = gsd_wacom_device_get_settings (stylus);
+		set_mode_from_gsettings (GTK_COMBO_BOX (WID ("combo-tabletmode")), page);
+	}
 
 	/* Tablet name */
-	gtk_label_set_text (GTK_LABEL (WID ("label-tabletmodel")), gsd_wacom_device_get_name (stylus));
+	if (stylus != NULL)
+		gtk_label_set_text (GTK_LABEL (WID ("label-tabletmodel")), gsd_wacom_device_get_name (stylus));
+	else if (pad != NULL)
+		gtk_label_set_text (GTK_LABEL (WID ("label-tabletmodel")), gsd_wacom_device_get_name (pad));
 
 	/* Left-handedness */
-	if (gsd_wacom_device_reversible (stylus))
+	if (stylus != NULL && gsd_wacom_device_reversible (stylus))
 		set_left_handed_from_gsettings (page);
 
 	/* Tablet icon */
-	set_icon_name (page, "image-tablet", gsd_wacom_device_get_icon_name (stylus));
+	if (pad != NULL && gsd_wacom_device_is_remote (pad))
+		set_icon_name (page, "image-tablet", gsd_wacom_device_get_icon_name (pad));
+	else
+		set_icon_name (page, "image-tablet", gsd_wacom_device_get_icon_name (stylus));
 
 	/* Add styli */
-	add_styli (page);
+	if (stylus != NULL) {
+		add_styli (page);
 
 	/* Get the current stylus and switch to its page */
-	stylus_changed (priv->stylus, NULL, page);
-	g_signal_connect (G_OBJECT (priv->stylus), "notify::last-stylus",
-			  G_CALLBACK (stylus_changed), page);
+		stylus_changed (priv->stylus, NULL, page);
+		g_signal_connect (G_OBJECT (priv->stylus), "notify::last-stylus",
+				  G_CALLBACK (stylus_changed), page);
+	}
 
 	return GTK_WIDGET (page);
 }
diff --git a/panels/wacom/cc-wacom-panel.c b/panels/wacom/cc-wacom-panel.c
index aedd5ed..91a245e 100644
--- a/panels/wacom/cc-wacom-panel.c
+++ b/panels/wacom/cc-wacom-panel.c
@@ -316,7 +316,14 @@ update_current_page (CcWacomPanel *self)
 		GtkWidget *page;
 
 		tablet = l->data;
-		if (tablet->stylus == NULL) {
+		/* For most "Tablets" a NULL tablet->stylus will trigger a cleanup. However, if the device
+		 * has no stylus (e.g. ExpressKey Remote), we skip the the cleanup and proceed to page
+		 * creation. Since both GsdWacomDevice members (tablet/pad) of a Tablet know if their
+		 * physical device has a stylus, we can find out from the solo pad device if the hardware
+		 * supports a stylus. */
+		if (tablet->pad != NULL && !gsd_wacom_device_get_has_stylus (tablet->pad)){
+			/* This is a full device but it doesn't have a stylus - skip the cleanup */
+		} else if (tablet->stylus == NULL) {
 			page = g_hash_table_lookup (priv->pages, tablet->name);
 			if (page != NULL) {
 				remove_page (GTK_NOTEBOOK (priv->notebook), page);
diff --git a/panels/wacom/gsd-wacom-device.c b/panels/wacom/gsd-wacom-device.c
index 0cf725b..ed8d852 100644
--- a/panels/wacom/gsd-wacom-device.c
+++ b/panels/wacom/gsd-wacom-device.c
@@ -353,6 +353,8 @@ struct GsdWacomDevicePrivate
 	GHashTable *modes; /* key = int (group), value = int (index) */
 	GHashTable *num_modes; /* key = int (group), value = int (index) */
 	GSettings *wacom_settings;
+	gboolean has_stylus;
+	WacomClass class;
 };
 
 enum {
@@ -1389,6 +1391,8 @@ gsd_wacom_device_update_from_db (GsdWacomDevice *device,
 	device->priv->wacom_settings = g_settings_new_with_path (WACOM_TABLET_SCHEMA,
 								 settings_path);
 
+	device->priv->class = libwacom_get_class (wacom_device);
+	device->priv->has_stylus = libwacom_has_stylus (wacom_device);
 	device->priv->name = g_strdup (libwacom_get_name (wacom_device));
 	device->priv->layout_path = g_strdup (libwacom_get_layout_filename (wacom_device));
 	device->priv->reversible = libwacom_is_reversible (wacom_device);
@@ -1400,6 +1404,8 @@ gsd_wacom_device_update_from_db (GsdWacomDevice *device,
 			device->priv->icon_name = "wacom-tablet-cintiq";
 		else
 			device->priv->icon_name = "wacom-tablet-pc";
+	} else if (gsd_wacom_device_is_remote (device)) {
+		device->priv->icon_name = "wacom-remote";
 	} else {
 		device->priv->icon_name = "wacom-tablet";
 	}
@@ -1784,6 +1790,22 @@ gsd_wacom_device_get_num_rings (GsdWacomDevice *device)
 	return device->priv->num_rings;
 }
 
+gboolean
+gsd_wacom_device_get_has_stylus (GsdWacomDevice *device)
+{
+	g_return_val_if_fail (GSD_IS_WACOM_DEVICE (device), FALSE);
+
+	return device->priv->has_stylus;
+}
+
+gboolean
+gsd_wacom_device_is_remote (GsdWacomDevice *device)
+{
+	g_return_val_if_fail (GSD_IS_WACOM_DEVICE (device), FALSE);
+
+	return device->priv->class == WCLASS_REMOTE;
+}
+
 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 374eca9..04d893b 100644
--- a/panels/wacom/gsd-wacom-device.h
+++ b/panels/wacom/gsd-wacom-device.h
@@ -158,6 +158,8 @@ gboolean         gsd_wacom_device_reversible       (GsdWacomDevice *device);
 gboolean         gsd_wacom_device_is_screen_tablet (GsdWacomDevice *device);
 gboolean         gsd_wacom_device_is_isd           (GsdWacomDevice *device);
 gboolean         gsd_wacom_device_is_fallback      (GsdWacomDevice *device);
+gboolean         gsd_wacom_device_is_remote        (GsdWacomDevice *device);
+gboolean         gsd_wacom_device_get_has_stylus   (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);
diff --git a/panels/wacom/wacom-remote.svg b/panels/wacom/wacom-remote.svg
new file mode 100644
index 0000000..fedc369
--- /dev/null
+++ b/panels/wacom/wacom-remote.svg
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   id="svg86858"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   width="148"
+   height="95"
+   sodipodi:docname="wacom-remote.svg">
+  <metadata
+     id="metadata86864">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs86862" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1920"
+     inkscape:window-height="1043"
+     id="namedview86860"
+     showgrid="false"
+     borderlayer="true"
+     inkscape:showpageshadow="false"
+     inkscape:zoom="1.4142136"
+     inkscape:cx="42.197473"
+     inkscape:cy="89.570991"
+     inkscape:window-x="1600"
+     inkscape:window-y="0"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g4353-0">
+    <inkscape:grid
+       type="xygrid"
+       id="grid86892"
+       empspacing="5"
+       visible="true"
+       enabled="true"
+       snapvisiblegridlinesonly="true" />
+  </sodipodi:namedview>
+  <g
+     style="display:inline"
+     transform="matrix(0.59415025,0,0,0.67531282,405.44733,-74.059104)"
+     id="g4353-0">
+    <path
+       style="fill:#d3d7cf;fill-opacity:1;stroke:#babdb6;stroke-width:0.9364267px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m -595.42042,115.40742 -0.44204,122.18594 c 16.23481,7.79709 47.17933,10.08912 65.6984,0 l -0.44204,-122.18594 z"
+       id="path3568-6"
+       inkscape:connector-curvature="0"
+       sodipodi:nodetypes="ccccc" />
+    <rect
+       style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:#babdb6;fill-opacity:1;fill-rule:nonzero;stroke:#babdb6;stroke-width:0.81427532;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate"
+       id="rect10889"
+       width="43.043358"
+       height="71.11171"
+       x="-584.53485"
+       y="163.02573" />
+    <ellipse
+       style="fill:#babdb6;fill-opacity:1"
+       id="path3392"
+       cx="-563.9823"
+       cy="139.35141"
+       rx="22.017115"
+       ry="19.894526" />
+  </g>
+</svg>
diff --git a/panels/wacom/wacom.gresource.xml b/panels/wacom/wacom.gresource.xml
index 7683b4d..14d41c1 100644
--- a/panels/wacom/wacom.gresource.xml
+++ b/panels/wacom/wacom.gresource.xml
@@ -5,6 +5,7 @@
     <file preprocess="xml-stripblanks">wacom-stylus-page.ui</file>
     <file preprocess="xml-stripblanks">button-mapping.ui</file>
     <file>wacom-tablet.svg</file>
+    <file>wacom-remote.svg</file>
     <file>wacom-stylus.svg</file>
     <file>wacom-stylus-no-eraser.svg</file>
     <file>wacom-stylus-airbrush.svg</file>
-- 
2.9.3