[gnome-settings-daemon] wacom: Add helper to set LEDs for mode switching
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] wacom: Add helper to set LEDs for mode switching
- Date: Sun, 4 Mar 2012 14:46:23 +0000 (UTC)
commit 36d25ad690fd23439274e1199798d6b1f94102b9
Author: Bastien Nocera <hadess hadess net>
Date: Sun Mar 4 14:17:17 2012 +0000
wacom: Add helper to set LEDs for mode switching
Based upon the power plugin's backlight helper.
configure.ac | 2 +-
plugins/wacom/Makefile.am | 28 +++-
plugins/wacom/gsd-wacom-led-helper.c | 174 ++++++++++++++++++++
...nome.settings-daemon.plugins.wacom.policy.in.in | 31 ++++
4 files changed, 233 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ebf37fd..b0ed0da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -199,7 +199,7 @@ dnl ---------------------------------------------------------------------------
dnl - wacom
dnl ---------------------------------------------------------------------------
-PKG_CHECK_MODULES(WACOM, [libwacom >= $LIBWACOM_REQUIRED_VERSION x11 xi xtst gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION xorg-wacom])
+PKG_CHECK_MODULES(WACOM, [libwacom >= $LIBWACOM_REQUIRED_VERSION x11 xi xtst $GUDEV_PKG gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION xorg-wacom])
dnl ==============================================
dnl PackageKit section
diff --git a/plugins/wacom/Makefile.am b/plugins/wacom/Makefile.am
index 375f107..a3086c3 100644
--- a/plugins/wacom/Makefile.am
+++ b/plugins/wacom/Makefile.am
@@ -32,6 +32,32 @@ libgsdwacom_la_LIBADD = \
$(SETTINGS_PLUGIN_LIBS) \
$(WACOM_LIBS)
+org.gnome.settings-daemon.plugins.wacom.policy.in: org.gnome.settings-daemon.plugins.wacom.policy.in.in Makefile
+ $(AM_V_GEN) sed -e "s|\ libexecdir\@|$(libexecdir)|" $< > $@
+
+ INTLTOOL_POLICY_RULE@
+polkit_policydir = $(datadir)/polkit-1/actions
+polkit_policy_in_files = org.gnome.settings-daemon.plugins.wacom.policy.in
+polkit_policy_DATA = $(polkit_policy_in_files:.policy.in=.policy)
+
+# so it always gets included in the tarball
+gsd_wacom_led_helper_SOURCES = gsd-wacom-led-helper.c
+
+EXTRA_DIST = $(gsd_wacom_led_helper_SOURCES)
+
+if HAVE_GUDEV
+libexec_PROGRAMS = gsd-wacom-led-helper
+
+gsd_wacom_led_helper_LDFLAGS = \
+ $(BACKLIGHT_HELPER_LIBS) \
+ -lm
+
+gsd_wacom_led_helper_CFLAGS = \
+ $(BACKLIGHT_HELPER_CFLAGS)
+endif
+
+EXTRA_DIST += org.gnome.settings-daemon.plugins.wacom.policy.in.in
+
noinst_PROGRAMS = test-wacom list-wacom
test_wacom_SOURCES = \
@@ -96,7 +122,7 @@ plugin_in_files = wacom.gnome-settings-plugin.in
plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin)
-EXTRA_DIST = $(plugin_in_files)
+EXTRA_DIST += $(plugin_in_files)
CLEANFILES = $(plugin_DATA)
DISTCLEANFILES = $(plugin_DATA)
diff --git a/plugins/wacom/gsd-wacom-led-helper.c b/plugins/wacom/gsd-wacom-led-helper.c
new file mode 100644
index 0000000..32b68ca
--- /dev/null
+++ b/plugins/wacom/gsd-wacom-led-helper.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2010-2011 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2012 Bastien Nocera <hadess hadess net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <locale.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <gudev/gudev.h>
+
+static gboolean
+gsd_wacom_led_helper_write (const gchar *filename, gint value, GError **error)
+{
+ gchar *text = NULL;
+ gint retval;
+ gint length;
+ gint fd = -1;
+ gboolean ret = TRUE;
+
+ fd = open (filename, O_WRONLY);
+ if (fd < 0) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "failed to open filename: %s", filename);
+ goto out;
+ }
+
+ /* convert to text */
+ text = g_strdup_printf ("%i", value);
+ length = strlen (text);
+
+ /* write to device file */
+ retval = write (fd, text, length);
+ if (retval != length) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "writing '%s' to %s failed", text, filename);
+ goto out;
+ }
+out:
+ if (fd >= 0)
+ close (fd);
+ g_free (text);
+ return ret;
+}
+
+static char *
+get_led_sysfs_path (GUdevDevice *device,
+ int group_num)
+{
+ char *status;
+ char *filename;
+
+ status = g_strdup_printf ("status_led%d_select", group_num);
+ filename = g_build_filename (g_udev_device_get_sysfs_path (device), "wacom_led", status, NULL);
+ g_free (status);
+
+ return filename;
+}
+
+static char *path = NULL;
+static int group_num = -1;
+static int led_num = -1;
+
+const GOptionEntry options[] = {
+ { "path", '\0', 0, G_OPTION_ARG_FILENAME, &path, "Device path for the Wacom device", NULL },
+ { "group", '\0', 0, G_OPTION_ARG_INT, &group_num, "Which LED group to set", NULL },
+ { "led", '\0', 0, G_OPTION_ARG_INT, &led_num, "Which LED to set", NULL },
+ { NULL}
+};
+
+
+int main (int argc, char **argv)
+{
+ GOptionContext *context;
+ GUdevClient *client;
+ GUdevDevice *device, *parent;
+ char *filename;
+ GError *error = NULL;
+ const char * const subsystems[] = { "input", NULL };
+
+ g_type_init ();
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "GNOME Settings Daemon Wacom LED Helper");
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+
+ if (path == NULL ||
+ group_num < 0 ||
+ led_num < 0) {
+ char *txt;
+
+ txt = g_option_context_get_help (context, FALSE, NULL);
+ g_print ("%s", txt);
+ g_free (txt);
+
+ g_option_context_free (context);
+
+ return 1;
+ }
+ g_option_context_free (context);
+
+ client = g_udev_client_new (subsystems);
+ device = g_udev_client_query_by_device_file (client, path);
+ if (device == NULL) {
+ g_debug ("Could not find device '%s' in udev database", path);
+ goto bail;
+ }
+
+ if (g_udev_device_get_property_as_boolean (device, "ID_INPUT_TABLET") == FALSE &&
+ g_udev_device_get_property_as_boolean (device, "ID_INPUT_TOUCHPAD") == FALSE) {
+ g_debug ("Device '%s' is not a Wacom tablet", path);
+ goto bail;
+ }
+
+ if (g_strcmp0 (g_udev_device_get_property (device, "ID_BUS"), "usb") != 0) {
+ /* FIXME handle Bluetooth LEDs too */
+ g_debug ("Non-USB LEDs setting is not supported");
+ goto bail;
+ }
+
+ parent = g_udev_device_get_parent_with_subsystem (device, "usb", "usb_interface");
+ if (parent == NULL) {
+ g_debug ("Could not find parent USB device for '%s'", path);
+ goto bail;
+ }
+ g_object_unref (device);
+ device = parent;
+
+ filename = get_led_sysfs_path (device, group_num);
+ if (gsd_wacom_led_helper_write (filename, led_num, &error) == FALSE) {
+ g_debug ("Could not set LED status for '%s': %s", path, error->message);
+ g_error_free (error);
+ g_free (filename);
+ goto bail;
+ }
+ g_free (filename);
+
+ g_debug ("Successfully set LED status for '%s', group %d to %d",
+ path, group_num, led_num);
+
+ g_object_unref (device);
+ g_object_unref (client);
+
+ return 0;
+
+bail:
+ if (device != NULL)
+ g_object_unref (device);
+ if (client != NULL)
+ g_object_unref (client);
+ return 1;
+}
diff --git a/plugins/wacom/org.gnome.settings-daemon.plugins.wacom.policy.in.in b/plugins/wacom/org.gnome.settings-daemon.plugins.wacom.policy.in.in
new file mode 100644
index 0000000..9821827
--- /dev/null
+++ b/plugins/wacom/org.gnome.settings-daemon.plugins.wacom.policy.in.in
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+<policyconfig>
+
+ <!--
+ Policy definitions for gnome-settings-daemon system-wide actions.
+ -->
+
+ <vendor>GNOME Settings Daemon</vendor>
+ <vendor_url>http://git.gnome.org/browse/gnome-settings-daemon</vendor_url>
+ <icon_name>input-tablet</icon_name>
+
+ <action id="org.gnome.settings-daemon.plugins.wacom.wacom-led-helper">
+ <!-- SECURITY:
+ - A normal active user on the local machine does not need permission
+ to change the LED setting for a Wacom tablet
+ -->
+ <_description>Modify the lit LED for a Wacom tablet</_description>
+ <_message>Authentication is required to modify the lit LED for a Wacom tablet</_message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ <annotate key="org.freedesktop.policykit.exec.path">@libexecdir@/gsd-wacom-led-helper</annotate>
+ </action>
+
+</policyconfig>
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]