aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/config/udev.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/config/udev.c')
-rw-r--r--xorg-server/config/udev.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/xorg-server/config/udev.c b/xorg-server/config/udev.c
index 304ee2c93..bf463168e 100644
--- a/xorg-server/config/udev.c
+++ b/xorg-server/config/udev.c
@@ -28,6 +28,7 @@
#endif
#include <libudev.h>
+#include <ctype.h>
#include "input.h"
#include "inputstr.h"
@@ -37,6 +38,17 @@
#define UDEV_XKB_PROP_KEY "xkb"
+#define LOG_PROPERTY(path, prop, val) \
+ LogMessageVerb(X_INFO, 10, \
+ "config/udev: getting property %s on %s " \
+ "returned \"%s\"\n", \
+ (prop), (path), (val) ? (val) : "(null)")
+#define LOG_SYSATTR(path, attr, val) \
+ LogMessageVerb(X_INFO, 10, \
+ "config/udev: getting attribute %s on %s " \
+ "returned \"%s\"\n", \
+ (attr), (path), (val) ? (val) : "(null)")
+
static struct udev_monitor *udev_monitor;
static void
@@ -45,6 +57,8 @@ device_added(struct udev_device *udev_device)
const char *path, *name = NULL;
char *config_info = NULL;
const char *syspath;
+ const char *tags_prop;
+ const char *usb_vendor = NULL, *usb_model = NULL;
const char *key, *value, *tmp;
InputOption *options = NULL, *tmpo;
InputAttributes attrs = {};
@@ -60,8 +74,13 @@ device_added(struct udev_device *udev_device)
if (!path || !syspath)
return;
- if (!udev_device_get_property_value(udev_device, "ID_INPUT"))
+ if (!udev_device_get_property_value(udev_device, "ID_INPUT")) {
+ LogMessageVerb(X_INFO, 10,
+ "config/udev: ignoring device %s without "
+ "property ID_INPUT set\n",
+ path);
return;
+ }
options = calloc(sizeof(*options), 1);
if (!options)
@@ -74,9 +93,17 @@ device_added(struct udev_device *udev_device)
parent = udev_device_get_parent(udev_device);
if (parent) {
+ const char *ppath = udev_device_get_devnode(parent);
+
name = udev_device_get_sysattr_value(parent, "name");
- if (!name)
+ LOG_SYSATTR(ppath, "name", name);
+ if (!name) {
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)";
@@ -87,7 +114,10 @@ device_added(struct udev_device *udev_device)
add_option(&options, "path", path);
add_option(&options, "device", path);
attrs.device = path;
- attrs.tags = xstrtokenize(udev_device_get_property_value(udev_device, "ID_INPUT.tags"), ",");
+
+ tags_prop = udev_device_get_property_value(udev_device, "ID_INPUT.tags");
+ LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop);
+ attrs.tags = xstrtokenize(tags_prop, ",");
config_info = Xprintf("udev:%s", syspath);
if (!config_info)
@@ -107,6 +137,7 @@ device_added(struct udev_device *udev_device)
value = udev_list_entry_get_value(entry);
if (!strncasecmp(key, UDEV_XKB_PROP_KEY,
sizeof(UDEV_XKB_PROP_KEY) - 1)) {
+ LOG_PROPERTY(path, key, value);
tmp = key + sizeof(UDEV_XKB_PROP_KEY) - 1;
if (!strcasecmp(tmp, "rules"))
add_option(&options, "xkb_rules", value);
@@ -119,21 +150,45 @@ device_added(struct udev_device *udev_device)
else if (!strcasecmp(tmp, "options"))
add_option(&options, "xkb_options", value);
} else if (!strcmp(key, "ID_VENDOR")) {
+ LOG_PROPERTY(path, key, value);
attrs.vendor = value;
+ } else if (!strcmp(key, "ID_VENDOR_ID")) {
+ LOG_PROPERTY(path, key, value);
+ usb_vendor = value;
+ } else if (!strcmp(key, "ID_VENDOR_MODEL")) {
+ LOG_PROPERTY(path, key, value);
+ usb_model = value;
} else if (!strcmp(key, "ID_INPUT_KEY")) {
+ LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_KEYBOARD;
} else if (!strcmp(key, "ID_INPUT_MOUSE")) {
+ LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_POINTER;
} else if (!strcmp(key, "ID_INPUT_JOYSTICK")) {
+ LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_JOYSTICK;
} else if (!strcmp(key, "ID_INPUT_TABLET")) {
+ LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_TABLET;
} else if (!strcmp(key, "ID_INPUT_TOUCHPAD")) {
+ LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_TOUCHPAD;
} else if (!strcmp(key, "ID_INPUT_TOUCHSCREEN")) {
+ LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_TOUCHSCREEN;
}
}
+
+ /* construct USB ID in lowercase hex - "0000:ffff" */
+ if (usb_vendor && usb_model) {
+ attrs.usb_id = Xprintf("%s:%s", usb_vendor, usb_model);
+ if (attrs.usb_id) {
+ char *cur;
+ for (cur = attrs.usb_id; *cur; cur++)
+ *cur = tolower(*cur);
+ }
+ }
+
LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
name, path);
rc = NewInputDeviceRequest(options, &attrs, &dev);
@@ -154,6 +209,7 @@ device_added(struct udev_device *udev_device)
free(tmpo);
}
+ free(attrs.usb_id);
if (attrs.tags) {
char **tag = attrs.tags;
while (*tag) {