diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-18 10:10:49 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-18 10:11:43 +1000 |
commit | 8fecb19147ca12980f36a7936341ab432c67948e (patch) | |
tree | b49a155632cc50dee49e058279f5ee260e96d542 | |
parent | b5f0536a4f9370f52355a5c7760d2e3f14d8c7c1 (diff) | |
download | libinput-8fecb19147ca12980f36a7936341ab432c67948e.tar.gz |
Use bit(foo) instead of (1 << foo)
Translates to the same thing, but the bit() helper is nicer and less
likely to be typoed.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/evdev-middle-button.c | 8 | ||||
-rw-r--r-- | src/evdev-mt-touchpad-buttons.c | 2 | ||||
-rw-r--r-- | src/evdev-mt-touchpad-tap.c | 6 | ||||
-rw-r--r-- | src/evdev-mt-touchpad.c | 8 | ||||
-rw-r--r-- | src/evdev-tablet-pad-leds.c | 4 | ||||
-rw-r--r-- | src/libinput-private.h | 2 | ||||
-rw-r--r-- | src/libinput.c | 8 | ||||
-rw-r--r-- | src/timer.h | 2 | ||||
-rw-r--r-- | test/test-device.c | 2 | ||||
-rw-r--r-- | tools/libinput-record.c | 5 |
10 files changed, 24 insertions, 23 deletions
diff --git a/src/evdev-middle-button.c b/src/evdev-middle-button.c index 8d5dd199..e5142a25 100644 --- a/src/evdev-middle-button.c +++ b/src/evdev-middle-button.c @@ -583,7 +583,7 @@ evdev_middlebutton_filter_button(struct evdev_device *device, enum evdev_middlebutton_event event; bool is_press = state == LIBINPUT_BUTTON_STATE_PRESSED; int rc; - unsigned int bit = (button - BTN_LEFT); + unsigned int btnbit = (button - BTN_LEFT); uint32_t old_mask = 0; if (!device->middlebutton.enabled) @@ -612,7 +612,7 @@ evdev_middlebutton_filter_button(struct evdev_device *device, } if (button < BTN_LEFT || - bit >= sizeof(device->middlebutton.button_mask) * 8) { + btnbit >= sizeof(device->middlebutton.button_mask) * 8) { evdev_log_bug_libinput(device, "Button mask too small for %s\n", libevdev_event_code_get_name(EV_KEY, @@ -624,9 +624,9 @@ evdev_middlebutton_filter_button(struct evdev_device *device, old_mask = device->middlebutton.button_mask; if (is_press) - device->middlebutton.button_mask |= 1 << bit; + device->middlebutton.button_mask |= bit(btnbit); else - device->middlebutton.button_mask &= ~(1 << bit); + device->middlebutton.button_mask &= ~bit(btnbit); if (old_mask != device->middlebutton.button_mask && device->middlebutton.button_mask == 0) { diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c index 8426b133..3ebb5f7a 100644 --- a/src/evdev-mt-touchpad-buttons.c +++ b/src/evdev-mt-touchpad-buttons.c @@ -592,7 +592,7 @@ tp_process_button(struct tp_dispatch *tp, const struct input_event *e, uint64_t time) { - uint32_t mask = 1 << (e->code - BTN_LEFT); + uint32_t mask = bit(e->code - BTN_LEFT); /* Ignore other buttons on clickpads */ if (tp->buttons.is_clickpad && e->code != BTN_LEFT) { diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 530f71a8..42d91297 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -139,9 +139,9 @@ tp_tap_notify(struct tp_dispatch *tp, button = button_map[tp->tap.map][nfingers - 1]; if (state == LIBINPUT_BUTTON_STATE_PRESSED) - tp->tap.buttons_pressed |= (1 << nfingers); + tp->tap.buttons_pressed |= bit(nfingers); else - tp->tap.buttons_pressed &= ~(1 << nfingers); + tp->tap.buttons_pressed &= ~bit(nfingers); evdev_pointer_notify_button(tp->device, time, @@ -1603,7 +1603,7 @@ tp_release_all_taps(struct tp_dispatch *tp, uint64_t now) int i; for (i = 1; i <= 3; i++) { - if (tp->tap.buttons_pressed & (1 << i)) + if (tp->tap.buttons_pressed & bit(i)) tp_tap_notify(tp, now, i, LIBINPUT_BUTTON_STATE_RELEASED); } diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 6c97bce1..c0fc5d93 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -39,7 +39,7 @@ #define DEFAULT_TRACKPOINT_EVENT_TIMEOUT ms2us(40) #define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1 ms2us(200) #define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2 ms2us(500) -#define FAKE_FINGER_OVERFLOW (1 << 7) +#define FAKE_FINGER_OVERFLOW bit(7) #define THUMB_IGNORE_SPEED_THRESHOLD 20 /* mm/s */ enum notify { @@ -198,7 +198,7 @@ tp_detect_wobbling(struct tp_dispatch *tp, if (dx > 0) { /* right move */ static const char r_l_r = 0x5; /* {Right, Left, Right} */ - t->hysteresis.x_motion_history |= (1 << 2); + t->hysteresis.x_motion_history |= bit(2); if (t->hysteresis.x_motion_history == r_l_r) { tp->hysteresis.enabled = true; evdev_log_debug(tp->device, @@ -303,10 +303,10 @@ tp_fake_finger_set(struct tp_dispatch *tp, if (is_press) { tp->fake_touches &= ~FAKE_FINGER_OVERFLOW; - tp->fake_touches |= 1 << shift; + tp->fake_touches |= bit(shift); } else { - tp->fake_touches &= ~(0x1 << shift); + tp->fake_touches &= ~bit(shift); } } diff --git a/src/evdev-tablet-pad-leds.c b/src/evdev-tablet-pad-leds.c index 9d81ec7a..8f5131f2 100644 --- a/src/evdev-tablet-pad-leds.c +++ b/src/evdev-tablet-pad-leds.c @@ -412,7 +412,7 @@ pad_init_mode_buttons(struct pad_dispatch *pad, return 1; } - group->button_mask |= 1 << i; + group->button_mask |= bit(i); if (flags & WACOM_BUTTON_MODESWITCH) { struct pad_mode_toggle_button *b; @@ -423,7 +423,7 @@ pad_init_mode_buttons(struct pad_dispatch *pad, return 1; g = (struct pad_led_group*)group; list_insert(&g->toggle_button_list, &b->link); - group->toggle_button_mask |= 1 << i; + group->toggle_button_mask |= bit(i); } } diff --git a/src/libinput-private.h b/src/libinput-private.h index d5845420..051e828b 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -865,7 +865,7 @@ xy_get_direction(double x, double y) d1 = (int)(r + 0.9) % 8; d2 = (int)(r + 0.1) % 8; - dir = (1 << d1) | (1 << d2); + dir = bit(d1) | bit(d2); } return dir; diff --git a/src/libinput.c b/src/libinput.c index f985b79f..4bb0bf28 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -3427,7 +3427,7 @@ libinput_tablet_pad_mode_group_has_button(struct libinput_tablet_pad_mode_group libinput_device_tablet_pad_get_num_buttons(group->device)) return 0; - return !!(group->button_mask & (1 << button)); + return !!(group->button_mask & bit(button)); } LIBINPUT_EXPORT int @@ -3438,7 +3438,7 @@ libinput_tablet_pad_mode_group_has_ring(struct libinput_tablet_pad_mode_group *g libinput_device_tablet_pad_get_num_rings(group->device)) return 0; - return !!(group->ring_mask & (1 << ring)); + return !!(group->ring_mask & bit(ring)); } LIBINPUT_EXPORT int @@ -3449,7 +3449,7 @@ libinput_tablet_pad_mode_group_has_strip(struct libinput_tablet_pad_mode_group * libinput_device_tablet_pad_get_num_strips(group->device)) return 0; - return !!(group->strip_mask & (1 << strip)); + return !!(group->strip_mask & bit(strip)); } LIBINPUT_EXPORT int @@ -3460,7 +3460,7 @@ libinput_tablet_pad_mode_group_button_is_toggle(struct libinput_tablet_pad_mode_ libinput_device_tablet_pad_get_num_buttons(group->device)) return 0; - return !!(group->toggle_button_mask & (1 << button)); + return !!(group->toggle_button_mask & bit(button)); } LIBINPUT_EXPORT struct libinput_tablet_pad_mode_group * diff --git a/src/timer.h b/src/timer.h index 828f506c..3cc191e2 100644 --- a/src/timer.h +++ b/src/timer.h @@ -54,7 +54,7 @@ libinput_timer_set(struct libinput_timer *timer, uint64_t expire); enum timer_flags { TIMER_FLAG_NONE = 0, - TIMER_FLAG_ALLOW_NEGATIVE = (1 << 0), + TIMER_FLAG_ALLOW_NEGATIVE = bit(0), }; void diff --git a/test/test-device.c b/test/test-device.c index 2ff0fc9d..8c1679d5 100644 --- a/test/test-device.c +++ b/test/test-device.c @@ -56,7 +56,7 @@ START_TEST(device_sendevents_config_invalid) device = dev->libinput_device; status = libinput_device_config_send_events_set_mode(device, - LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | (1 << 4)); + LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | bit(4)); ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); } END_TEST diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 8ed14b5d..7adebdf2 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -48,6 +48,7 @@ #include "libinput-git-version.h" #include "shared.h" #include "builddir.h" +#include "util-bits.h" #include "util-list.h" #include "util-time.h" #include "util-input-event.h" @@ -391,9 +392,9 @@ handle_evdev_frame(struct record_device *d) assert(slot < sizeof(d->touch.slot_state) * 8); if (e.value != -1) - d->touch.slot_state |= 1 << slot; + d->touch.slot_state |= bit(slot); else - d->touch.slot_state &= ~(1 << slot); + d->touch.slot_state &= ~bit(slot); } if (e.type == EV_SYN && e.code == SYN_REPORT) |