2
* Copyright (C) 2010-2011 Richard Hughes <richard@hughsie.com>
3
* Copyright (C) 2012 Bastien Nocera <hadess@hadess.net>
5
* Licensed under the GNU General Public License Version 2
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27
#include <sys/types.h>
31
#include <gudev/gudev.h>
33
#define LED_BRIGHTNESS 127 /* maximum brightness accepted by led on wacom Intuos4 connected over Bluetooth */
36
gsd_wacom_led_helper_write (const gchar *filename, gint value, GError **error)
44
fd = open (filename, O_WRONLY);
46
g_set_error (error, 1, 0, "failed to open filename: %s", filename);
51
text = g_strdup_printf ("%i", value);
52
length = strlen (text);
54
/* write to device file */
55
retval = write (fd, text, length);
56
if (retval != length) {
57
g_set_error (error, 1, 0, "writing '%s' to %s failed", text, filename);
69
get_led_sys_path (GUdevClient *client,
78
char *filename = NULL;
83
const char *dev_hid_uniq;
85
/* check for new unified hid implementation first */
86
parent = g_udev_device_get_parent_with_subsystem (device, "hid", NULL);
88
status = g_strdup_printf ("status_led%d_select", group_num);
89
filename = g_build_filename (g_udev_device_get_sysfs_path (parent), "wacom_led", status, NULL);
91
g_object_unref (parent);
92
if(g_file_test (filename, G_FILE_TEST_EXISTS)) {
93
*write_value = led_num;
96
g_clear_pointer (&filename, g_free);
101
parent = g_udev_device_get_parent_with_subsystem (device, "usb", "usb_interface");
104
status = g_strdup_printf ("status_led%d_select", group_num);
105
filename = g_build_filename (g_udev_device_get_sysfs_path (parent), "wacom_led", status, NULL);
108
*write_value = led_num;
110
parent = g_udev_device_get_parent_with_subsystem (device, "input", NULL);
113
dev_uniq = g_udev_device_get_property (parent, "UNIQ");
115
hid_list = g_udev_client_query_by_subsystem (client, "hid");
116
element = g_list_first(hid_list);
118
hid_dev = (GUdevDevice*)element->data;
119
dev_hid_uniq = g_udev_device_get_property (hid_dev, "HID_UNIQ");
120
if (g_strrstr (dev_uniq, dev_hid_uniq)){
121
status = g_strdup_printf ("/leds/%s:selector:%i/brightness", g_udev_device_get_name (hid_dev), led_num);
122
filename = g_build_filename (g_udev_device_get_sysfs_path (hid_dev), status, NULL);
126
element = g_list_next(element);
128
g_list_free_full(hid_list, g_object_unref);
130
*write_value = LED_BRIGHTNESS;
133
g_object_unref (parent);
138
g_debug ("Could not find proper parent device for '%s'",
139
g_udev_device_get_device_file (device));
144
int main (int argc, char **argv)
146
GOptionContext *context;
153
GError *error = NULL;
154
const char * const subsystems[] = { "hid", "input", NULL };
161
const GOptionEntry options[] = {
162
{ "path", '\0', 0, G_OPTION_ARG_FILENAME, &path, "Device path for the Wacom device", NULL },
163
{ "group", '\0', 0, G_OPTION_ARG_INT, &group_num, "Which LED group to set", NULL },
164
{ "led", '\0', 0, G_OPTION_ARG_INT, &led_num, "Which LED to set", NULL },
168
/* get calling process */
171
if (uid != 0 || euid != 0) {
172
g_print ("This program can only be used by the root user\n");
176
context = g_option_context_new (NULL);
177
g_option_context_set_summary (context, "GNOME Settings Daemon Wacom LED Helper");
178
g_option_context_add_main_entries (context, options, NULL);
179
g_option_context_parse (context, &argc, &argv, NULL);
186
txt = g_option_context_get_help (context, FALSE, NULL);
190
g_option_context_free (context);
194
g_option_context_free (context);
196
client = g_udev_client_new (subsystems);
197
device = g_udev_client_query_by_device_file (client, path);
198
if (device == NULL) {
199
g_debug ("Could not find device '%s' in udev database", path);
203
if (g_udev_device_get_property_as_boolean (device, "ID_INPUT_TABLET") == FALSE &&
204
g_udev_device_get_property_as_boolean (device, "ID_INPUT_TOUCHPAD") == FALSE) {
205
g_debug ("Device '%s' is not a Wacom tablet", path);
209
if (g_strcmp0 (g_udev_device_get_property (device, "ID_BUS"), "usb") != 0)
214
filename = get_led_sys_path (client, device, group_num, led_num, usb, &value);
218
if (gsd_wacom_led_helper_write (filename, value, &error)) {
219
g_debug ("Could not set LED status for '%s': %s", path, error->message);
220
g_error_free (error);
226
g_debug ("Successfully set LED status for '%s', group %d to %d",
227
path, group_num, led_num);
233
g_clear_object (&device);
234
g_clear_object (&client);