setting evdev properties from HAL?

Peter Hutterer peter.hutterer at who-t.net
Sat Jul 4 15:44:40 PDT 2009


On Sat, Jul 04, 2009 at 02:32:09PM +0200, Simon Thum wrote:
> Asbjørn Sannes wrote:
> > But for "Evdev Axis Calibration" I have not found anything that works ..
> > 
> > Any hints and suggestions are welcome :)
> One could probably do a patch which adds property manipulation to
> config/hal, but it didn't surface yet.
> 
> I remember to have heard hal can be configured to invoke scripts like
> yours on device add/remove. Not sure of it, though.
 
I started that once but I'm being told HAL is on its way out so I decided
not to finish them. If you want to pick it up - be my guest, patches below.
Having said that, it is questionable whether they will go upstream if you do
finish them. There is quite a push away from HAL and adding new HAL-only
functionality is not the way to go. Especially for things like this that can
be set at runtime.

Time is possibly better spent investigating libudev and finding out how to
automatically port current fdi configurations so they work on a udev-only
system.

Cheers,
  Peter

>From 74c05685e47586f70e0d7b324a1e29eac44e59b9 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer at who-t.net>
Date: Thu, 26 Mar 2009 14:23:09 +1000
Subject: [PATCH] config: rename LIBHAL_... defines for better namespacing.

---
 config/hal.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index 36fa839..782fbb5 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -40,8 +40,8 @@
 #include "os.h"
 
 
-#define LIBHAL_PROP_KEY "input.x11_options."
-#define LIBHAL_XKB_PROP_KEY "input.xkb."
+#define LIBHAL_OPTIONS_KEY "input.x11_options."
+#define LIBHAL_XKB_OPTIONS_KEY "input.xkb."
 
 
 struct config_hal_info {
@@ -273,7 +273,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         if (psi_key){
 
             /* normal options first (input.x11_options.<propname>) */
-            if (!strncasecmp(psi_key, LIBHAL_PROP_KEY, sizeof(LIBHAL_PROP_KEY)-1)){
+            if (!strncasecmp(psi_key, LIBHAL_OPTIONS_KEY, sizeof(LIBHAL_OPTIONS_KEY)-1)){
                 char* tmp;
 
                 /* only support strings for all values */
@@ -319,7 +319,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                     } else
                     {
                         /* all others */
-                        add_option(&options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val);
+                        add_option(&options, psi_key + sizeof(LIBHAL_OPTIONS_KEY)-1, tmp_val);
                         xfree(tmp_val);
                     }
                 } else
@@ -335,15 +335,15 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                         xkb_opts.options = strdup(tmp_val);
                     }
                 }
-            } else if (!strncasecmp(psi_key, LIBHAL_XKB_PROP_KEY, sizeof(LIBHAL_XKB_PROP_KEY)-1)){
+            } else if (!strncasecmp(psi_key, LIBHAL_XKB_OPTIONS_KEY, sizeof(LIBHAL_XKB_OPTIONS_KEY)-1)){
                 char* tmp;
 
                 /* only support strings for all values */
                 tmp_val = get_prop_string(hal_ctx, udi, psi_key);
 
-                if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_PROP_KEY)) {
+                if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_OPTIONS_KEY)) {
 
-                    tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1];
+                    tmp = &psi_key[sizeof(LIBHAL_XKB_OPTIONS_KEY) - 1];
 
                     if (!strcasecmp(tmp, "layout"))
                     {
@@ -371,9 +371,9 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                 {
                     /* server 1.4 had xkb options as strlist */
                     tmp_val = get_prop_string_array(hal_ctx, udi, psi_key);
-                    if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_PROP_KEY))
+                    if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_OPTIONS_KEY))
                     {
-                        tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1];
+                        tmp = &psi_key[sizeof(LIBHAL_XKB_OPTIONS_KEY) - 1];
                         if (!strcasecmp(tmp, ".options") && (!xkb_opts.options))
                             xkb_opts.options = strdup(tmp_val);
                     }
-- 
1.6.0.6


>From 96bbf362cb7a9c624189b6c53c4578a3496abddd Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer at who-t.net>
Date: Thu, 26 Mar 2009 14:23:47 +1000
Subject: [PATCH] config: allow device labelling through hal keys.

Supports hal keys in the following format:
<append key="input.x11_property.abc" type="strlist">123</append>
<append key="input.x11_property.abc" type="strlist">456</append>
<append key="input.x11_property.foo" type="strlist">bar</append>

The above results in two properties being added to the input device:
  "abc" -> "123", "456"
  "foo" -> "bar"

Where both "abc" and "foo" are properties that contain lists of Atoms (and
123, 456 and bar are Atoms created on-the-fly).

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 config/hal.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index 782fbb5..8156d8b 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -32,15 +32,18 @@
 #include <hal/libhal.h>
 #include <string.h>
 #include <sys/select.h>
+#include <X11/Xatom.h>
 
 #include "input.h"
 #include "inputstr.h"
 #include "hotplug.h"
 #include "config-backends.h"
 #include "os.h"
+#include "exevents.h"
 
 
 #define LIBHAL_OPTIONS_KEY "input.x11_options."
+#define LIBHAL_PROPERTIES_KEY "input.x11_property."
 #define LIBHAL_XKB_OPTIONS_KEY "input.xkb."
 
 
@@ -58,6 +61,12 @@ struct xkb_options {
     char* options;
 };
 
+struct dev_property {
+    struct dev_property *next; /* null-terminated */
+    char *propname;
+    int nitems;
+    char **values;
+};
 
 static void
 remove_device(DeviceIntPtr dev)
@@ -132,6 +141,9 @@ get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name)
     return ret;
 }
 
+/**
+ * Get the strlist from HAL and collate into a comma-separated list.
+ */
 static char *
 get_prop_string_array(LibHalContext *hal_ctx, const char *udi, const char *prop)
 {
@@ -166,6 +178,39 @@ get_prop_string_array(LibHalContext *hal_ctx, const char *udi, const char *prop)
     return ret;
 }
 
+/**
+ * Duplicate the strlist from hal and return it in strlist_return. Returns the
+ * number of items.
+ * Caller must free the list.
+ */
+static int
+get_prop_strlist(LibHalContext *hal_ctx, const char *udi,
+                 const char *prop, char ***strlist_return)
+{
+    char **props;
+    int i, nitems = 0;
+
+    props = libhal_device_get_property_strlist(hal_ctx, udi, prop, NULL);
+    if (props) {
+        for (i = 0; props[i]; i++)
+            nitems++;
+
+        *strlist_return = xcalloc(nitems, sizeof(char**));
+        if (!*strlist_return) {
+            libhal_free_string_array(props);
+            return 0;
+        }
+
+        for (i = 0; props[i]; i++) {
+            (*strlist_return)[i] = strdup(props[i]);
+        }
+
+    }
+
+    libhal_free_string_array(props);
+    return nitems;
+}
+
 static BOOL
 device_is_duplicate(char *config_info)
 {
@@ -194,6 +239,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     DeviceIntPtr dev = NULL;
     DBusError error;
     struct xkb_options xkb_opts = {0};
+    struct dev_property *dev_props = NULL;
     int rc;
 
     LibHalPropertySet *set = NULL;
@@ -378,6 +424,26 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                             xkb_opts.options = strdup(tmp_val);
                     }
                 }
+            } else if (!strncasecmp(psi_key, LIBHAL_PROPERTIES_KEY, sizeof(LIBHAL_PROPERTIES_KEY)-1)){
+                char **strlist;
+                int nitems;
+                if ((strlen(psi_key) >= sizeof(LIBHAL_PROPERTIES_KEY)) &&
+                    (nitems = get_prop_strlist(hal_ctx, udi, psi_key, &strlist)))
+                {
+                    struct dev_property *dp;
+
+                    dp = xcalloc (1, sizeof(struct dev_property));
+                    if (dp)
+                    {
+                        dp->propname =
+                            strdup(&psi_key[sizeof(LIBHAL_PROPERTIES_KEY) - 1]);
+
+                        dp->nitems = nitems;
+                        dp->values = strlist;
+                        dp->next = dev_props;
+                        dev_props = dp;
+                    }
+                }
             }
         }
 
@@ -406,6 +472,30 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         goto unwind;
     }
 
+    while(dev_props) {
+        struct dev_property *next  = dev_props->next;
+        int i;
+        Atom *atoms;
+        Atom prop = MakeAtom(dev_props->propname, strlen(dev_props->propname),
+                TRUE);
+
+        atoms = xcalloc(dev_props->nitems, sizeof(Atom));
+
+        for (i = 0; i < dev_props->nitems; i++)
+        {
+            atoms[i] = MakeAtom(dev_props->values[i],
+                                  strlen(dev_props->values[i]), TRUE);
+            xfree(dev_props->values[i]);
+        }
+
+        XIChangeDeviceProperty(dev, prop, XA_ATOM, 32, PropModeReplace,
+                               dev_props->nitems, atoms, FALSE);
+
+        xfree(dev_props->values);
+        xfree(atoms);
+        dev_props = next;
+    }
+
     for (; dev; dev = dev->next){
         if (dev->config_info)
             xfree(dev->config_info);
-- 
1.6.0.6




More information about the xorg mailing list