diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 60f456cc1..f47121dbe 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -228,22 +228,22 @@ struct libinput_device *wlr_libinput_get_device_handle( struct wlr_libinput_input_device *dev = NULL; switch (wlr_dev->type) { case WLR_INPUT_DEVICE_KEYBOARD: - dev = device_from_keyboard(wlr_dev->keyboard); + dev = device_from_keyboard(wlr_keyboard_from_input_device(wlr_dev)); break; case WLR_INPUT_DEVICE_POINTER: - dev = device_from_pointer(wlr_dev->pointer); + dev = device_from_pointer(wlr_pointer_from_input_device(wlr_dev)); break; case WLR_INPUT_DEVICE_SWITCH: - dev = device_from_switch(wlr_dev->switch_device); + dev = device_from_switch(wlr_switch_from_input_device(wlr_dev)); break; case WLR_INPUT_DEVICE_TOUCH: - dev = device_from_touch(wlr_dev->touch); + dev = device_from_touch(wlr_touch_from_input_device(wlr_dev)); break; case WLR_INPUT_DEVICE_TABLET_TOOL: - dev = device_from_tablet(wlr_dev->tablet); + dev = device_from_tablet(wlr_tablet_from_input_device(wlr_dev)); break; case WLR_INPUT_DEVICE_TABLET_PAD: - dev = device_from_tablet_pad(wlr_dev->tablet_pad); + dev = device_from_tablet_pad(wlr_tablet_pad_from_input_device(wlr_dev)); break; } return dev->handle; diff --git a/backend/libinput/events.c b/backend/libinput/events.c index e52dbd956..b9f2f43c5 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -41,17 +41,23 @@ void destroy_libinput_input_device(struct wlr_libinput_input_device *dev) { bool wlr_input_device_is_libinput(struct wlr_input_device *wlr_dev) { switch (wlr_dev->type) { case WLR_INPUT_DEVICE_KEYBOARD: - return wlr_dev->keyboard->impl == &libinput_keyboard_impl; + return wlr_keyboard_from_input_device(wlr_dev)->impl == + &libinput_keyboard_impl; case WLR_INPUT_DEVICE_POINTER: - return wlr_dev->pointer->impl == &libinput_pointer_impl; + return wlr_pointer_from_input_device(wlr_dev)->impl == + &libinput_pointer_impl; case WLR_INPUT_DEVICE_TOUCH: - return wlr_dev->touch->impl == &libinput_touch_impl; + return wlr_touch_from_input_device(wlr_dev)->impl == + &libinput_touch_impl; case WLR_INPUT_DEVICE_TABLET_TOOL: - return wlr_dev->tablet->impl == &libinput_tablet_impl; + return wlr_tablet_from_input_device(wlr_dev)-> impl == + &libinput_tablet_impl; case WLR_INPUT_DEVICE_TABLET_PAD: - return wlr_dev->tablet_pad->impl == &libinput_tablet_pad_impl; + return wlr_tablet_pad_from_input_device(wlr_dev)->impl == + &libinput_tablet_pad_impl; case WLR_INPUT_DEVICE_SWITCH: - return wlr_dev->switch_device->impl == &libinput_switch_impl; + return wlr_switch_from_input_device(wlr_dev)->impl == + &libinput_switch_impl; default: return false; } diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c index c05591aa3..d1c75b397 100644 --- a/backend/wayland/seat.c +++ b/backend/wayland/seat.c @@ -280,15 +280,15 @@ void destroy_wl_seats(struct wlr_wl_backend *wl) { bool wlr_input_device_is_wl(struct wlr_input_device *dev) { switch (dev->type) { case WLR_INPUT_DEVICE_KEYBOARD: - return dev->keyboard->impl == &keyboard_impl; + return wlr_keyboard_from_input_device(dev)->impl == &keyboard_impl; case WLR_INPUT_DEVICE_POINTER: - return dev->pointer->impl == &wl_pointer_impl; + return wlr_pointer_from_input_device(dev)->impl == &wl_pointer_impl; case WLR_INPUT_DEVICE_TOUCH: - return dev->touch->impl == &touch_impl; + return wlr_touch_from_input_device(dev)->impl == &touch_impl; case WLR_INPUT_DEVICE_TABLET_TOOL: - return dev->tablet->impl == &wl_tablet_impl; + return wlr_tablet_from_input_device(dev)-> impl == &wl_tablet_impl; case WLR_INPUT_DEVICE_TABLET_PAD: - return dev->tablet_pad->impl == &wl_tablet_pad_impl; + return wlr_tablet_pad_from_input_device(dev)->impl == &wl_tablet_pad_impl; default: return false; } diff --git a/backend/x11/input_device.c b/backend/x11/input_device.c index d1f5c2c1f..41168222d 100644 --- a/backend/x11/input_device.c +++ b/backend/x11/input_device.c @@ -317,11 +317,11 @@ void update_x11_pointer_position(struct wlr_x11_output *output, bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) { switch (wlr_dev->type) { case WLR_INPUT_DEVICE_KEYBOARD: - return wlr_dev->keyboard->impl == &x11_keyboard_impl; + return wlr_keyboard_from_input_device(wlr_dev)->impl == &x11_keyboard_impl; case WLR_INPUT_DEVICE_POINTER: - return wlr_dev->pointer->impl == &x11_pointer_impl; + return wlr_pointer_from_input_device(wlr_dev)->impl == &x11_pointer_impl; case WLR_INPUT_DEVICE_TOUCH: - return wlr_dev->touch->impl == &x11_touch_impl; + return wlr_touch_from_input_device(wlr_dev)->impl == &x11_touch_impl; default: return false; } diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index d6189f29f..26311319c 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -64,7 +64,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -188,7 +188,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -211,11 +211,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -228,7 +228,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; diff --git a/examples/output-layout.c b/examples/output-layout.c index a057ca78b..97939953f 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -45,7 +45,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -186,7 +186,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -229,11 +229,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -246,7 +246,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; diff --git a/examples/pointer.c b/examples/pointer.c index 1197386e7..6eb328ac2 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -70,7 +70,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *state; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -231,7 +231,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -297,11 +297,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->state = state; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -314,7 +314,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; diff --git a/examples/quads.c b/examples/quads.c index 88c59f7c4..a9c7a14b8 100644 --- a/examples/quads.c +++ b/examples/quads.c @@ -39,7 +39,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -132,7 +132,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -155,11 +155,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -172,7 +172,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; diff --git a/examples/rotation.c b/examples/rotation.c index a2e868af2..087fa8d18 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -44,7 +44,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -137,7 +137,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -176,11 +176,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -193,7 +193,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; diff --git a/examples/simple.c b/examples/simple.c index e46093be5..5a41d19e4 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -35,7 +35,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -112,7 +112,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -137,11 +137,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -154,7 +154,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; diff --git a/examples/tablet.c b/examples/tablet.c index 35def7007..1fb0233bb 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -43,7 +43,7 @@ struct sample_state { struct tablet_tool_state { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_tablet *wlr_tablet; struct wl_listener destroy; struct wl_listener axis; struct wl_listener proximity; @@ -55,7 +55,7 @@ struct tablet_tool_state { struct tablet_pad_state { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_tablet_pad *wlr_tablet_pad; struct wl_listener destroy; struct wl_listener button; struct wl_listener ring; @@ -72,7 +72,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -264,7 +264,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -287,11 +287,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -304,40 +304,40 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; case WLR_INPUT_DEVICE_TABLET_PAD:; struct tablet_pad_state *pstate = calloc(sizeof(struct tablet_pad_state), 1); - pstate->device = device; + pstate->wlr_tablet_pad = wlr_tablet_pad_from_input_device(device); pstate->sample = sample; pstate->destroy.notify = tablet_pad_destroy_notify; wl_signal_add(&device->events.destroy, &pstate->destroy); pstate->button.notify = tablet_pad_button_notify; - wl_signal_add(&device->tablet_pad->events.button, &pstate->button); + wl_signal_add(&pstate->wlr_tablet_pad->events.button, &pstate->button); pstate->ring.notify = tablet_pad_ring_notify; - wl_signal_add(&device->tablet_pad->events.ring, &pstate->ring); + wl_signal_add(&pstate->wlr_tablet_pad->events.ring, &pstate->ring); wl_list_insert(&sample->tablet_pads, &pstate->link); break; case WLR_INPUT_DEVICE_TABLET_TOOL:; - struct wlr_tablet *tablet = device->tablet; + struct wlr_tablet *tablet = wlr_tablet_from_input_device(device); sample->width_mm = tablet->width_mm == 0 ? 20 : tablet->width_mm; sample->height_mm = tablet->height_mm == 0 ? 10 : tablet->height_mm; struct tablet_tool_state *tstate = calloc(sizeof(struct tablet_tool_state), 1); - tstate->device = device; + tstate->wlr_tablet = tablet; tstate->sample = sample; tstate->destroy.notify = tablet_tool_destroy_notify; wl_signal_add(&device->events.destroy, &tstate->destroy); tstate->axis.notify = tablet_tool_axis_notify; - wl_signal_add(&device->tablet->events.axis, &tstate->axis); + wl_signal_add(&tablet->events.axis, &tstate->axis); tstate->proximity.notify = tablet_tool_proximity_notify; - wl_signal_add(&device->tablet->events.proximity, &tstate->proximity); + wl_signal_add(&tablet->events.proximity, &tstate->proximity); tstate->button.notify = tablet_tool_button_notify; - wl_signal_add(&device->tablet->events.button, &tstate->button); + wl_signal_add(&tablet->events.button, &tstate->button); wl_list_insert(&sample->tablet_tools, &tstate->link); break; default: diff --git a/examples/touch.c b/examples/touch.c index 765b41aa8..d33e148aa 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -41,7 +41,7 @@ struct touch_point { struct touch_state { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_touch *wlr_touch; struct wl_listener destroy; struct wl_listener down; struct wl_listener up; @@ -59,7 +59,7 @@ struct sample_output { struct sample_keyboard { struct sample_state *sample; - struct wlr_input_device *device; + struct wlr_keyboard *wlr_keyboard; struct wl_listener key; struct wl_listener destroy; }; @@ -175,7 +175,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_keyboard_key_event *event = data; uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + int nsyms = xkb_state_key_get_syms(keyboard->wlr_keyboard->xkb_state, keycode, &syms); for (int i = 0; i < nsyms; i++) { xkb_keysym_t sym = syms[i]; @@ -198,11 +198,11 @@ static void new_input_notify(struct wl_listener *listener, void *data) { switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD:; struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard)); - keyboard->device = device; + keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device); keyboard->sample = sample; wl_signal_add(&device->events.destroy, &keyboard->destroy); keyboard->destroy.notify = keyboard_destroy_notify; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&keyboard->wlr_keyboard->events.key, &keyboard->key); keyboard->key.notify = keyboard_key_notify; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!context) { @@ -215,22 +215,22 @@ static void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB keymap"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); break; case WLR_INPUT_DEVICE_TOUCH:; struct touch_state *tstate = calloc(sizeof(struct touch_state), 1); - tstate->device = device; + tstate->wlr_touch = wlr_touch_from_input_device(device); tstate->sample = sample; tstate->destroy.notify = touch_destroy_notify; wl_signal_add(&device->events.destroy, &tstate->destroy); tstate->down.notify = touch_down_notify; - wl_signal_add(&device->touch->events.down, &tstate->down); + wl_signal_add(&tstate->wlr_touch->events.down, &tstate->down); tstate->motion.notify = touch_motion_notify; - wl_signal_add(&device->touch->events.motion, &tstate->motion); + wl_signal_add(&tstate->wlr_touch->events.motion, &tstate->motion); tstate->up.notify = touch_up_notify; - wl_signal_add(&device->touch->events.up, &tstate->up); + wl_signal_add(&tstate->wlr_touch->events.up, &tstate->up); wl_list_insert(&sample->touch, &tstate->link); break; default: diff --git a/include/wlr/types/wlr_input_device.h b/include/wlr/types/wlr_input_device.h index 8c360aab7..0bbf517bc 100644 --- a/include/wlr/types/wlr_input_device.h +++ b/include/wlr/types/wlr_input_device.h @@ -30,17 +30,6 @@ struct wlr_input_device { unsigned int vendor, product; char *name; - /* wlr_input_device.type determines which of these is valid */ - union { - void *_device; - struct wlr_keyboard *keyboard; - struct wlr_pointer *pointer; - struct wlr_switch *switch_device; - struct wlr_touch *touch; - struct wlr_tablet *tablet; - struct wlr_tablet_pad *tablet_pad; - }; - struct { struct wl_signal destroy; } events; diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index 6a7eff810..39449aea4 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -101,6 +101,14 @@ struct wlr_keyboard_key_event { enum wl_keyboard_key_state state; }; +/** + * Get a struct wlr_keyboard from a struct wlr_input_device. + * + * Asserts that the input device is a keyboard. + */ +struct wlr_keyboard *wlr_keyboard_from_input_device( + struct wlr_input_device *input_device); + bool wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); diff --git a/include/wlr/types/wlr_pointer.h b/include/wlr/types/wlr_pointer.h index 17ab258a9..73e641fc4 100644 --- a/include/wlr/types/wlr_pointer.h +++ b/include/wlr/types/wlr_pointer.h @@ -145,4 +145,12 @@ struct wlr_pointer_hold_end_event { bool cancelled; }; +/** + * Get a struct wlr_pointer from a struct wlr_input_device. + * + * Asserts that the input device is a pointer. + */ +struct wlr_pointer *wlr_pointer_from_input_device( + struct wlr_input_device *input_device); + #endif diff --git a/include/wlr/types/wlr_switch.h b/include/wlr/types/wlr_switch.h index e26c9a3f0..b560f0baa 100644 --- a/include/wlr/types/wlr_switch.h +++ b/include/wlr/types/wlr_switch.h @@ -43,4 +43,12 @@ struct wlr_switch_toggle_event { enum wlr_switch_state switch_state; }; +/** + * Get a struct wlr_switch from a struct wlr_input_device. + * + * Asserts that the input device is a switch. + */ +struct wlr_switch *wlr_switch_from_input_device( + struct wlr_input_device *input_device); + #endif diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index 32a3231db..f19505a97 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -92,4 +92,12 @@ struct wlr_tablet_pad_strip_event { unsigned int mode; }; +/** + * Get a struct wlr_tablet_pad from a struct wlr_input_device. + * + * Asserts that the input device is a tablet pad. + */ +struct wlr_tablet_pad *wlr_tablet_pad_from_input_device( + struct wlr_input_device *); + #endif diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index ec0fc42a8..495c7094a 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -144,4 +144,12 @@ struct wlr_tablet_tool_button_event { enum wlr_button_state state; }; +/** + * Get a struct wlr_tablet from a struct wlr_input_device. + * + * Asserts that the input device is a tablet tool. + */ +struct wlr_tablet *wlr_tablet_from_input_device( + struct wlr_input_device *input_device); + #endif diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 0d2a27b6b..da294f765 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -62,4 +62,12 @@ struct wlr_touch_cancel_event { int32_t touch_id; }; +/** + * Get a struct wlr_touch from a struct wlr_input_device. + * + * Asserts that the input device is a touch device. + */ +struct wlr_touch *wlr_touch_from_input_device( + struct wlr_input_device *input_device); + #endif diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index f96fe7919..2b58a4b5c 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -238,10 +238,12 @@ static void keyboard_handle_destroy(struct wl_listener *listener, void *data) { static void server_new_keyboard(struct tinywl_server *server, struct wlr_input_device *device) { + struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(device); + struct tinywl_keyboard *keyboard = calloc(1, sizeof(struct tinywl_keyboard)); keyboard->server = server; - keyboard->wlr_keyboard = device->keyboard; + keyboard->wlr_keyboard = wlr_keyboard; /* We need to prepare an XKB keymap and assign it to the keyboard. This * assumes the defaults (e.g. layout = "us"). */ @@ -249,16 +251,16 @@ static void server_new_keyboard(struct tinywl_server *server, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL, XKB_KEYMAP_COMPILE_NO_FLAGS); - wlr_keyboard_set_keymap(device->keyboard, keymap); + wlr_keyboard_set_keymap(wlr_keyboard, keymap); xkb_keymap_unref(keymap); xkb_context_unref(context); - wlr_keyboard_set_repeat_info(device->keyboard, 25, 600); + wlr_keyboard_set_repeat_info(wlr_keyboard, 25, 600); /* Here we set up listeners for keyboard events. */ keyboard->modifiers.notify = keyboard_handle_modifiers; - wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers); + wl_signal_add(&wlr_keyboard->events.modifiers, &keyboard->modifiers); keyboard->key.notify = keyboard_handle_key; - wl_signal_add(&device->keyboard->events.key, &keyboard->key); + wl_signal_add(&wlr_keyboard->events.key, &keyboard->key); keyboard->destroy.notify = keyboard_handle_destroy; wl_signal_add(&device->events.destroy, &keyboard->destroy); diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index a468a1248..a7ac9ef8f 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -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; diff --git a/types/tablet_v2/wlr_tablet_v2_tablet.c b/types/tablet_v2/wlr_tablet_v2_tablet.c index b9189a26a..38668fda1 100644 --- a/types/tablet_v2/wlr_tablet_v2_tablet.c +++ b/types/tablet_v2/wlr_tablet_v2_tablet.c @@ -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; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index cd50e61e7..fd3ae5f5e 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -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; } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 2a82cfa8e..4d866d007 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -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); diff --git a/types/wlr_pointer.c b/types/wlr_pointer.c index e4d39f6af..be505b6c4 100644 --- a/types/wlr_pointer.c +++ b/types/wlr_pointer.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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); diff --git a/types/wlr_switch.c b/types/wlr_switch.c index 3b05ec6c0..5a2083ff2 100644 --- a/types/wlr_switch.c +++ b/types/wlr_switch.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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); diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index 353b4d431..34c81301c 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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); diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c index 7d8eb4187..a25b71a6e 100644 --- a/types/wlr_tablet_tool.c +++ b/types/wlr_tablet_tool.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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); diff --git a/types/wlr_touch.c b/types/wlr_touch.c index 28fec1982..d6285180e 100644 --- a/types/wlr_touch.c +++ b/types/wlr_touch.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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); diff --git a/types/wlr_virtual_keyboard_v1.c b/types/wlr_virtual_keyboard_v1.c index 791557dbc..2d313575f 100644 --- a/types/wlr_virtual_keyboard_v1.c +++ b/types/wlr_virtual_keyboard_v1.c @@ -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, diff --git a/types/wlr_virtual_pointer_v1.c b/types/wlr_virtual_pointer_v1.c index 931545afe..f1fea0f02 100644 --- a/types/wlr_virtual_pointer_v1.c +++ b/types/wlr_virtual_pointer_v1.c @@ -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,