diff options
author | Hans de Goede <hdegoede@redhat.com> | 2015-04-13 11:15:00 +0200 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-05-03 14:34:52 -0400 |
commit | f0983247a5e8c50fc2d28349ff0ee71b95ceb74e (patch) | |
tree | 92caabeeb4a0ae3c7c18a9e19c96374152f388c9 | |
parent | 94599694d96307c4ba6000c159b264b12562ff7f (diff) |
udev: input_id: Make test_pointer / test_keys return if they've found anything
Make test_pointer / test_keys return a boolean indicating whether or not
they've set any properties on the device.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | src/udev/udev-builtin-input_id.c | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 1e94b0939a..3f3e78557b 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -126,7 +126,7 @@ static void get_cap_mask(struct udev_device *dev, } /* pointer devices */ -static void test_pointers(struct udev_device *dev, +static bool test_pointers(struct udev_device *dev, const unsigned long* bitmask_ev, const unsigned long* bitmask_abs, const unsigned long* bitmask_key, @@ -135,77 +135,93 @@ static void test_pointers(struct udev_device *dev, bool test) { int is_mouse = 0; int is_touchpad = 0; + bool ret = false; if (test_bit(INPUT_PROP_ACCELEROMETER, bitmask_props)) { udev_builtin_add_property(dev, test, "ID_INPUT_ACCELEROMETER", "1"); - return; + return true; } if (!test_bit(EV_KEY, bitmask_ev)) { if (test_bit(EV_ABS, bitmask_ev) && test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs) && - test_bit(ABS_Z, bitmask_abs)) + test_bit(ABS_Z, bitmask_abs)) { udev_builtin_add_property(dev, test, "ID_INPUT_ACCELEROMETER", "1"); - return; + ret = true; + } + return ret; } if (test_bit(EV_ABS, bitmask_ev) && test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) { - if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) + if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) { udev_builtin_add_property(dev, test, "ID_INPUT_TABLET", "1"); - else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) + ret = true; + } else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) { is_touchpad = 1; - else if (test_bit(BTN_MOUSE, bitmask_key)) + } else if (test_bit(BTN_MOUSE, bitmask_key)) { /* This path is taken by VMware's USB mouse, which has * absolute axes, but no touch/pressure button. */ is_mouse = 1; - else if (test_bit(BTN_TOUCH, bitmask_key)) + } else if (test_bit(BTN_TOUCH, bitmask_key)) { udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHSCREEN", "1"); + ret = true; /* joysticks don't necessarily have to have buttons; e. g. * rudders/pedals are joystick-like, but buttonless; they have * other fancy axes */ - else if (test_bit(BTN_TRIGGER, bitmask_key) || - test_bit(BTN_A, bitmask_key) || - test_bit(BTN_1, bitmask_key) || - test_bit(ABS_RX, bitmask_abs) || - test_bit(ABS_RY, bitmask_abs) || - test_bit(ABS_RZ, bitmask_abs) || - test_bit(ABS_THROTTLE, bitmask_abs) || - test_bit(ABS_RUDDER, bitmask_abs) || - test_bit(ABS_WHEEL, bitmask_abs) || - test_bit(ABS_GAS, bitmask_abs) || - test_bit(ABS_BRAKE, bitmask_abs)) + } else if (test_bit(BTN_TRIGGER, bitmask_key) || + test_bit(BTN_A, bitmask_key) || + test_bit(BTN_1, bitmask_key) || + test_bit(ABS_RX, bitmask_abs) || + test_bit(ABS_RY, bitmask_abs) || + test_bit(ABS_RZ, bitmask_abs) || + test_bit(ABS_THROTTLE, bitmask_abs) || + test_bit(ABS_RUDDER, bitmask_abs) || + test_bit(ABS_WHEEL, bitmask_abs) || + test_bit(ABS_GAS, bitmask_abs) || + test_bit(ABS_BRAKE, bitmask_abs)) { udev_builtin_add_property(dev, test, "ID_INPUT_JOYSTICK", "1"); + ret = true; + } } - if (test_bit(INPUT_PROP_POINTING_STICK, bitmask_props)) + if (test_bit(INPUT_PROP_POINTING_STICK, bitmask_props)) { udev_builtin_add_property(dev, test, "ID_INPUT_POINTINGSTICK", "1"); + ret = true; + } if (test_bit(EV_REL, bitmask_ev) && test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) && test_bit(BTN_MOUSE, bitmask_key)) is_mouse = 1; - if (is_mouse) + if (is_mouse) { udev_builtin_add_property(dev, test, "ID_INPUT_MOUSE", "1"); - if (is_touchpad) + ret = true; + } + if (is_touchpad) { udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHPAD", "1"); + ret = true; + } + + return ret; } /* key like devices */ -static void test_key(struct udev_device *dev, +static bool test_key(struct udev_device *dev, const unsigned long* bitmask_ev, const unsigned long* bitmask_key, bool test) { unsigned i; unsigned long found; unsigned long mask; + bool ret = false; /* do we have any KEY_* capability? */ if (!test_bit(EV_KEY, bitmask_ev)) { log_debug("test_key: no EV_KEY capability"); - return; + return false; } /* only consider KEY_* here, not BTN_* */ @@ -225,14 +241,20 @@ static void test_key(struct udev_device *dev, } } - if (found > 0) + if (found > 0) { udev_builtin_add_property(dev, test, "ID_INPUT_KEY", "1"); + ret = true; + } /* the first 32 bits are ESC, numbers, and Q to D; if we have all of * those, consider it a full keyboard; do not test KEY_RESERVED, though */ mask = 0xFFFFFFFE; - if ((bitmask_key[0] & mask) == mask) + if ((bitmask_key[0] & mask) == mask) { udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD", "1"); + ret = true; + } + + return ret; } static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], bool test) { |