wlr_input_device: remove anon union field

This union is unnecessary since the recent input device refactor and can
now be replaced by wlr_*_from_input_device() functions.
This commit is contained in:
Isaac Freund 2022-06-20 16:57:29 +02:00 committed by Simon Ser
parent 5c4384a133
commit 91943a68a6
31 changed files with 216 additions and 130 deletions

View file

@ -376,7 +376,7 @@ struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create(
if (!seat) {
return NULL;
}
struct wlr_tablet_pad *wlr_pad = wlr_device->tablet_pad;
struct wlr_tablet_pad *wlr_pad = wlr_tablet_pad_from_input_device(wlr_device);
struct wlr_tablet_v2_tablet_pad *pad = calloc(1, sizeof(struct wlr_tablet_v2_tablet_pad));
if (!pad) {
return NULL;

View file

@ -60,7 +60,7 @@ struct wlr_tablet_v2_tablet *wlr_tablet_create(
if (!seat) {
return NULL;
}
struct wlr_tablet *wlr_tablet = wlr_device->tablet;
struct wlr_tablet *wlr_tablet = wlr_tablet_from_input_device(wlr_device);
struct wlr_tablet_v2_tablet *tablet = calloc(1, sizeof(struct wlr_tablet_v2_tablet));
if (!tablet) {
return NULL;

View file

@ -648,75 +648,78 @@ static struct wlr_cursor_device *cursor_device_create(
c_device->destroy.notify = handle_device_destroy;
if (device->type == WLR_INPUT_DEVICE_POINTER) {
wl_signal_add(&device->pointer->events.motion, &c_device->motion);
struct wlr_pointer *pointer = wlr_pointer_from_input_device(device);
wl_signal_add(&pointer->events.motion, &c_device->motion);
c_device->motion.notify = handle_pointer_motion;
wl_signal_add(&device->pointer->events.motion_absolute,
wl_signal_add(&pointer->events.motion_absolute,
&c_device->motion_absolute);
c_device->motion_absolute.notify = handle_pointer_motion_absolute;
wl_signal_add(&device->pointer->events.button, &c_device->button);
wl_signal_add(&pointer->events.button, &c_device->button);
c_device->button.notify = handle_pointer_button;
wl_signal_add(&device->pointer->events.axis, &c_device->axis);
wl_signal_add(&pointer->events.axis, &c_device->axis);
c_device->axis.notify = handle_pointer_axis;
wl_signal_add(&device->pointer->events.frame, &c_device->frame);
wl_signal_add(&pointer->events.frame, &c_device->frame);
c_device->frame.notify = handle_pointer_frame;
wl_signal_add(&device->pointer->events.swipe_begin, &c_device->swipe_begin);
wl_signal_add(&pointer->events.swipe_begin, &c_device->swipe_begin);
c_device->swipe_begin.notify = handle_pointer_swipe_begin;
wl_signal_add(&device->pointer->events.swipe_update, &c_device->swipe_update);
wl_signal_add(&pointer->events.swipe_update, &c_device->swipe_update);
c_device->swipe_update.notify = handle_pointer_swipe_update;
wl_signal_add(&device->pointer->events.swipe_end, &c_device->swipe_end);
wl_signal_add(&pointer->events.swipe_end, &c_device->swipe_end);
c_device->swipe_end.notify = handle_pointer_swipe_end;
wl_signal_add(&device->pointer->events.pinch_begin, &c_device->pinch_begin);
wl_signal_add(&pointer->events.pinch_begin, &c_device->pinch_begin);
c_device->pinch_begin.notify = handle_pointer_pinch_begin;
wl_signal_add(&device->pointer->events.pinch_update, &c_device->pinch_update);
wl_signal_add(&pointer->events.pinch_update, &c_device->pinch_update);
c_device->pinch_update.notify = handle_pointer_pinch_update;
wl_signal_add(&device->pointer->events.pinch_end, &c_device->pinch_end);
wl_signal_add(&pointer->events.pinch_end, &c_device->pinch_end);
c_device->pinch_end.notify = handle_pointer_pinch_end;
wl_signal_add(&device->pointer->events.hold_begin, &c_device->hold_begin);
wl_signal_add(&pointer->events.hold_begin, &c_device->hold_begin);
c_device->hold_begin.notify = handle_pointer_hold_begin;
wl_signal_add(&device->pointer->events.hold_end, &c_device->hold_end);
wl_signal_add(&pointer->events.hold_end, &c_device->hold_end);
c_device->hold_end.notify = handle_pointer_hold_end;
} else if (device->type == WLR_INPUT_DEVICE_TOUCH) {
wl_signal_add(&device->touch->events.motion, &c_device->touch_motion);
struct wlr_touch *touch = wlr_touch_from_input_device(device);
wl_signal_add(&touch->events.motion, &c_device->touch_motion);
c_device->touch_motion.notify = handle_touch_motion;
wl_signal_add(&device->touch->events.down, &c_device->touch_down);
wl_signal_add(&touch->events.down, &c_device->touch_down);
c_device->touch_down.notify = handle_touch_down;
wl_signal_add(&device->touch->events.up, &c_device->touch_up);
wl_signal_add(&touch->events.up, &c_device->touch_up);
c_device->touch_up.notify = handle_touch_up;
wl_signal_add(&device->touch->events.cancel, &c_device->touch_cancel);
wl_signal_add(&touch->events.cancel, &c_device->touch_cancel);
c_device->touch_cancel.notify = handle_touch_cancel;
wl_signal_add(&device->touch->events.frame, &c_device->touch_frame);
wl_signal_add(&touch->events.frame, &c_device->touch_frame);
c_device->touch_frame.notify = handle_touch_frame;
} else if (device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
wl_signal_add(&device->tablet->events.tip,
&c_device->tablet_tool_tip);
struct wlr_tablet *tablet = wlr_tablet_from_input_device(device);
wl_signal_add(&tablet->events.tip, &c_device->tablet_tool_tip);
c_device->tablet_tool_tip.notify = handle_tablet_tool_tip;
wl_signal_add(&device->tablet->events.proximity,
wl_signal_add(&tablet->events.proximity,
&c_device->tablet_tool_proximity);
c_device->tablet_tool_proximity.notify = handle_tablet_tool_proximity;
wl_signal_add(&device->tablet->events.axis,
&c_device->tablet_tool_axis);
wl_signal_add(&tablet->events.axis, &c_device->tablet_tool_axis);
c_device->tablet_tool_axis.notify = handle_tablet_tool_axis;
wl_signal_add(&device->tablet->events.button,
&c_device->tablet_tool_button);
wl_signal_add(&tablet->events.button, &c_device->tablet_tool_button);
c_device->tablet_tool_button.notify = handle_tablet_tool_button;
}

View file

@ -13,6 +13,12 @@
#include "util/signal.h"
#include "util/time.h"
struct wlr_keyboard *wlr_keyboard_from_input_device(
struct wlr_input_device *input_device) {
assert(input_device->type == WLR_INPUT_DEVICE_KEYBOARD);
return wl_container_of(input_device, (struct wlr_keyboard *)NULL, base);
}
void keyboard_led_update(struct wlr_keyboard *keyboard) {
if (keyboard->xkb_state == NULL) {
return;
@ -118,7 +124,6 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
const struct wlr_keyboard_impl *impl, const char *name) {
memset(kb, 0, sizeof(*kb));
wlr_input_device_init(&kb->base, WLR_INPUT_DEVICE_KEYBOARD, name);
kb->base.keyboard = kb;
kb->impl = impl;
wl_signal_init(&kb->events.key);

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
@ -6,11 +7,16 @@
#include "interfaces/wlr_input_device.h"
struct wlr_pointer *wlr_pointer_from_input_device(
struct wlr_input_device *input_device) {
assert(input_device->type == WLR_INPUT_DEVICE_POINTER);
return wl_container_of(input_device, (struct wlr_pointer *)NULL, base);
}
void wlr_pointer_init(struct wlr_pointer *pointer,
const struct wlr_pointer_impl *impl, const char *name) {
memset(pointer, 0, sizeof(*pointer));
wlr_input_device_init(&pointer->base, WLR_INPUT_DEVICE_POINTER, name);
pointer->base.pointer = pointer;
pointer->impl = impl;
wl_signal_init(&pointer->events.motion);

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
@ -6,11 +7,16 @@
#include "interfaces/wlr_input_device.h"
struct wlr_switch *wlr_switch_from_input_device(
struct wlr_input_device *input_device) {
assert(input_device->type == WLR_INPUT_DEVICE_SWITCH);
return wl_container_of(input_device, (struct wlr_switch *)NULL, base);
}
void wlr_switch_init(struct wlr_switch *switch_device,
const struct wlr_switch_impl *impl, const char *name) {
memset(switch_device, 0, sizeof(*switch_device));
wlr_input_device_init(&switch_device->base, WLR_INPUT_DEVICE_SWITCH, name);
switch_device->base.switch_device = switch_device;
switch_device->impl = impl;
wl_signal_init(&switch_device->events.toggle);

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
@ -7,11 +8,16 @@
#include "interfaces/wlr_input_device.h"
struct wlr_tablet_pad *wlr_tablet_pad_from_input_device(
struct wlr_input_device *input_device) {
assert(input_device->type == WLR_INPUT_DEVICE_TABLET_PAD);
return wl_container_of(input_device, (struct wlr_tablet_pad *)NULL, base);
}
void wlr_tablet_pad_init(struct wlr_tablet_pad *pad,
const struct wlr_tablet_pad_impl *impl, const char *name) {
memset(pad, 0, sizeof(*pad));
wlr_input_device_init(&pad->base, WLR_INPUT_DEVICE_TABLET_PAD, name);
pad->base.tablet_pad = pad;
pad->impl = impl;
wl_signal_init(&pad->events.button);

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
@ -6,11 +7,16 @@
#include "interfaces/wlr_input_device.h"
struct wlr_tablet *wlr_tablet_from_input_device(
struct wlr_input_device *input_device) {
assert(input_device->type == WLR_INPUT_DEVICE_TABLET_TOOL);
return wl_container_of(input_device, (struct wlr_tablet *)NULL, base);
}
void wlr_tablet_init(struct wlr_tablet *tablet,
const struct wlr_tablet_impl *impl, const char *name) {
memset(tablet, 0, sizeof(*tablet));
wlr_input_device_init(&tablet->base, WLR_INPUT_DEVICE_TABLET_TOOL, name);
tablet->base.tablet = tablet;
tablet->impl = impl;
wl_signal_init(&tablet->events.axis);

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
@ -6,11 +7,16 @@
#include "interfaces/wlr_input_device.h"
struct wlr_touch *wlr_touch_from_input_device(
struct wlr_input_device *input_device) {
assert(input_device->type == WLR_INPUT_DEVICE_TOUCH);
return wl_container_of(input_device, (struct wlr_touch *)NULL, base);
}
void wlr_touch_init(struct wlr_touch *touch,
const struct wlr_touch_impl *impl, const char *name) {
memset(touch, 0, sizeof(*touch));
wlr_input_device_init(&touch->base, WLR_INPUT_DEVICE_TOUCH, name);
touch->base.touch = touch;
touch->impl = impl;
wl_signal_init(&touch->events.down);

View file

@ -26,11 +26,15 @@ static struct wlr_virtual_keyboard_v1 *virtual_keyboard_from_resource(
struct wlr_virtual_keyboard_v1 *wlr_input_device_get_virtual_keyboard(
struct wlr_input_device *wlr_dev) {
if (wlr_dev->type != WLR_INPUT_DEVICE_KEYBOARD
|| wlr_dev->keyboard->impl != &keyboard_impl) {
if (wlr_dev->type != WLR_INPUT_DEVICE_KEYBOARD) {
return NULL;
}
return (struct wlr_virtual_keyboard_v1 *)wlr_dev->keyboard;
struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(wlr_dev);
if (wlr_keyboard->impl != &keyboard_impl) {
return NULL;
}
return wl_container_of(wlr_keyboard,
(struct wlr_virtual_keyboard_v1 *)NULL, keyboard);
}
static void virtual_keyboard_keymap(struct wl_client *client,

View file

@ -106,21 +106,20 @@ static void virtual_pointer_frame(struct wl_client *client,
if (pointer == NULL) {
return;
}
struct wlr_input_device *wlr_dev = &pointer->pointer.base;
for (size_t i = 0;
i < sizeof(pointer->axis_valid) / sizeof(pointer->axis_valid[0]);
++i) {
if (pointer->axis_valid[i]) {
/* Deliver pending axis event */
wlr_signal_emit_safe(&wlr_dev->pointer->events.axis,
wlr_signal_emit_safe(&pointer->pointer.events.axis,
&pointer->axis_event[i]);
memset(&pointer->axis_event[i], 0, sizeof(pointer->axis_event[i]));
pointer->axis_valid[i] = false;
}
}
wlr_signal_emit_safe(&wlr_dev->pointer->events.frame, wlr_dev->pointer);
wlr_signal_emit_safe(&pointer->pointer.events.frame, &pointer->pointer);
}
static void virtual_pointer_axis_source(struct wl_client *client,