1 From f1bb40166b1061f630fab615f658310c25abf423 Mon Sep 17 00:00:00 2001
2 From: Michael Natterer <mitch@gimp.org>
3 Date: Thu, 23 Jun 2011 14:30:58 +0000
4 Subject: Bug 592364 - Use GUdev rather than deprecated HAL for GIMP
6 GIMP was probably the only user of libhal on most systems, this had
7 to stop. Ported the linux-input module to GUdev.
9 diff --git a/configure.in b/configure.in
10 index 1297e0c..f4c1457 100644
13 @@ -58,7 +58,7 @@ m4_define([pygtk_required_version], [2.10.4])
14 m4_define([poppler_required_version], [0.12.4])
15 m4_define([libcurl_required_version], [7.15.1])
16 m4_define([dbus_glib_required_version], [0.70])
17 -m4_define([libhal_required_version], [0.5.7])
18 +m4_define([libgudev_required_version], [167])
19 m4_define([exif_required_version], [0.6.15])
20 m4_define([lcms_required_version], [1.16])
21 m4_define([libpng_required_version], [1.2.37])
22 @@ -1623,27 +1623,27 @@ if test "x$have_dbus_glib" = xyes; then
26 -###############################################
27 -# Check for libhal (Hardware Abstraction Layer)
28 -###############################################
33 -AC_ARG_WITH(hal, [ --without-hal build without HAL support])
34 +AC_ARG_WITH(gudev, [ --without-gudev build without GUdev support])
39 -if test "x$with_hal" = xno; then
40 - have_libhal="no (disabled)"
41 +if test "x$with_gudev" = xno; then
42 + have_libgudev="no (disabled)"
45 if test "x$have_linux_input" = xyes && test "x$have_dbus_glib" = xyes &&
46 - test "x$with_hal" != xno; then
47 - PKG_CHECK_MODULES(HAL, hal >= libhal_required_version,
49 - have_libhal="no (libhal not found)")
50 + test "x$with_gudev" != xno; then
51 + PKG_CHECK_MODULES(GUDEV, gudev-1.0 >= libgudev_required_version,
53 + have_libgudev="no (libgudev not found)")
56 -if test "x$have_libhal" = xyes; then
57 - AC_DEFINE(HAVE_LIBHAL, 1, [Define to 1 if libhal is available])
58 +if test "x$have_libgudev" = xyes; then
59 + AC_DEFINE(HAVE_LIBGUDEV, 1, [Define to 1 if libgudev is available])
63 @@ -2304,7 +2304,7 @@ Plug-In Features:
66 ALSA (MIDI Input): $have_alsa
67 - Linux Input: $have_linux_input (HAL support: $have_libhal)
68 + Linux Input: $have_linux_input (GUdev support: $have_libgudev)
69 DirectInput (Win32): $have_dx_dinput
70 Color Correction: $have_lcms
71 Soft Proof: $have_lcms
72 diff --git a/modules/Makefile.am b/modules/Makefile.am
73 index 4dfced7..ab476a3 100644
74 --- a/modules/Makefile.am
75 +++ b/modules/Makefile.am
76 @@ -104,13 +104,13 @@ libdisplay_filter_proof_la_LDFLAGS = -avoid-version -module $(no_undefined)
77 libdisplay_filter_proof_la_LIBADD = $(display_filter_libadd) $(LCMS_LIBS)
79 libcontroller_linux_input_la_SOURCES = \
80 - gimpinputdevicestore-hal.c \
81 + gimpinputdevicestore-gudev.c \
82 gimpinputdevicestore.h \
83 controller-linux-input.c
84 -libcontroller_linux_input_la_CFLAGS = $(DBUS_GLIB_CFLAGS) $(HAL_CFLAGS)
85 +libcontroller_linux_input_la_CFLAGS = $(GUDEV_CFLAGS)
86 libcontroller_linux_input_la_LDFLAGS = -avoid-version -module $(no_undefined)
87 libcontroller_linux_input_la_LIBADD = \
88 - $(controller_libadd) $(DBUS_GLIB_LIBS) $(HAL_LIBS)
89 + $(controller_libadd) $(GUDEV_LIBS)
91 libcontroller_dx_dinput_la_SOURCES = \
92 gimpinputdevicestore-dx.c \
93 diff --git a/modules/controller-linux-input.c b/modules/controller-linux-input.c
94 index b7f69e0..fe3f5e8 100644
95 --- a/modules/controller-linux-input.c
96 +++ b/modules/controller-linux-input.c
97 @@ -218,7 +218,7 @@ controller_linux_input_class_init (ControllerLinuxInputClass *klass)
98 _("The name of the device to read Linux Input events from."),
100 GIMP_CONFIG_PARAM_FLAGS));
102 +#ifdef HAVE_LIBGUDEV
103 g_object_class_install_property (object_class, PROP_DEVICE_STORE,
104 g_param_spec_object ("device-values",
106 @@ -480,11 +480,11 @@ linux_input_get_device_info (ControllerLinuxInput *controller,
109 linux_input_device_changed (ControllerLinuxInput *controller,
111 + const gchar *identifier)
113 - if (controller->device && strcmp (udi, controller->device) == 0)
114 + if (controller->device && strcmp (identifier, controller->device) == 0)
116 - linux_input_set_device (controller, udi);
117 + linux_input_set_device (controller, identifier);
118 g_object_notify (G_OBJECT (controller), "device");
121 diff --git a/modules/gimpinputdevicestore-hal.c b/modules/gimpinputdevicestore-gudev.c
122 index 06770dd..4c703bc 100644
123 --- a/modules/gimpinputdevicestore-hal.c
124 +++ b/modules/gimpinputdevicestore-gudev.c
126 /* GIMP - The GNU Image Manipulation Program
127 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
129 - * gimpinputdevicestore-hal.c
130 - * Input device store based on HAL, the hardware abstraction layer.
131 + * gimpinputdevicestore-gudev.c
132 + * Input device store based on GUdev, the hardware abstraction layer.
133 * Copyright (C) 2007 Sven Neumann <sven@gimp.org>
134 + * 2011 Michael Natterer <mitch@gimp.org>
136 * This program is free software: you can redistribute it and/or modify
137 * it under the terms of the GNU General Public License as published by
139 #include "gimpinputdevicestore.h"
143 +#ifdef HAVE_LIBGUDEV
145 -#include <dbus/dbus-glib.h>
146 -#include <dbus/dbus-glib-lowlevel.h>
147 -#include <hal/libhal.h>
148 +#include <gudev/gudev.h>
156 + COLUMN_DEVICE_FILE,
160 @@ -60,10 +60,10 @@ typedef struct _GimpInputDeviceStoreClass GimpInputDeviceStoreClass;
162 struct _GimpInputDeviceStore
164 - GtkListStore parent_instance;
165 + GtkListStore parent_instance;
167 - LibHalContext *context;
169 + GUdevClient *client;
174 @@ -72,23 +72,23 @@ struct _GimpInputDeviceStoreClass
175 GtkListStoreClass parent_class;
177 void (* device_added) (GimpInputDeviceStore *store,
179 + const gchar *identifier);
180 void (* device_removed) (GimpInputDeviceStore *store,
182 + const gchar *identifier);
186 static void gimp_input_device_store_finalize (GObject *object);
188 static gboolean gimp_input_device_store_add (GimpInputDeviceStore *store,
190 + GUdevDevice *device);
191 static gboolean gimp_input_device_store_remove (GimpInputDeviceStore *store,
193 + GUdevDevice *device);
195 -static void gimp_input_device_store_device_added (LibHalContext *ctx,
197 -static void gimp_input_device_store_device_removed (LibHalContext *ctx,
199 +static void gimp_input_device_store_uevent (GUdevClient *client,
200 + const gchar *action,
201 + GUdevDevice *device,
202 + GimpInputDeviceStore *store);
205 G_DEFINE_DYNAMIC_TYPE (GimpInputDeviceStore, gimp_input_device_store,
206 @@ -140,61 +140,31 @@ gimp_input_device_store_class_finalize (GimpInputDeviceStoreClass *klass)
208 gimp_input_device_store_init (GimpInputDeviceStore *store)
210 - GType types[] = { G_TYPE_STRING, G_TYPE_STRING };
211 - DBusGConnection *connection;
212 - DBusError dbus_error;
213 + GType types[] = { G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING };
214 + const gchar *subsystems[] = { "input", NULL };
218 gtk_list_store_set_column_types (GTK_LIST_STORE (store),
219 G_N_ELEMENTS (types), types);
221 - connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &store->error);
222 + store->client = g_udev_client_new (subsystems);
226 + devices = g_udev_client_query_by_subsystem (store->client, "input");
228 - store->context = libhal_ctx_new ();
230 - libhal_ctx_set_dbus_connection (store->context,
231 - dbus_g_connection_get_connection (connection));
232 - dbus_g_connection_unref (connection);
234 - dbus_error_init (&dbus_error);
236 - if (libhal_ctx_init (store->context, &dbus_error))
237 + for (list = devices; list; list = g_list_next (list))
240 - int i, num_devices;
242 - devices = libhal_find_device_by_capability (store->context, "input",
243 - &num_devices, NULL);
245 - for (i = 0; i < num_devices; i++)
246 - gimp_input_device_store_add (store, devices[i]);
247 + GUdevDevice *device = list->data;
249 - libhal_free_string_array (devices);
251 - libhal_ctx_set_user_data (store->context, store);
253 - libhal_ctx_set_device_added (store->context,
254 - gimp_input_device_store_device_added);
255 - libhal_ctx_set_device_removed (store->context,
256 - gimp_input_device_store_device_removed);
257 + gimp_input_device_store_add (store, device);
258 + g_object_unref (device);
262 - if (dbus_error_is_set (&dbus_error))
264 - dbus_set_g_error (&store->error, &dbus_error);
265 - dbus_error_free (&dbus_error);
269 - g_set_error (&store->error, 0, 0, "Unable to connect to hald");
272 - libhal_ctx_free (store->context);
273 - store->context = NULL;
275 + g_list_free (devices);
277 + g_signal_connect (store->client, "uevent",
278 + G_CALLBACK (gimp_input_device_store_uevent),
283 @@ -204,11 +172,10 @@ gimp_input_device_store_finalize (GObject *object)
285 GimpInputDeviceStore *store = GIMP_INPUT_DEVICE_STORE (object);
287 - if (store->context)
290 - libhal_ctx_shutdown (store->context, NULL);
291 - libhal_ctx_free (store->context);
292 - store->context = NULL;
293 + g_object_unref (store->client);
294 + store->client = NULL;
298 @@ -222,7 +189,7 @@ gimp_input_device_store_finalize (GObject *object)
301 gimp_input_device_store_lookup (GimpInputDeviceStore *store,
303 + const gchar *identifier,
306 GtkTreeModel *model = GTK_TREE_MODEL (store);
307 @@ -235,11 +202,11 @@ gimp_input_device_store_lookup (GimpInputDeviceStore *store,
311 - gtk_tree_model_get_value (model, iter, COLUMN_UDI, &value);
312 + gtk_tree_model_get_value (model, iter, COLUMN_IDENTIFIER, &value);
314 str = g_value_get_string (&value);
316 - if (strcmp (str, udi) == 0)
317 + if (strcmp (str, identifier) == 0)
319 g_value_unset (&value);
321 @@ -254,8 +221,9 @@ gimp_input_device_store_lookup (GimpInputDeviceStore *store,
322 /* insert in alphabetic order */
324 gimp_input_device_store_insert (GimpInputDeviceStore *store,
326 - const gchar *label)
327 + const gchar *identifier,
328 + const gchar *label,
329 + const gchar *device_file)
331 GtkTreeModel *model = GTK_TREE_MODEL (store);
333 @@ -283,72 +251,90 @@ gimp_input_device_store_insert (GimpInputDeviceStore *store,
336 gtk_list_store_insert_with_values (GTK_LIST_STORE (store), &iter, pos,
338 - COLUMN_LABEL, label,
339 + COLUMN_IDENTIFIER, identifier,
340 + COLUMN_LABEL, label,
341 + COLUMN_DEVICE_FILE, device_file,
346 gimp_input_device_store_add (GimpInputDeviceStore *store,
348 + GUdevDevice *device)
350 - gboolean added = FALSE;
354 - caps = libhal_device_get_property_strlist (store->context,
355 - udi, "info.capabilities",
358 - for (i = 0; caps && caps[i] && !added; i++)
359 + const gchar *device_file = g_udev_device_get_device_file (device);
361 + const gchar *path = g_udev_device_get_sysfs_path (device);
363 + const gchar *name = g_udev_device_get_sysfs_attr (device, "name");
366 + g_printerr ("\ndevice added: %s, %s, %s\n",
367 + name ? name : "NULL",
368 + device_file ? device_file : "NULL",
377 + GtkTreeIter unused;
379 + if (! gimp_input_device_store_lookup (store, name, &unused))
381 + gimp_input_device_store_insert (store, name, name, device_file);
383 - if (strcmp (caps[i], "input") != 0)
385 + g_signal_emit (store, store_signals[DEVICE_ADDED], 0,
388 - /* skip "PC Speaker" (why is this an input device at all?) */
389 - str = libhal_device_get_property_string (store->context,
390 - udi, "input.physical_device",
399 - strcmp (str, "/org/freedesktop/Hal/devices/platform_pcspkr") == 0;
400 + GUdevDevice *parent = g_udev_device_get_parent (device);
401 + const gchar *parent_name;
403 - libhal_free_string (str);
404 + parent_name = g_udev_device_get_sysfs_attr (parent, "name");
411 + GtkTreeIter unused;
413 - str = libhal_device_get_property_string (store->context,
414 - udi, "input.product",
418 - gimp_input_device_store_insert (store, udi, str);
419 + if (! gimp_input_device_store_lookup (store, parent_name, &unused))
421 + gimp_input_device_store_insert (store, parent_name, parent_name,
424 + g_signal_emit (store, store_signals[DEVICE_ADDED], 0,
427 - libhal_free_string (str);
428 + g_object_unref (parent);
434 + g_object_unref (parent);
439 - libhal_free_string_array (caps);
446 gimp_input_device_store_remove (GimpInputDeviceStore *store,
448 + GUdevDevice *device)
450 + const gchar *name = g_udev_device_get_sysfs_attr (device, "name");
453 - if (gimp_input_device_store_lookup (store, udi, &iter))
454 + if (gimp_input_device_store_lookup (store, name, &iter))
456 gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
458 + g_signal_emit (store, store_signals[DEVICE_REMOVED], 0, name);
463 @@ -356,26 +342,18 @@ gimp_input_device_store_remove (GimpInputDeviceStore *store,
467 -gimp_input_device_store_device_added (LibHalContext *ctx,
469 +gimp_input_device_store_uevent (GUdevClient *client,
470 + const gchar *action,
471 + GUdevDevice *device,
472 + GimpInputDeviceStore *store)
474 - GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
476 - if (gimp_input_device_store_add (store, udi))
477 + if (! strcmp (action, "add"))
479 - g_signal_emit (store, store_signals[DEVICE_ADDED], 0, udi);
480 + gimp_input_device_store_add (store, device);
485 -gimp_input_device_store_device_removed (LibHalContext *ctx,
488 - GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
490 - if (gimp_input_device_store_remove (store, udi))
491 + else if (! strcmp (action, "remove"))
493 - g_signal_emit (store, store_signals[DEVICE_REMOVED], 0, udi);
494 + gimp_input_device_store_remove (store, device);
498 @@ -387,30 +365,26 @@ gimp_input_device_store_new (void)
501 gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
503 + const gchar *identifier)
507 g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
508 - g_return_val_if_fail (udi != NULL, NULL);
509 + g_return_val_if_fail (identifier != NULL, NULL);
511 - if (! store->context)
512 + if (! store->client)
515 - if (gimp_input_device_store_lookup (store, udi, &iter))
516 + if (gimp_input_device_store_lookup (store, identifier, &iter))
518 - char *str = libhal_device_get_property_string (store->context,
519 - udi, "input.device",
524 - gchar *retval = g_strdup (str);
525 + GtkTreeModel *model = GTK_TREE_MODEL (store);
526 + gchar *device_file;
528 - libhal_free_string (str);
529 + gtk_tree_model_get (model, &iter,
530 + COLUMN_DEVICE_FILE, &device_file,
535 + return device_file;
539 @@ -424,7 +398,7 @@ gimp_input_device_store_get_error (GimpInputDeviceStore *store)
540 return store->error ? g_error_copy (store->error) : NULL;
543 -#else /* HAVE_LIBHAL */
544 +#else /* HAVE_LIBGUDEV */
547 gimp_input_device_store_register_types (GTypeModule *module)
548 @@ -445,7 +419,7 @@ gimp_input_device_store_new (void)
551 gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
553 + const gchar *identifier)
557 @@ -456,4 +430,4 @@ gimp_input_device_store_get_error (GimpInputDeviceStore *store)
561 -#endif /* HAVE_LIBHAL */
562 +#endif /* HAVE_LIBGUDEV */