From 467752047ebfa2f82195f6bf80956483bd832100 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 27 Aug 2020 01:17:24 -0700 Subject: [PATCH] [clang-tidy] do not use else after return Found with readability-else-after-return Signed-off-by: Rosen Penev --- src/evdev-mt-touchpad-buttons.c | 6 ++-- src/evdev-mt-touchpad-gestures.c | 10 +++--- src/evdev-mt-touchpad.c | 32 +++++++++++------ src/evdev.c | 12 ++++--- src/libinput.c | 59 +++++++++++++++++--------------- src/udev-seat.c | 4 ++- src/util-ratelimit.c | 4 ++- tools/libinput-list-devices.c | 38 ++++++++++---------- tools/libinput-record.c | 9 +++-- tools/shared.c | 9 +++-- 10 files changed, 105 insertions(+), 78 deletions(-) diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c index 2a6092bc..6ce35218 100644 --- a/src/evdev-mt-touchpad-buttons.c +++ b/src/evdev-mt-touchpad-buttons.c @@ -794,7 +794,8 @@ tp_click_get_default_method(struct tp_dispatch *tp) if (!tp->buttons.is_clickpad) return LIBINPUT_CONFIG_CLICK_METHOD_NONE; - else if (evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD)) + + if (evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD)) return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; return LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; @@ -1286,8 +1287,7 @@ tp_post_button_events(struct tp_dispatch *tp, uint64_t time) if (tp->buttons.is_clickpad || tp->device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON) return tp_post_clickpadbutton_buttons(tp, time); - else - return tp_post_physical_buttons(tp, time); + return tp_post_physical_buttons(tp, time); } bool diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index 6c63183b..22392f79 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -383,8 +383,7 @@ tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) if (!tp->gesture.enabled) { if (ntouches == 2) return GESTURE_STATE_SCROLL; - else - return GESTURE_STATE_NONE; + return GESTURE_STATE_NONE; } first = touches[0]; @@ -525,9 +524,8 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time) if (tp->gesture.finger_count == 2) { tp_gesture_set_scroll_buildup(tp); return GESTURE_STATE_SCROLL; - } else { - return GESTURE_STATE_SWIPE; } + return GESTURE_STATE_SWIPE; } /* If one touch exceeds the max_move threshold while the other has not @@ -589,7 +587,9 @@ tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time) if (tp->gesture.finger_count == 2) { tp_gesture_set_scroll_buildup(tp); return GESTURE_STATE_SCROLL; - } else if (tp->gesture.enabled) { + } + + if (tp->gesture.enabled) { return GESTURE_STATE_SWIPE; } } diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index c44aeaf0..d8db704b 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -256,8 +256,9 @@ tp_fake_finger_count(struct tp_dispatch *tp) if (tp->fake_touches & FAKE_FINGER_OVERFLOW) return FAKE_FINGER_OVERFLOW; - else /* don't count BTN_TOUCH */ - return ffs(tp->fake_touches >> 1); + + /* don't count BTN_TOUCH */ + return ffs(tp->fake_touches >> 1); } static inline bool @@ -898,7 +899,9 @@ tp_palm_detect_dwt_triggered(struct tp_dispatch *tp, t->palm.state = PALM_TYPING; t->palm.first = t->point; return true; - } else if (!tp->dwt.keyboard_active && + } + + if (!tp->dwt.keyboard_active && t->state == TOUCH_UPDATE && t->palm.state == PALM_TYPING) { /* If a touch has started before the first or after the last @@ -932,7 +935,9 @@ tp_palm_detect_trackpoint_triggered(struct tp_dispatch *tp, tp->palm.trackpoint_active) { t->palm.state = PALM_TRACKPOINT; return true; - } else if (t->palm.state == PALM_TRACKPOINT && + } + + if (t->palm.state == PALM_TRACKPOINT && t->state == TOUCH_UPDATE && !tp->palm.trackpoint_active) { @@ -1074,7 +1079,9 @@ tp_palm_detect_edge(struct tp_dispatch *tp, t->index); } return false; - } else if (tp_palm_detect_multifinger(tp, t, time)) { + } + + if (tp_palm_detect_multifinger(tp, t, time)) { return false; } @@ -2327,7 +2334,8 @@ tp_want_dwt(struct evdev_device *touchpad, considered a happy couple */ if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD) return vendor_tp == vendor_kbd && product_tp == product_kbd; - else if (keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) + + if (keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) return true; /* keyboard is not tagged as internal keyboard and it's not part of @@ -2684,14 +2692,16 @@ evdev_tag_touchpad(struct evdev_device *device, if (streq(prop, "internal")) { evdev_tag_touchpad_internal(device); return; - } else if (streq(prop, "external")) { + } + + if (streq(prop, "external")) { evdev_tag_touchpad_external(device); return; - } else { - evdev_log_info(device, - "tagged with unknown value %s\n", - prop); } + + evdev_log_info(device, + "tagged with unknown value %s\n", + prop); } /* The hwdb is the authority on integration, these heuristics are diff --git a/src/evdev.c b/src/evdev.c index 453c89a0..c3c02d2a 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -763,8 +763,8 @@ evdev_scroll_get_button_lock(struct libinput_device *device) if (evdev->scroll.lock_state == BUTTONSCROLL_LOCK_DISABLED) return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; - else - return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED; + + return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED; } static enum libinput_config_scroll_button_lock_state @@ -1806,7 +1806,9 @@ evdev_configure_device(struct evdev_device *device) evdev_log_info(device, "device is an accelerometer, ignoring\n"); return NULL; - } else if (udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER) { + } + + if (udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER) { evdev_disable_accelerometer_axes(device); } @@ -1853,7 +1855,9 @@ evdev_configure_device(struct evdev_device *device) evdev_log_info(device, "device is a tablet pad\n"); return dispatch; - } else if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) { + } + + if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) { dispatch = evdev_tablet_create(device); device->seat_caps |= EVDEV_DEVICE_TABLET; evdev_log_info(device, "device is a tablet\n"); diff --git a/src/libinput.c b/src/libinput.c index 7a535986..423f81c7 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2020,9 +2020,9 @@ libinput_seat_unref(struct libinput_seat *seat) if (seat->refcount == 0) { libinput_seat_destroy(seat); return NULL; - } else { - return seat; } + + return seat; } LIBINPUT_EXPORT void @@ -2086,9 +2086,9 @@ libinput_device_unref(struct libinput_device *device) if (device->refcount == 0) { libinput_device_destroy(device); return NULL; - } else { - return device; } + + return device; } LIBINPUT_EXPORT int @@ -3617,9 +3617,9 @@ libinput_device_group_unref(struct libinput_device_group *group) if (group->refcount == 0) { libinput_device_group_destroy(group); return NULL; - } else { - return group; } + + return group; } LIBINPUT_EXPORT void @@ -3854,8 +3854,9 @@ libinput_device_config_send_events_set_mode(struct libinput_device *device, if (device->config.sendevents) return device->config.sendevents->set_mode(device, mode); - else /* mode must be _ENABLED to get here */ - return LIBINPUT_CONFIG_STATUS_SUCCESS; + + /* mode must be _ENABLED to get here */ + return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT uint32_t @@ -3863,8 +3864,8 @@ libinput_device_config_send_events_get_mode(struct libinput_device *device) { if (device->config.sendevents) return device->config.sendevents->get_mode(device); - else - return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; + + return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; } LIBINPUT_EXPORT uint32_t @@ -4036,8 +4037,8 @@ libinput_device_config_click_get_methods(struct libinput_device *device) { if (device->config.click_method) return device->config.click_method->get_methods(device); - else - return 0; + + return 0; } LIBINPUT_EXPORT enum libinput_config_status @@ -4059,8 +4060,9 @@ libinput_device_config_click_set_method(struct libinput_device *device, if (device->config.click_method) return device->config.click_method->set_method(device, method); - else /* method must be _NONE to get here */ - return LIBINPUT_CONFIG_STATUS_SUCCESS; + + /* method must be _NONE to get here */ + return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT enum libinput_config_click_method @@ -4068,8 +4070,8 @@ libinput_device_config_click_get_method(struct libinput_device *device) { if (device->config.click_method) return device->config.click_method->get_method(device); - else - return LIBINPUT_CONFIG_CLICK_METHOD_NONE; + + return LIBINPUT_CONFIG_CLICK_METHOD_NONE; } LIBINPUT_EXPORT enum libinput_config_click_method @@ -4077,8 +4079,8 @@ libinput_device_config_click_get_default_method(struct libinput_device *device) { if (device->config.click_method) return device->config.click_method->get_default_method(device); - else - return LIBINPUT_CONFIG_CLICK_METHOD_NONE; + + return LIBINPUT_CONFIG_CLICK_METHOD_NONE; } LIBINPUT_EXPORT int @@ -4087,8 +4089,8 @@ libinput_device_config_middle_emulation_is_available( { if (device->config.middle_emulation) return device->config.middle_emulation->available(device); - else - return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; + + return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; } LIBINPUT_EXPORT enum libinput_config_status @@ -4140,8 +4142,8 @@ libinput_device_config_scroll_get_methods(struct libinput_device *device) { if (device->config.scroll_method) return device->config.scroll_method->get_methods(device); - else - return 0; + + return 0; } LIBINPUT_EXPORT enum libinput_config_status @@ -4164,8 +4166,9 @@ libinput_device_config_scroll_set_method(struct libinput_device *device, if (device->config.scroll_method) return device->config.scroll_method->set_method(device, method); - else /* method must be _NO_SCROLL to get here */ - return LIBINPUT_CONFIG_STATUS_SUCCESS; + + /* method must be _NO_SCROLL to get here */ + return LIBINPUT_CONFIG_STATUS_SUCCESS; } LIBINPUT_EXPORT enum libinput_config_scroll_method @@ -4173,8 +4176,8 @@ libinput_device_config_scroll_get_method(struct libinput_device *device) { if (device->config.scroll_method) return device->config.scroll_method->get_method(device); - else - return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; + + return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } LIBINPUT_EXPORT enum libinput_config_scroll_method @@ -4182,8 +4185,8 @@ libinput_device_config_scroll_get_default_method(struct libinput_device *device) { if (device->config.scroll_method) return device->config.scroll_method->get_default_method(device); - else - return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; + + return LIBINPUT_CONFIG_SCROLL_NO_SCROLL; } LIBINPUT_EXPORT enum libinput_config_status diff --git a/src/udev-seat.c b/src/udev-seat.c index de78929c..28b21b6e 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -128,7 +128,9 @@ device_added(struct udev_device *udev_device, sysname, devnode); return 0; - } else if (device == NULL) { + } + + if (device == NULL) { log_info(&input->base, "%-7s - failed to create input device '%s'\n", sysname, diff --git a/src/util-ratelimit.c b/src/util-ratelimit.c index a3943b1b..e765ebeb 100644 --- a/src/util-ratelimit.c +++ b/src/util-ratelimit.c @@ -69,7 +69,9 @@ ratelimit_test(struct ratelimit *r) r->begin = utime; r->num = 1; return RATELIMIT_PASS; - } else if (r->num < r->burst) { + } + + if (r->num < r->burst) { /* continue burst */ return (++r->num == r->burst) ? RATELIMIT_THRESHOLD : RATELIMIT_PASS; diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index a803e7b7..a0e5d334 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -44,8 +44,8 @@ tap_default(struct libinput_device *device) if (libinput_device_config_tap_get_default_enabled(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static const char * @@ -56,8 +56,8 @@ drag_default(struct libinput_device *device) if (libinput_device_config_tap_get_default_drag_enabled(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static const char * @@ -68,8 +68,8 @@ draglock_default(struct libinput_device *device) if (libinput_device_config_tap_get_default_drag_lock_enabled(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static const char* @@ -80,8 +80,8 @@ left_handed_default(struct libinput_device *device) if (libinput_device_config_left_handed_get_default(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static const char * @@ -92,8 +92,8 @@ nat_scroll_default(struct libinput_device *device) if (libinput_device_config_scroll_get_default_natural_scroll_enabled(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static const char * @@ -104,8 +104,8 @@ middle_emulation_default(struct libinput_device *device) if (libinput_device_config_middle_emulation_get_default_enabled(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static char * @@ -222,8 +222,8 @@ dwt_default(struct libinput_device *device) if (libinput_device_config_dwt_get_default_enabled(device)) return "enabled"; - else - return "disabled"; + + return "disabled"; } static char * @@ -384,13 +384,15 @@ main(int argc, char **argv) if (streq(argv[1], "--help")) { usage(); return 0; - } else if (streq(argv[1], "--version")) { + } + + if (streq(argv[1], "--version")) { printf("%s\n", LIBINPUT_VERSION); return 0; - } else { - usage(); - return EXIT_INVALID_USAGE; } + + usage(); + return EXIT_INVALID_USAGE; } li = tools_open_backend(BACKEND_UDEV, seat, false, &grab); diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 79715a91..6572858c 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -2200,12 +2200,17 @@ mainloop(struct record_context *ctx) fprintf(stderr, "Error: %m\n"); autorestart = false; break; - } else if (rc == 0) { + } + + if (rc == 0) { fprintf(stderr, " ... timeout%s\n", had_events ? "" : " (file is empty)"); break; - } else if (fds[0].revents != 0) { /* signal */ + + } + + if (fds[0].revents != 0) { /* signal */ autorestart = false; break; } diff --git a/tools/shared.c b/tools/shared.c index af791274..0e99c358 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -564,12 +564,11 @@ tools_exec_command(const char *prefix, int real_argc, char **real_argv) "libinput: %s is not installed\n", command); return EXIT_INVALID_USAGE; - } else { - fprintf(stderr, - "Failed to execute '%s' (%s)\n", - command, - strerror(errno)); } + fprintf(stderr, + "Failed to execute '%s' (%s)\n", + command, + strerror(errno)); } return EXIT_FAILURE;