From cce59210159e2699a4f69d4c4a601a1bbc7cecfe Mon Sep 17 00:00:00 2001 From: weizhixiang Date: Wed, 19 May 2021 21:09:30 +0900 Subject: use ARRAY_FOR_EACH when traverse array Signed-off-by: weizhixiang --- tools/libinput-debug-gui.c | 16 ++++++++-------- tools/libinput-debug-tablet.c | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'tools') diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index fc5af4d8..187567a6 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -1036,10 +1036,10 @@ static void handle_event_device_notify(struct libinput_event *ev) { struct libinput_device *dev = libinput_event_get_device(ev); + struct libinput_device **device; struct libinput *li; struct window *w; const char *type; - size_t i; li = libinput_event_get_context(ev); w = libinput_get_user_data(li); @@ -1060,17 +1060,17 @@ handle_event_device_notify(struct libinput_event *ev) type); if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) { - for (i = 0; i < ARRAY_LENGTH(w->devices); i++) { - if (w->devices[i] == NULL) { - w->devices[i] = libinput_device_ref(dev); + ARRAY_FOR_EACH(w->devices, device) { + if (*device == NULL) { + *device = libinput_device_ref(dev); break; } } } else { - for (i = 0; i < ARRAY_LENGTH(w->devices); i++) { - if (w->devices[i] == dev) { - libinput_device_unref(w->devices[i]); - w->devices[i] = NULL; + ARRAY_FOR_EACH(w->devices, device) { + if (*device == dev) { + libinput_device_unref(*device); + *device = NULL; break; } } diff --git a/tools/libinput-debug-tablet.c b/tools/libinput-debug-tablet.c index 08d3e432..ceaee1d1 100644 --- a/tools/libinput-debug-tablet.c +++ b/tools/libinput-debug-tablet.c @@ -306,17 +306,18 @@ handle_tablet_button_event(struct context *ctx, struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); unsigned int button = libinput_event_tablet_tool_get_button(t); + unsigned int *btn; enum libinput_button_state state = libinput_event_tablet_tool_get_button_state(t); - for (size_t i = 0; i < ARRAY_LENGTH(ctx->buttons_down); i++) { + ARRAY_FOR_EACH(ctx->buttons_down, btn) { if (state == LIBINPUT_BUTTON_STATE_PRESSED) { - if (ctx->buttons_down[i] == 0) { - ctx->buttons_down[i] = button; + if (*btn == 0) { + *btn = button; break; } } else { - if (ctx->buttons_down[i] == button) { - ctx->buttons_down[i] = 0; + if (*btn == button) { + *btn = 0; break; } } -- cgit v1.2.1