[systemd-devel] [PATCH v2 1/2] input_id: Make test_pointer / test_keys return if they've found anything

Hans de Goede hdegoede at redhat.com
Mon Apr 13 06:08:53 PDT 2015


Hi,

On 13-04-15 14:41, Zbigniew Jędrzejewski-Szmek wrote:
> On Mon, Apr 13, 2015 at 11:15:00AM +0200, Hans de Goede wrote:
>> Make test_pointer / test_keys return a boolean indicating whether or not
>> they've set any properties on the device.
>>
>> While touching allmost all test_bit() using lines anyways also remove
>> the extra space between the function name and the '(' (coding style issue).
>>
>> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
>> ---
>>   src/udev/udev-builtin-input_id.c | 98 ++++++++++++++++++++++++----------------
>>   1 file changed, 60 insertions(+), 38 deletions(-)
>>
>> diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c
>> index ecfc447..2c8a9ee 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,
>                              ^
> Those spaces after function name declaration should go too.

That seems like something for a separate commit.

> And
> the white-space changes should probably be a separate commit becuase
> now it's hard to see what is going on ;)

Almost all changed lines are changed because they must be changed
(adding { or }, changing indentation), only 5 or so changed lines
are purely removing the extra space between test_bit and '(' which
is exactly why I squashed in those changes.

Regards,

Hans


>
> Zbyszek
>
>> @@ -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)) {
>> +        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))
>> +        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)) {
>>                           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(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)) {
>>                           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))
>> +        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)) {
>> +        if (!test_bit(EV_KEY, bitmask_ev)) {
>>                   log_debug("test_key: no EV_KEY capability");
>> -                return;
>> +                return false;
>>           }
>>
>>           /* only consider KEY_* here, not BTN_* */
>> @@ -217,7 +233,7 @@ static void test_key (struct udev_device *dev,
>>           /* If there are no keys in the lower block, check the higher block */
>>           if (!found) {
>>                   for (i = KEY_OK; i < BTN_TRIGGER_HAPPY; ++i) {
>> -                        if (test_bit (i, bitmask_key)) {
>> +                        if (test_bit(i, bitmask_key)) {
>>                                   log_debug("test_key: Found key %x in high block", i);
>>                                   found = 1;
>>                                   break;
>> @@ -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) {
>> --
>> 2.3.4
>>
>> _______________________________________________
>> systemd-devel mailing list
>> systemd-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list