backend/libinput: use struct initializers for events

This is more readable and consistent with the rest of wlroots.
master
Simon Ser 1 year ago
parent e1c6801b65
commit 2d9659d765

@ -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);
}

@ -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,

@ -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);
}

@ -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;

@ -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;

@ -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);
}

Loading…
Cancel
Save