]> git.pld-linux.org Git - packages/gimp.git/blob - gimp-udev.patch
- BR: poppler-glib with gdk
[packages/gimp.git] / gimp-udev.patch
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
5
6 GIMP was probably the only user of libhal on most systems, this had
7 to stop. Ported the linux-input module to GUdev.
8 ---
9 diff --git a/configure.in b/configure.in
10 index 1297e0c..f4c1457 100644
11 --- a/configure.in
12 +++ b/configure.in
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
23  fi
24  
25  
26 -###############################################
27 -# Check for libhal (Hardware Abstraction Layer)
28 -###############################################
29 +####################
30 +# Check for libgudev
31 +####################
32  
33 -AC_ARG_WITH(hal,   [  --without-hal           build without HAL support])
34 +AC_ARG_WITH(gudev, [  --without-gudev        build without GUdev support])
35  
36 -have_libhal=no
37 +have_libgudev=no
38  
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)"
43  fi
44  
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,
48 -    have_libhal=yes,
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,
52 +    have_libgudev=yes,
53 +    have_libgudev="no (libgudev not found)")
54  fi
55  
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])
60  fi
61  
62  
63 @@ -2304,7 +2304,7 @@ Plug-In Features:
64  
65  Optional Modules:
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)
78  
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)
90  
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."),
99                                                          NULL,
100                                                          GIMP_CONFIG_PARAM_FLAGS));
101 -#ifdef HAVE_LIBHAL
102 +#ifdef HAVE_LIBGUDEV
103    g_object_class_install_property (object_class, PROP_DEVICE_STORE,
104                                     g_param_spec_object ("device-values",
105                                                          NULL, NULL,
106 @@ -480,11 +480,11 @@ linux_input_get_device_info (ControllerLinuxInput *controller,
107  
108  static void
109  linux_input_device_changed (ControllerLinuxInput *controller,
110 -                            const gchar          *udi)
111 +                            const gchar          *identifier)
112  {
113 -  if (controller->device && strcmp (udi, controller->device) == 0)
114 +  if (controller->device && strcmp (identifier, controller->device) == 0)
115      {
116 -      linux_input_set_device (controller, udi);
117 +      linux_input_set_device (controller, identifier);
118        g_object_notify (G_OBJECT (controller), "device");
119      }
120  }
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
125 @@ -1,9 +1,10 @@
126  /* GIMP - The GNU Image Manipulation Program
127   * Copyright (C) 1995 Spencer Kimball and Peter Mattis
128   *
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>
135   *
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
138 @@ -30,17 +31,16 @@
139  #include "gimpinputdevicestore.h"
140  
141  
142 -#ifdef HAVE_LIBHAL
143 +#ifdef HAVE_LIBGUDEV
144  
145 -#include <dbus/dbus-glib.h>
146 -#include <dbus/dbus-glib-lowlevel.h>
147 -#include <hal/libhal.h>
148 +#include <gudev/gudev.h>
149  
150  
151  enum
152  {
153 -  COLUMN_UDI,
154 +  COLUMN_IDENTIFIER,
155    COLUMN_LABEL,
156 +  COLUMN_DEVICE_FILE,
157    NUM_COLUMNS
158  };
159  
160 @@ -60,10 +60,10 @@ typedef struct _GimpInputDeviceStoreClass GimpInputDeviceStoreClass;
161  
162  struct _GimpInputDeviceStore
163  {
164 -  GtkListStore    parent_instance;
165 +  GtkListStore  parent_instance;
166  
167 -  LibHalContext  *context;
168 -  GError         *error;
169 +  GUdevClient  *client;
170 +  GError       *error;
171  };
172  
173  
174 @@ -72,23 +72,23 @@ struct _GimpInputDeviceStoreClass
175    GtkListStoreClass   parent_class;
176  
177    void  (* device_added)   (GimpInputDeviceStore *store,
178 -                            const gchar          *udi);
179 +                            const gchar          *identifier);
180    void  (* device_removed) (GimpInputDeviceStore *store,
181 -                            const gchar          *udi);
182 +                            const gchar          *identifier);
183  };
184  
185  
186  static void      gimp_input_device_store_finalize   (GObject              *object);
187  
188  static gboolean  gimp_input_device_store_add        (GimpInputDeviceStore *store,
189 -                                                     const gchar          *udi);
190 +                                                     GUdevDevice          *device);
191  static gboolean  gimp_input_device_store_remove     (GimpInputDeviceStore *store,
192 -                                                     const gchar          *udi);
193 +                                                     GUdevDevice          *device);
194  
195 -static void      gimp_input_device_store_device_added   (LibHalContext *ctx,
196 -                                                         const char    *udi);
197 -static void      gimp_input_device_store_device_removed (LibHalContext *ctx,
198 -                                                         const char    *udi);
199 +static void      gimp_input_device_store_uevent     (GUdevClient          *client,
200 +                                                     const gchar          *action,
201 +                                                     GUdevDevice          *device,
202 +                                                     GimpInputDeviceStore *store);
203  
204  
205  G_DEFINE_DYNAMIC_TYPE (GimpInputDeviceStore, gimp_input_device_store,
206 @@ -140,61 +140,31 @@ gimp_input_device_store_class_finalize (GimpInputDeviceStoreClass *klass)
207  static void
208  gimp_input_device_store_init (GimpInputDeviceStore *store)
209  {
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 };
215 +  GList       *devices;
216 +  GList       *list;
217  
218    gtk_list_store_set_column_types (GTK_LIST_STORE (store),
219                                     G_N_ELEMENTS (types), types);
220  
221 -  connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &store->error);
222 +  store->client = g_udev_client_new (subsystems);
223  
224 -  if (! connection)
225 -    return;
226 +  devices = g_udev_client_query_by_subsystem (store->client, "input");
227  
228 -  store->context = libhal_ctx_new ();
229 -
230 -  libhal_ctx_set_dbus_connection (store->context,
231 -                                  dbus_g_connection_get_connection (connection));
232 -  dbus_g_connection_unref (connection);
233 -
234 -  dbus_error_init (&dbus_error);
235 -
236 -  if (libhal_ctx_init (store->context, &dbus_error))
237 +  for (list = devices; list; list = g_list_next (list))
238      {
239 -      char **devices;
240 -      int    i, num_devices;
241 -
242 -      devices = libhal_find_device_by_capability (store->context, "input",
243 -                                                  &num_devices, NULL);
244 -
245 -      for (i = 0; i < num_devices; i++)
246 -        gimp_input_device_store_add (store, devices[i]);
247 +      GUdevDevice *device = list->data;
248  
249 -      libhal_free_string_array (devices);
250 -
251 -      libhal_ctx_set_user_data (store->context, store);
252 -
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);
259      }
260 -  else
261 -    {
262 -      if (dbus_error_is_set (&dbus_error))
263 -        {
264 -          dbus_set_g_error (&store->error, &dbus_error);
265 -          dbus_error_free (&dbus_error);
266 -        }
267 -      else
268 -        {
269 -          g_set_error (&store->error, 0, 0, "Unable to connect to hald");
270 -        }
271  
272 -      libhal_ctx_free (store->context);
273 -      store->context = NULL;
274 -    }
275 +  g_list_free (devices);
276 +
277 +  g_signal_connect (store->client, "uevent",
278 +                    G_CALLBACK (gimp_input_device_store_uevent),
279 +                    store);
280  }
281  
282  static void
283 @@ -204,11 +172,10 @@ gimp_input_device_store_finalize (GObject *object)
284  {
285    GimpInputDeviceStore *store = GIMP_INPUT_DEVICE_STORE (object);
286  
287 -  if (store->context)
288 +  if (store->client)
289      {
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;
295      }
296  
297    if (store->error)
298 @@ -222,7 +189,7 @@ gimp_input_device_store_finalize (GObject *object)
299  
300  static gboolean
301  gimp_input_device_store_lookup (GimpInputDeviceStore *store,
302 -                                const gchar          *udi,
303 +                                const gchar          *identifier,
304                                  GtkTreeIter          *iter)
305  {
306    GtkTreeModel *model = GTK_TREE_MODEL (store);
307 @@ -235,11 +202,11 @@ gimp_input_device_store_lookup (GimpInputDeviceStore *store,
308      {
309        const gchar *str;
310  
311 -      gtk_tree_model_get_value (model, iter, COLUMN_UDI, &value);
312 +      gtk_tree_model_get_value (model, iter, COLUMN_IDENTIFIER, &value);
313  
314        str = g_value_get_string (&value);
315  
316 -      if (strcmp (str, udi) == 0)
317 +      if (strcmp (str, identifier) == 0)
318          {
319            g_value_unset (&value);
320            break;
321 @@ -254,8 +221,9 @@ gimp_input_device_store_lookup (GimpInputDeviceStore *store,
322  /*  insert in alphabetic order  */
323  static void
324  gimp_input_device_store_insert (GimpInputDeviceStore *store,
325 -                                const gchar          *udi,
326 -                                const gchar          *label)
327 +                                const gchar          *identifier,
328 +                                const gchar          *label,
329 +                                const gchar          *device_file)
330  {
331    GtkTreeModel *model = GTK_TREE_MODEL (store);
332    GtkTreeIter   iter;
333 @@ -283,72 +251,90 @@ gimp_input_device_store_insert (GimpInputDeviceStore *store,
334      }
335  
336    gtk_list_store_insert_with_values (GTK_LIST_STORE (store), &iter, pos,
337 -                                     COLUMN_UDI,   udi,
338 -                                     COLUMN_LABEL, label,
339 +                                     COLUMN_IDENTIFIER,  identifier,
340 +                                     COLUMN_LABEL,       label,
341 +                                     COLUMN_DEVICE_FILE, device_file,
342                                       -1);
343  }
344  
345  static gboolean
346  gimp_input_device_store_add (GimpInputDeviceStore *store,
347 -                             const gchar          *udi)
348 +                             GUdevDevice          *device)
349  {
350 -  gboolean   added = FALSE;
351 -  char     **caps;
352 -  gint       i;
353 -
354 -  caps = libhal_device_get_property_strlist (store->context,
355 -                                             udi, "info.capabilities",
356 -                                             NULL);
357 -
358 -  for (i = 0; caps && caps[i] && !added; i++)
359 +  const gchar *device_file = g_udev_device_get_device_file (device);
360 +#if 0
361 +  const gchar *path        = g_udev_device_get_sysfs_path (device);
362 +#endif
363 +  const gchar *name        = g_udev_device_get_sysfs_attr (device, "name");
364 +
365 +#if 0
366 +  g_printerr ("\ndevice added: %s, %s, %s\n",
367 +              name ? name : "NULL",
368 +              device_file ? device_file : "NULL",
369 +              path);
370 +#endif
371 +
372 +  if (device_file)
373      {
374 -      char *str;
375 +      if (name)
376 +        {
377 +          GtkTreeIter unused;
378 +
379 +          if (! gimp_input_device_store_lookup (store, name, &unused))
380 +            {
381 +              gimp_input_device_store_insert (store, name, name, device_file);
382  
383 -      if (strcmp (caps[i], "input") != 0)
384 -        continue;
385 +              g_signal_emit (store, store_signals[DEVICE_ADDED], 0,
386 +                             name);
387  
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",
391 -                                               NULL);
392 -      if (str)
393 +              return TRUE;
394 +            }
395 +        }
396 +      else
397          {
398 -          gboolean speaker =
399 -            strcmp (str, "/org/freedesktop/Hal/devices/platform_pcspkr") == 0;
400 +          GUdevDevice *parent = g_udev_device_get_parent (device);
401 +          const gchar *parent_name;
402  
403 -          libhal_free_string (str);
404 +          parent_name = g_udev_device_get_sysfs_attr (parent, "name");
405  
406 -          if (speaker)
407 -            continue;
408 -        }
409 +          if (parent_name)
410 +            {
411 +              GtkTreeIter unused;
412  
413 -      str = libhal_device_get_property_string (store->context,
414 -                                               udi, "input.product",
415 -                                               NULL);
416 -      if (str)
417 -        {
418 -          gimp_input_device_store_insert (store, udi, str);
419 +              if (! gimp_input_device_store_lookup (store, parent_name, &unused))
420 +                {
421 +                  gimp_input_device_store_insert (store, parent_name, parent_name,
422 +                                                  device_file);
423 +
424 +                  g_signal_emit (store, store_signals[DEVICE_ADDED], 0,
425 +                                 parent_name);
426  
427 -          libhal_free_string (str);
428 +                  g_object_unref (parent);
429 +                  return TRUE;
430 +                }
431 +            }
432  
433 -          added = TRUE;
434 +          g_object_unref (parent);
435 +          return FALSE;
436          }
437      }
438  
439 -  libhal_free_string_array (caps);
440 -
441 -  return added;
442 +  return FALSE;
443  }
444  
445  static gboolean
446  gimp_input_device_store_remove (GimpInputDeviceStore *store,
447 -                                const gchar          *udi)
448 +                                GUdevDevice          *device)
449  {
450 +  const gchar *name = g_udev_device_get_sysfs_attr (device, "name");
451    GtkTreeIter  iter;
452  
453 -  if (gimp_input_device_store_lookup (store, udi, &iter))
454 +  if (gimp_input_device_store_lookup (store, name, &iter))
455      {
456        gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
457 +
458 +      g_signal_emit (store, store_signals[DEVICE_REMOVED], 0, name);
459 +
460        return TRUE;
461      }
462  
463 @@ -356,26 +342,18 @@ gimp_input_device_store_remove (GimpInputDeviceStore *store,
464  }
465  
466  static void
467 -gimp_input_device_store_device_added (LibHalContext *ctx,
468 -                                      const char    *udi)
469 +gimp_input_device_store_uevent (GUdevClient          *client,
470 +                                const gchar          *action,
471 +                                GUdevDevice          *device,
472 +                                GimpInputDeviceStore *store)
473  {
474 -  GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
475 -
476 -  if (gimp_input_device_store_add (store, udi))
477 +  if (! strcmp (action, "add"))
478      {
479 -      g_signal_emit (store, store_signals[DEVICE_ADDED], 0, udi);
480 +      gimp_input_device_store_add (store, device);
481      }
482 -}
483 -
484 -static void
485 -gimp_input_device_store_device_removed (LibHalContext *ctx,
486 -                                        const char    *udi)
487 -{
488 -  GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
489 -
490 -  if (gimp_input_device_store_remove (store, udi))
491 +  else if (! strcmp (action, "remove"))
492      {
493 -      g_signal_emit (store, store_signals[DEVICE_REMOVED], 0, udi);
494 +      gimp_input_device_store_remove (store, device);
495      }
496  }
497  
498 @@ -387,30 +365,26 @@ gimp_input_device_store_new (void)
499  
500  gchar *
501  gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
502 -                                         const gchar          *udi)
503 +                                         const gchar          *identifier)
504  {
505    GtkTreeIter iter;
506  
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);
510  
511 -  if (! store->context)
512 +  if (! store->client)
513      return NULL;
514  
515 -  if (gimp_input_device_store_lookup (store, udi, &iter))
516 +  if (gimp_input_device_store_lookup (store, identifier, &iter))
517      {
518 -      char *str = libhal_device_get_property_string (store->context,
519 -                                                     udi, "input.device",
520 -                                                     NULL);
521 -
522 -      if (str)
523 -        {
524 -          gchar *retval = g_strdup (str);
525 +      GtkTreeModel *model = GTK_TREE_MODEL (store);
526 +      gchar        *device_file;
527  
528 -          libhal_free_string (str);
529 +      gtk_tree_model_get (model, &iter,
530 +                          COLUMN_DEVICE_FILE, &device_file,
531 +                          -1);
532  
533 -          return retval;
534 -        }
535 +      return device_file;
536      }
537  
538    return NULL;
539 @@ -424,7 +398,7 @@ gimp_input_device_store_get_error (GimpInputDeviceStore  *store)
540    return store->error ? g_error_copy (store->error) : NULL;
541  }
542  
543 -#else /* HAVE_LIBHAL */
544 +#else /* HAVE_LIBGUDEV */
545  
546  void
547  gimp_input_device_store_register_types (GTypeModule *module)
548 @@ -445,7 +419,7 @@ gimp_input_device_store_new (void)
549  
550  gchar *
551  gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
552 -                                         const gchar          *udi)
553 +                                         const gchar          *identifier)
554  {
555    return NULL;
556  }
557 @@ -456,4 +430,4 @@ gimp_input_device_store_get_error (GimpInputDeviceStore  *store)
558    return NULL;
559  }
560  
561 -#endif /* HAVE_LIBHAL */
562 +#endif /* HAVE_LIBGUDEV */
563 --
564 cgit v0.9
This page took 0.115424 seconds and 3 git commands to generate.