summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorweizhixiang <weizhixiang@uniontech.com>2021-05-19 21:09:30 +0900
committerPeter Hutterer <peter.hutterer@who-t.net>2021-05-24 04:11:32 +0000
commitcce59210159e2699a4f69d4c4a601a1bbc7cecfe (patch)
treef12113ea6ec30a37a04918f5259afa8792acc277
parent0cb570addd126648cd53d54591c6c34810738092 (diff)
downloadlibinput-cce59210159e2699a4f69d4c4a601a1bbc7cecfe.tar.gz
use ARRAY_FOR_EACH when traverse array
Signed-off-by: weizhixiang <weizhixiang@uniontech.com>
-rw-r--r--tools/libinput-debug-gui.c16
-rw-r--r--tools/libinput-debug-tablet.c11
2 files changed, 14 insertions, 13 deletions
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;
}
}