[PATCH 09/11] xfree86: Match devices based on PnP ID

Dan Nicholson dbn.lists at gmail.com
Thu May 20 07:09:11 PDT 2010


Serial input devices lack properties such as product or vendor name. This
makes matching InputClass sections difficult. Add a MatchPnPID entry to
test against the PnP ID of the device. The entry supports a shell pattern
match on platforms that support fnmatch(3). For example:

	MatchPnPID "WACf*"

Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
---
 config/hal.c                         |    9 ++++++++-
 config/udev.c                        |    3 +++
 hw/xfree86/common/xf86Xinput.c       |    4 ++++
 hw/xfree86/doc/man/xorg.conf.man.pre |    6 ++++++
 hw/xfree86/parser/InputClass.c       |    6 ++++++
 hw/xfree86/parser/xf86Parser.h       |    1 +
 hw/xfree86/parser/xf86tokens.h       |    1 +
 include/input.h                      |    1 +
 8 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index 553c999..64e6967 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -130,7 +130,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
 {
     char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL;
     char **tags = NULL;
-    char *vendor = NULL, *hal_tags;
+    char *vendor = NULL, *hal_tags, *parent, *pnp_id = NULL;
     InputOption *options = NULL, *tmpo = NULL;
     InputAttributes attrs = {0};
     DeviceIntPtr dev = NULL;
@@ -184,6 +184,12 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     if (libhal_device_query_capability(hal_ctx, udi, "input.touchscreen", NULL))
         attrs.flags |= ATTR_TOUCHSCREEN;
 
+    parent = get_prop_string(hal_ctx, udi, "info.parent");
+    if (parent) {
+        attrs.pnp_id = pnp_id = get_prop_string(hal_ctx, parent, "pnp.id");
+        free(parent);
+    }
+
     options = calloc(sizeof(*options), 1);
     if (!options){
         LogMessage(X_ERROR, "config/hal: couldn't allocate space for input options!\n");
@@ -395,6 +401,7 @@ unwind:
     }
 
     free(vendor);
+    free(pnp_id);
     if (tags) {
         char **tag = tags;
         while (*tag) {
diff --git a/config/udev.c b/config/udev.c
index 0f5cf11..274e2a0 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -100,6 +100,9 @@ device_added(struct udev_device *udev_device)
             name = udev_device_get_property_value(parent, "NAME");
             LOG_PROPERTY(ppath, "NAME", name);
         }
+
+        attrs.pnp_id = udev_device_get_sysattr_value(parent, "id");
+        LOG_SYSATTR(ppath, "id", attrs.pnp_id);
     }
     if (!name)
         name = "(unnamed)";
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 0304c55..72c9bbf 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -597,6 +597,10 @@ InputClassMatches(XF86ConfInputClassPtr iclass, InputAttributes *attrs)
     if (!MatchAttrToken(HostOS(), iclass->match_os, strcasecmp))
         return FALSE;
 
+    /* MatchPnPID pattern */
+    if (!MatchAttrToken(attrs->pnp_id, iclass->match_pnpid, MatchPattern))
+        return FALSE;
+
     /*
      * MatchTag string
      * See if any of the device's tags match any of the MatchTag tokens.
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 7b66b7e..e74c78b 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -1095,6 +1095,12 @@ string. This entry is only supported on platforms providing the
 system call. Multiple operating systems can be matched by separating arguments
 with a '|' character.
 .TP 7
+.BI "MatchPnPID \*q" matchpnp \*q
+The device's Plug and Play (PnP) ID can be checked against the
+.RI \*q matchpnp \*q
+shell wildcard pattern. Multiple IDs can be matched by separating arguments
+with a '|' character.
+.TP 7
 .BI "MatchTag \*q" matchtag \*q
 This entry can be used to check if tags assigned by the config backend
 matches the
diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
index 0332c31..c1a785a 100644
--- a/hw/xfree86/parser/InputClass.c
+++ b/hw/xfree86/parser/InputClass.c
@@ -48,6 +48,7 @@ xf86ConfigSymTabRec InputClassTab[] =
     {MATCH_VENDOR, "matchvendor"},
     {MATCH_DEVICE_PATH, "matchdevicepath"},
     {MATCH_OS, "matchos"},
+    {MATCH_PNPID, "matchpnpid"},
     {MATCH_TAG, "matchtag"},
     {MATCH_IS_KEYBOARD, "matchiskeyboard"},
     {MATCH_IS_POINTER, "matchispointer"},
@@ -114,6 +115,11 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchOS");
             ptr->match_os = xstrtokenize(val.str, TOKEN_SEP);
             break;
+        case MATCH_PNPID:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchPnPID");
+            ptr->match_pnpid = xstrtokenize(val.str, TOKEN_SEP);
+            break;
         case MATCH_TAG:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchTag");
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 3623ca1..87fc31c 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -347,6 +347,7 @@ typedef struct
 	char **match_vendor;
 	char **match_device;
 	char **match_os;
+	char **match_pnpid;
 	char **match_tag;
 	xf86TriState is_keyboard;
 	xf86TriState is_pointer;
diff --git a/hw/xfree86/parser/xf86tokens.h b/hw/xfree86/parser/xf86tokens.h
index fd13d6d..aa33935 100644
--- a/hw/xfree86/parser/xf86tokens.h
+++ b/hw/xfree86/parser/xf86tokens.h
@@ -280,6 +280,7 @@ typedef enum {
     MATCH_VENDOR,
     MATCH_DEVICE_PATH,
     MATCH_OS,
+    MATCH_PNPID,
     MATCH_TAG,
     MATCH_IS_KEYBOARD,
     MATCH_IS_POINTER,
diff --git a/include/input.h b/include/input.h
index e36577d..9991624 100644
--- a/include/input.h
+++ b/include/input.h
@@ -215,6 +215,7 @@ typedef struct _InputAttributes {
     const char          *product;
     const char          *vendor;
     const char          *device;
+    const char          *pnp_id;
     const char  * const *tags; /* null-terminated */
     uint32_t            flags;
 } InputAttributes;
-- 
1.6.6.1



More information about the xorg-devel mailing list