From 2d9659d765b9da1a0ad3d7ea4a064ba08eee6260 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 8 Jun 2023 17:21:07 +0200 Subject: [PATCH] backend/libinput: use struct initializers for events This is more readable and consistent with the rest of wlroots. --- backend/libinput/keyboard.c | 14 ++++----- backend/libinput/pointer.c | 56 +++++++++++++++++----------------- backend/libinput/switch.c | 6 ++-- backend/libinput/tablet_pad.c | 38 +++++++++++------------ backend/libinput/tablet_tool.c | 50 +++++++++++++++--------------- backend/libinput/touch.c | 34 ++++++++++----------- 6 files changed, 98 insertions(+), 100 deletions(-) diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index 789260d5..2e5e6ef1 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -36,13 +36,12 @@ void handle_keyboard_key(struct libinput_event *event, struct wlr_keyboard *kb) { struct libinput_event_keyboard *kbevent = libinput_event_get_keyboard_event(event); - struct wlr_keyboard_key_event wlr_event = { 0 }; - wlr_event.time_msec = - usec_to_msec(libinput_event_keyboard_get_time_usec(kbevent)); - wlr_event.keycode = libinput_event_keyboard_get_key(kbevent); - enum libinput_key_state state = - libinput_event_keyboard_get_key_state(kbevent); - switch (state) { + struct wlr_keyboard_key_event wlr_event = { + .time_msec = usec_to_msec(libinput_event_keyboard_get_time_usec(kbevent)), + .keycode = libinput_event_keyboard_get_key(kbevent), + .update_state = true, + }; + switch (libinput_event_keyboard_get_key_state(kbevent)) { case LIBINPUT_KEY_STATE_RELEASED: wlr_event.state = WL_KEYBOARD_KEY_STATE_RELEASED; break; @@ -50,6 +49,5 @@ void handle_keyboard_key(struct libinput_event *event, wlr_event.state = WL_KEYBOARD_KEY_STATE_PRESSED; break; } - wlr_event.update_state = true; wlr_keyboard_notify_key(kb, &wlr_event); } diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 93f7ca32..711474fe 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -28,14 +28,14 @@ void handle_pointer_motion(struct libinput_event *event, struct wlr_pointer *pointer) { struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); - struct wlr_pointer_motion_event wlr_event = { 0 }; - wlr_event.pointer = pointer; - wlr_event.time_msec = - usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); - wlr_event.delta_x = libinput_event_pointer_get_dx(pevent); - wlr_event.delta_y = libinput_event_pointer_get_dy(pevent); - wlr_event.unaccel_dx = libinput_event_pointer_get_dx_unaccelerated(pevent); - wlr_event.unaccel_dy = libinput_event_pointer_get_dy_unaccelerated(pevent); + struct wlr_pointer_motion_event wlr_event = { + .pointer = pointer, + .time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)), + .delta_x = libinput_event_pointer_get_dx(pevent), + .delta_y = libinput_event_pointer_get_dy(pevent), + .unaccel_dx = libinput_event_pointer_get_dx_unaccelerated(pevent), + .unaccel_dy = libinput_event_pointer_get_dy_unaccelerated(pevent), + }; wl_signal_emit_mutable(&pointer->events.motion, &wlr_event); wl_signal_emit_mutable(&pointer->events.frame, pointer); } @@ -44,12 +44,12 @@ void handle_pointer_motion_abs(struct libinput_event *event, struct wlr_pointer *pointer) { struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); - struct wlr_pointer_motion_absolute_event wlr_event = { 0 }; - wlr_event.pointer = pointer; - wlr_event.time_msec = - usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); - wlr_event.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1); - wlr_event.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1); + struct wlr_pointer_motion_absolute_event wlr_event = { + .pointer = pointer, + .time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)), + .x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1), + .y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1), + }; wl_signal_emit_mutable(&pointer->events.motion_absolute, &wlr_event); wl_signal_emit_mutable(&pointer->events.frame, pointer); } @@ -58,11 +58,11 @@ void handle_pointer_button(struct libinput_event *event, struct wlr_pointer *pointer) { struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); - struct wlr_pointer_button_event wlr_event = { 0 }; - wlr_event.pointer = pointer; - wlr_event.time_msec = - usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); - wlr_event.button = libinput_event_pointer_get_button(pevent); + struct wlr_pointer_button_event wlr_event = { + .pointer = pointer, + .time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)), + .button = libinput_event_pointer_get_button(pevent), + }; // Ignore events which aren't a seat-wide state change. For instance, if // the same button is pressed twice on the same seat, ignore the second // press. @@ -89,10 +89,10 @@ void handle_pointer_axis(struct libinput_event *event, struct wlr_pointer *pointer) { struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); - struct wlr_pointer_axis_event wlr_event = { 0 }; - wlr_event.pointer = pointer; - wlr_event.time_msec = - usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); + struct wlr_pointer_axis_event wlr_event = { + .pointer = pointer, + .time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)), + }; switch (libinput_event_pointer_get_axis_source(pevent)) { case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL: wlr_event.source = WLR_AXIS_SOURCE_WHEEL; @@ -139,11 +139,11 @@ void handle_pointer_axis_value120(struct libinput_event *event, struct wlr_pointer *pointer, enum wlr_axis_source source) { struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); - struct wlr_pointer_axis_event wlr_event = { 0 }; - wlr_event.pointer = pointer; - wlr_event.time_msec = - usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); - wlr_event.source = source; + struct wlr_pointer_axis_event wlr_event = { + .pointer = pointer, + .time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)), + .source = source, + }; const enum libinput_pointer_axis axes[] = { LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, diff --git a/backend/libinput/switch.c b/backend/libinput/switch.c index e8c68bef..61bb887f 100644 --- a/backend/libinput/switch.c +++ b/backend/libinput/switch.c @@ -28,7 +28,9 @@ void handle_switch_toggle(struct libinput_event *event, struct wlr_switch *wlr_switch) { struct libinput_event_switch *sevent = libinput_event_get_switch_event (event); - struct wlr_switch_toggle_event wlr_event = { 0 }; + struct wlr_switch_toggle_event wlr_event = { + .time_msec = usec_to_msec(libinput_event_switch_get_time_usec(sevent)), + }; switch (libinput_event_switch_get_switch(sevent)) { case LIBINPUT_SWITCH_LID: wlr_event.switch_type = WLR_SWITCH_TYPE_LID; @@ -45,7 +47,5 @@ void handle_switch_toggle(struct libinput_event *event, wlr_event.switch_state = WLR_SWITCH_STATE_ON; break; } - wlr_event.time_msec = - usec_to_msec(libinput_event_switch_get_time_usec(sevent)); wl_signal_emit_mutable(&wlr_switch->events.toggle, &wlr_event); } diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 078f7ca1..d72896c0 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -144,13 +144,13 @@ void handle_tablet_pad_button(struct libinput_event *event, struct wlr_tablet_pad *tablet_pad) { struct libinput_event_tablet_pad *pevent = libinput_event_get_tablet_pad_event(event); - struct wlr_tablet_pad_button_event wlr_event = { 0 }; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)); - wlr_event.button = libinput_event_tablet_pad_get_button_number(pevent); - wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent); - wlr_event.group = libinput_tablet_pad_mode_group_get_index( - libinput_event_tablet_pad_get_mode_group(pevent)); + struct wlr_tablet_pad_button_event wlr_event = { + .time_msec = usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)), + .button = libinput_event_tablet_pad_get_button_number(pevent), + .mode = libinput_event_tablet_pad_get_mode(pevent), + .group = libinput_tablet_pad_mode_group_get_index( + libinput_event_tablet_pad_get_mode_group(pevent)), + }; switch (libinput_event_tablet_pad_get_button_state(pevent)) { case LIBINPUT_BUTTON_STATE_PRESSED: wlr_event.state = WLR_BUTTON_PRESSED; @@ -166,12 +166,12 @@ void handle_tablet_pad_ring(struct libinput_event *event, struct wlr_tablet_pad *tablet_pad) { struct libinput_event_tablet_pad *pevent = libinput_event_get_tablet_pad_event(event); - struct wlr_tablet_pad_ring_event wlr_event = { 0 }; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)); - wlr_event.ring = libinput_event_tablet_pad_get_ring_number(pevent); - wlr_event.position = libinput_event_tablet_pad_get_ring_position(pevent); - wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent); + struct wlr_tablet_pad_ring_event wlr_event = { + .time_msec = usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)), + .ring = libinput_event_tablet_pad_get_ring_number(pevent), + .position = libinput_event_tablet_pad_get_ring_position(pevent), + .mode = libinput_event_tablet_pad_get_mode(pevent), + }; switch (libinput_event_tablet_pad_get_ring_source(pevent)) { case LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN: wlr_event.source = WLR_TABLET_PAD_RING_SOURCE_UNKNOWN; @@ -187,12 +187,12 @@ void handle_tablet_pad_strip(struct libinput_event *event, struct wlr_tablet_pad *tablet_pad) { struct libinput_event_tablet_pad *pevent = libinput_event_get_tablet_pad_event(event); - struct wlr_tablet_pad_strip_event wlr_event = { 0 }; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)); - wlr_event.strip = libinput_event_tablet_pad_get_strip_number(pevent); - wlr_event.position = libinput_event_tablet_pad_get_strip_position(pevent); - wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent); + struct wlr_tablet_pad_strip_event wlr_event = { + .time_msec = usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)), + .strip = libinput_event_tablet_pad_get_strip_number(pevent), + .position = libinput_event_tablet_pad_get_strip_position(pevent), + .mode = libinput_event_tablet_pad_get_mode(pevent), + }; switch (libinput_event_tablet_pad_get_strip_source(pevent)) { case LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN: wlr_event.source = WLR_TABLET_PAD_STRIP_SOURCE_UNKNOWN; diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index d049d16e..1962fc82 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -129,11 +129,11 @@ void handle_tablet_tool_axis(struct libinput_event *event, struct tablet_tool *tool = get_tablet_tool(dev, libinput_event_tablet_tool_get_tool(tevent)); - struct wlr_tablet_tool_axis_event wlr_event = { 0 }; - wlr_event.tablet = wlr_tablet; - wlr_event.tool = &tool->wlr_tool; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); + struct wlr_tablet_tool_axis_event wlr_event = { + .tablet = wlr_tablet, + .tool = &tool->wlr_tool, + .time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)), + }; if (libinput_event_tablet_tool_x_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X; wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1); @@ -183,13 +183,13 @@ void handle_tablet_tool_proximity(struct libinput_event *event, struct tablet_tool *tool = get_tablet_tool(dev, libinput_event_tablet_tool_get_tool(tevent)); - struct wlr_tablet_tool_proximity_event wlr_event = { 0 }; - wlr_event.tablet = wlr_tablet; - wlr_event.tool = &tool->wlr_tool; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); - wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1); - wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1); + struct wlr_tablet_tool_proximity_event wlr_event = { + .tablet = wlr_tablet, + .tool = &tool->wlr_tool, + .time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)), + .x = libinput_event_tablet_tool_get_x_transformed(tevent, 1), + .y = libinput_event_tablet_tool_get_y_transformed(tevent, 1), + }; switch (libinput_event_tablet_tool_get_proximity_state(tevent)) { case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT: @@ -225,13 +225,13 @@ void handle_tablet_tool_tip(struct libinput_event *event, struct tablet_tool *tool = get_tablet_tool(dev, libinput_event_tablet_tool_get_tool(tevent)); - struct wlr_tablet_tool_tip_event wlr_event = { 0 }; - wlr_event.tablet = wlr_tablet; - wlr_event.tool = &tool->wlr_tool; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); - wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1); - wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1); + struct wlr_tablet_tool_tip_event wlr_event = { + .tablet = wlr_tablet, + .tool = &tool->wlr_tool, + .time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)), + .x = libinput_event_tablet_tool_get_x_transformed(tevent, 1), + .y = libinput_event_tablet_tool_get_y_transformed(tevent, 1), + }; switch (libinput_event_tablet_tool_get_tip_state(tevent)) { case LIBINPUT_TABLET_TOOL_TIP_UP: @@ -253,12 +253,12 @@ void handle_tablet_tool_button(struct libinput_event *event, struct tablet_tool *tool = get_tablet_tool(dev, libinput_event_tablet_tool_get_tool(tevent)); - struct wlr_tablet_tool_button_event wlr_event = { 0 }; - wlr_event.tablet = wlr_tablet; - wlr_event.tool = &tool->wlr_tool; - wlr_event.time_msec = - usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); - wlr_event.button = libinput_event_tablet_tool_get_button(tevent); + struct wlr_tablet_tool_button_event wlr_event = { + .tablet = wlr_tablet, + .tool = &tool->wlr_tool, + .time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)), + .button = libinput_event_tablet_tool_get_button(tevent), + }; switch (libinput_event_tablet_tool_get_button_state(tevent)) { case LIBINPUT_BUTTON_STATE_RELEASED: wlr_event.state = WLR_BUTTON_RELEASED; diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 3316754e..14713b5b 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -45,11 +45,11 @@ void handle_touch_up(struct libinput_event *event, struct wlr_touch *touch) { struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); - struct wlr_touch_up_event wlr_event = { 0 }; - wlr_event.touch = touch; - wlr_event.time_msec = - usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent); + struct wlr_touch_up_event wlr_event = { + .touch = touch, + .time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)), + .touch_id = libinput_event_touch_get_seat_slot(tevent), + }; wl_signal_emit_mutable(&touch->events.up, &wlr_event); } @@ -57,13 +57,13 @@ void handle_touch_motion(struct libinput_event *event, struct wlr_touch *touch) { struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); - struct wlr_touch_motion_event wlr_event = { 0 }; - wlr_event.touch = touch; - wlr_event.time_msec = - usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent); - wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1); - wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1); + struct wlr_touch_motion_event wlr_event = { + .touch = touch, + .time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)), + .touch_id = libinput_event_touch_get_seat_slot(tevent), + .x = libinput_event_touch_get_x_transformed(tevent, 1), + .y = libinput_event_touch_get_y_transformed(tevent, 1), + }; wl_signal_emit_mutable(&touch->events.motion, &wlr_event); } @@ -71,11 +71,11 @@ void handle_touch_cancel(struct libinput_event *event, struct wlr_touch *touch) { struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); - struct wlr_touch_cancel_event wlr_event = { 0 }; - wlr_event.touch = touch; - wlr_event.time_msec = - usec_to_msec(libinput_event_touch_get_time_usec(tevent)); - wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent); + struct wlr_touch_cancel_event wlr_event = { + .touch = touch, + .time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)), + .touch_id = libinput_event_touch_get_seat_slot(tevent), + }; wl_signal_emit_mutable(&touch->events.cancel, &wlr_event); }