summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2015-03-20 13:17:20 +1000
committerAnthony G. Basile <blueness@gentoo.org>2015-04-12 12:26:55 -0400
commitca9aee0fac701be837d50a56d575cc10a39c5bc9 (patch)
treebea2cab7835b5c7ba0690760506b8873ed361941 /src/udev
parent13d57d7917499fab4216323ed84dd0c9da7d63b4 (diff)
udev: builtin-keyboard: move actual key mapping to a helper function
No changes in the mapping, but previously we opened the device only on successful parsing. Now we open the mapping as soon as we have a value that looks interesting. Since errors are supposed to be the exception, not the rule, this is probably fine. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-builtin-keyboard.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c
index 515edd45ce..f33401790c 100644
--- a/src/udev/udev-builtin-keyboard.c
+++ b/src/udev/udev-builtin-keyboard.c
@@ -66,12 +66,41 @@ static int install_force_release(struct udev_device *dev, const unsigned *releas
return ret;
}
-static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], bool test) {
- struct udev_list_entry *entry;
+static void map_keycode(int fd, const char *devnode, int scancode, const char *keycode)
+{
struct {
unsigned scan;
unsigned key;
} map;
+ char *endptr;
+ const struct key *k;
+ unsigned keycode_num;
+
+ /* translate identifier to key code */
+ k = keyboard_lookup_key(keycode, strlen(keycode));
+ if (k) {
+ keycode_num = k->id;
+ } else {
+ /* check if it's a numeric code already */
+ keycode_num = strtoul(keycode, &endptr, 0);
+ if (endptr[0] !='\0') {
+ log_error("Error, unknown key identifier '%s'", keycode);
+ return;
+ }
+ }
+
+ map.scan = scancode;
+ map.key = keycode_num;
+
+ log_debug("keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
+ map.scan, map.scan, map.key, map.key);
+
+ if (ioctl(fd, EVIOCSKEYCODE, &map) < 0)
+ log_error_errno(errno, "Error calling EVIOCSKEYCODE on device node '%s' (scan code 0x%x, key code %d): %m", devnode, map.scan, map.key);
+}
+
+static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], bool test) {
+ struct udev_list_entry *entry;
unsigned release[1024];
unsigned release_count = 0;
_cleanup_close_ int fd = -1;
@@ -85,10 +114,9 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev)) {
const char *key;
- unsigned scancode, keycode_num;
char *endptr;
+ unsigned scancode;
const char *keycode;
- const struct key *k;
key = udev_list_entry_get_name(entry);
if (!startswith(key, "KEYBOARD_KEY_"))
@@ -115,19 +143,6 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
continue;
}
- /* translate identifier to key code */
- k = keyboard_lookup_key(keycode, strlen(keycode));
- if (k) {
- keycode_num = k->id;
- } else {
- /* check if it's a numeric code already */
- keycode_num = strtoul(keycode, &endptr, 0);
- if (endptr[0] !='\0') {
- log_error("Error, unknown key identifier '%s'", keycode);
- continue;
- }
- }
-
if (fd == -1) {
fd = open(node, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
@@ -136,14 +151,7 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
}
}
- map.scan = scancode;
- map.key = keycode_num;
-
- log_debug("keyboard: mapping scan code %d (0x%x) to key code %d (0x%x)",
- map.scan, map.scan, map.key, map.key);
-
- if (ioctl(fd, EVIOCSKEYCODE, &map) < 0)
- log_error_errno(errno, "Error calling EVIOCSKEYCODE on device node '%s' (scan code 0x%x, key code %d): %m", node, map.scan, map.key);
+ map_keycode(fd, node, scancode, keycode);
}
/* install list of force-release codes */