use ARRAY_FOR_EACH when traverse array
authorweizhixiang <weizhixiang@uniontech.com>
Wed, 19 May 2021 12:09:30 +0000 (21:09 +0900)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 24 May 2021 04:11:32 +0000 (04:11 +0000)
Signed-off-by: weizhixiang <weizhixiang@uniontech.com>
tools/libinput-debug-gui.c
tools/libinput-debug-tablet.c

index fc5af4d856c57f9d4369b9e670706c9821def73a..187567a6dfb189f0ba38952c5c085bd60aebdeb9 100644 (file)
@@ -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;
                        }
                }
index 08d3e432e76bac9d6d19e28336b288e9d8a43ce8..ceaee1d1dc9fd610033f0bfd0b37ed7617f07db4 100644 (file)
@@ -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;
                        }
                }