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

@ -228,22 +228,22 @@ struct libinput_device *wlr_libinput_get_device_handle(
struct wlr_libinput_input_device *dev = NULL; struct wlr_libinput_input_device *dev = NULL;
switch (wlr_dev->type) { switch (wlr_dev->type) {
case WLR_INPUT_DEVICE_KEYBOARD: case WLR_INPUT_DEVICE_KEYBOARD:
dev = device_from_keyboard(wlr_dev->keyboard); dev = device_from_keyboard(wlr_keyboard_from_input_device(wlr_dev));
break; break;
case WLR_INPUT_DEVICE_POINTER: case WLR_INPUT_DEVICE_POINTER:
dev = device_from_pointer(wlr_dev->pointer); dev = device_from_pointer(wlr_pointer_from_input_device(wlr_dev));
break; break;
case WLR_INPUT_DEVICE_SWITCH: 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; break;
case WLR_INPUT_DEVICE_TOUCH: case WLR_INPUT_DEVICE_TOUCH:
dev = device_from_touch(wlr_dev->touch); dev = device_from_touch(wlr_touch_from_input_device(wlr_dev));
break; break;
case WLR_INPUT_DEVICE_TABLET_TOOL: 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; break;
case WLR_INPUT_DEVICE_TABLET_PAD: 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; break;
} }
return dev->handle; return dev->handle;

View File

@ -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) { bool wlr_input_device_is_libinput(struct wlr_input_device *wlr_dev) {
switch (wlr_dev->type) { switch (wlr_dev->type) {
case WLR_INPUT_DEVICE_KEYBOARD: 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: 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: 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: 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: 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: 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: default:
return false; return false;
} }

View File

@ -280,15 +280,15 @@ void destroy_wl_seats(struct wlr_wl_backend *wl) {
bool wlr_input_device_is_wl(struct wlr_input_device *dev) { bool wlr_input_device_is_wl(struct wlr_input_device *dev) {
switch (dev->type) { switch (dev->type) {
case WLR_INPUT_DEVICE_KEYBOARD: 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: 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: 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: 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: 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: default:
return false; return false;
} }

View File

@ -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) { bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) {
switch (wlr_dev->type) { switch (wlr_dev->type) {
case WLR_INPUT_DEVICE_KEYBOARD: 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: 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: 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: default:
return false; return false;
} }

View File

@ -64,7 +64,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;

View File

@ -45,7 +45,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;

View File

@ -70,7 +70,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *state; struct sample_state *state;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->state = state;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;

View File

@ -39,7 +39,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;

View File

@ -44,7 +44,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;

View File

@ -35,7 +35,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = struct sample_keyboard *keyboard =
calloc(1, sizeof(struct sample_keyboard)); calloc(1, sizeof(struct sample_keyboard));
keyboard->device = device; keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
keyboard->sample = sample; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;

View File

@ -43,7 +43,7 @@ struct sample_state {
struct tablet_tool_state { struct tablet_tool_state {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_tablet *wlr_tablet;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener axis; struct wl_listener axis;
struct wl_listener proximity; struct wl_listener proximity;
@ -55,7 +55,7 @@ struct tablet_tool_state {
struct tablet_pad_state { struct tablet_pad_state {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_tablet_pad *wlr_tablet_pad;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener button; struct wl_listener button;
struct wl_listener ring; struct wl_listener ring;
@ -72,7 +72,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;
case WLR_INPUT_DEVICE_TABLET_PAD:; case WLR_INPUT_DEVICE_TABLET_PAD:;
struct tablet_pad_state *pstate = calloc(sizeof(struct tablet_pad_state), 1); 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->sample = sample;
pstate->destroy.notify = tablet_pad_destroy_notify; pstate->destroy.notify = tablet_pad_destroy_notify;
wl_signal_add(&device->events.destroy, &pstate->destroy); wl_signal_add(&device->events.destroy, &pstate->destroy);
pstate->button.notify = tablet_pad_button_notify; 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; 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); wl_list_insert(&sample->tablet_pads, &pstate->link);
break; break;
case WLR_INPUT_DEVICE_TABLET_TOOL:; 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 ? sample->width_mm = tablet->width_mm == 0 ?
20 : tablet->width_mm; 20 : tablet->width_mm;
sample->height_mm = tablet->height_mm == 0 ? sample->height_mm = tablet->height_mm == 0 ?
10 : tablet->height_mm; 10 : tablet->height_mm;
struct tablet_tool_state *tstate = calloc(sizeof(struct tablet_tool_state), 1); struct tablet_tool_state *tstate = calloc(sizeof(struct tablet_tool_state), 1);
tstate->device = device; tstate->wlr_tablet = tablet;
tstate->sample = sample; tstate->sample = sample;
tstate->destroy.notify = tablet_tool_destroy_notify; tstate->destroy.notify = tablet_tool_destroy_notify;
wl_signal_add(&device->events.destroy, &tstate->destroy); wl_signal_add(&device->events.destroy, &tstate->destroy);
tstate->axis.notify = tablet_tool_axis_notify; 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; 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; 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); wl_list_insert(&sample->tablet_tools, &tstate->link);
break; break;
default: default:

View File

@ -41,7 +41,7 @@ struct touch_point {
struct touch_state { struct touch_state {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_touch *wlr_touch;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener down; struct wl_listener down;
struct wl_listener up; struct wl_listener up;
@ -59,7 +59,7 @@ struct sample_output {
struct sample_keyboard { struct sample_keyboard {
struct sample_state *sample; struct sample_state *sample;
struct wlr_input_device *device; struct wlr_keyboard *wlr_keyboard;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; 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; struct wlr_keyboard_key_event *event = data;
uint32_t keycode = event->keycode + 8; uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms; 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); keycode, &syms);
for (int i = 0; i < nsyms; i++) { for (int i = 0; i < nsyms; i++) {
xkb_keysym_t sym = syms[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) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:; case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_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; keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);
keyboard->destroy.notify = keyboard_destroy_notify; 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; keyboard->key.notify = keyboard_key_notify;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!context) { 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"); wlr_log(WLR_ERROR, "Failed to create XKB keymap");
exit(1); exit(1);
} }
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(keyboard->wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);
break; break;
case WLR_INPUT_DEVICE_TOUCH:; case WLR_INPUT_DEVICE_TOUCH:;
struct touch_state *tstate = calloc(sizeof(struct touch_state), 1); 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->sample = sample;
tstate->destroy.notify = touch_destroy_notify; tstate->destroy.notify = touch_destroy_notify;
wl_signal_add(&device->events.destroy, &tstate->destroy); wl_signal_add(&device->events.destroy, &tstate->destroy);
tstate->down.notify = touch_down_notify; 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; 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; 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); wl_list_insert(&sample->touch, &tstate->link);
break; break;
default: default:

View File

@ -30,17 +30,6 @@ struct wlr_input_device {
unsigned int vendor, product; unsigned int vendor, product;
char *name; 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 {
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;

View File

@ -101,6 +101,14 @@ struct wlr_keyboard_key_event {
enum wl_keyboard_key_state state; 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, bool wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
struct xkb_keymap *keymap); struct xkb_keymap *keymap);

View File

@ -145,4 +145,12 @@ struct wlr_pointer_hold_end_event {
bool cancelled; 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 #endif

View File

@ -43,4 +43,12 @@ struct wlr_switch_toggle_event {
enum wlr_switch_state switch_state; 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 #endif

View File

@ -92,4 +92,12 @@ struct wlr_tablet_pad_strip_event {
unsigned int mode; 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 #endif

View File

@ -144,4 +144,12 @@ struct wlr_tablet_tool_button_event {
enum wlr_button_state state; 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 #endif

View File

@ -62,4 +62,12 @@ struct wlr_touch_cancel_event {
int32_t touch_id; 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 #endif

View File

@ -238,10 +238,12 @@ static void keyboard_handle_destroy(struct wl_listener *listener, void *data) {
static void server_new_keyboard(struct tinywl_server *server, static void server_new_keyboard(struct tinywl_server *server,
struct wlr_input_device *device) { struct wlr_input_device *device) {
struct wlr_keyboard *wlr_keyboard = wlr_keyboard_from_input_device(device);
struct tinywl_keyboard *keyboard = struct tinywl_keyboard *keyboard =
calloc(1, sizeof(struct tinywl_keyboard)); calloc(1, sizeof(struct tinywl_keyboard));
keyboard->server = server; 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 /* We need to prepare an XKB keymap and assign it to the keyboard. This
* assumes the defaults (e.g. layout = "us"). */ * 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, struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, NULL,
XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_COMPILE_NO_FLAGS);
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(wlr_keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); 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. */ /* Here we set up listeners for keyboard events. */
keyboard->modifiers.notify = keyboard_handle_modifiers; 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; 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; keyboard->destroy.notify = keyboard_handle_destroy;
wl_signal_add(&device->events.destroy, &keyboard->destroy); wl_signal_add(&device->events.destroy, &keyboard->destroy);

View File

@ -376,7 +376,7 @@ struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create(
if (!seat) { if (!seat) {
return NULL; 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)); struct wlr_tablet_v2_tablet_pad *pad = calloc(1, sizeof(struct wlr_tablet_v2_tablet_pad));
if (!pad) { if (!pad) {
return NULL; return NULL;

View File

@ -60,7 +60,7 @@ struct wlr_tablet_v2_tablet *wlr_tablet_create(
if (!seat) { if (!seat) {
return NULL; 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)); struct wlr_tablet_v2_tablet *tablet = calloc(1, sizeof(struct wlr_tablet_v2_tablet));
if (!tablet) { if (!tablet) {
return NULL; return NULL;

View File

@ -648,75 +648,78 @@ static struct wlr_cursor_device *cursor_device_create(
c_device->destroy.notify = handle_device_destroy; c_device->destroy.notify = handle_device_destroy;
if (device->type == WLR_INPUT_DEVICE_POINTER) { 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; 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);
c_device->motion_absolute.notify = handle_pointer_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; 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; 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; 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; 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; 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; 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; 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; 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; 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; 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; c_device->hold_end.notify = handle_pointer_hold_end;
} else if (device->type == WLR_INPUT_DEVICE_TOUCH) { } 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; 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; 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; 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; 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; c_device->touch_frame.notify = handle_touch_frame;
} else if (device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { } else if (device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
wl_signal_add(&device->tablet->events.tip, struct wlr_tablet *tablet = wlr_tablet_from_input_device(device);
&c_device->tablet_tool_tip);
wl_signal_add(&tablet->events.tip, &c_device->tablet_tool_tip);
c_device->tablet_tool_tip.notify = handle_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);
c_device->tablet_tool_proximity.notify = handle_tablet_tool_proximity; c_device->tablet_tool_proximity.notify = handle_tablet_tool_proximity;
wl_signal_add(&device->tablet->events.axis, wl_signal_add(&tablet->events.axis, &c_device->tablet_tool_axis);
&c_device->tablet_tool_axis);
c_device->tablet_tool_axis.notify = handle_tablet_tool_axis; c_device->tablet_tool_axis.notify = handle_tablet_tool_axis;
wl_signal_add(&device->tablet->events.button, wl_signal_add(&tablet->events.button, &c_device->tablet_tool_button);
&c_device->tablet_tool_button);
c_device->tablet_tool_button.notify = handle_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/signal.h"
#include "util/time.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) { void keyboard_led_update(struct wlr_keyboard *keyboard) {
if (keyboard->xkb_state == NULL) { if (keyboard->xkb_state == NULL) {
return; return;
@ -118,7 +124,6 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
const struct wlr_keyboard_impl *impl, const char *name) { const struct wlr_keyboard_impl *impl, const char *name) {
memset(kb, 0, sizeof(*kb)); memset(kb, 0, sizeof(*kb));
wlr_input_device_init(&kb->base, WLR_INPUT_DEVICE_KEYBOARD, name); wlr_input_device_init(&kb->base, WLR_INPUT_DEVICE_KEYBOARD, name);
kb->base.keyboard = kb;
kb->impl = impl; kb->impl = impl;
wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.key);

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
@ -6,11 +7,16 @@
#include "interfaces/wlr_input_device.h" #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, void wlr_touch_init(struct wlr_touch *touch,
const struct wlr_touch_impl *impl, const char *name) { const struct wlr_touch_impl *impl, const char *name) {
memset(touch, 0, sizeof(*touch)); memset(touch, 0, sizeof(*touch));
wlr_input_device_init(&touch->base, WLR_INPUT_DEVICE_TOUCH, name); wlr_input_device_init(&touch->base, WLR_INPUT_DEVICE_TOUCH, name);
touch->base.touch = touch;
touch->impl = impl; touch->impl = impl;
wl_signal_init(&touch->events.down); 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_virtual_keyboard_v1 *wlr_input_device_get_virtual_keyboard(
struct wlr_input_device *wlr_dev) { struct wlr_input_device *wlr_dev) {
if (wlr_dev->type != WLR_INPUT_DEVICE_KEYBOARD if (wlr_dev->type != WLR_INPUT_DEVICE_KEYBOARD) {
|| wlr_dev->keyboard->impl != &keyboard_impl) {
return NULL; 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, 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) { if (pointer == NULL) {
return; return;
} }
struct wlr_input_device *wlr_dev = &pointer->pointer.base;
for (size_t i = 0; for (size_t i = 0;
i < sizeof(pointer->axis_valid) / sizeof(pointer->axis_valid[0]); i < sizeof(pointer->axis_valid) / sizeof(pointer->axis_valid[0]);
++i) { ++i) {
if (pointer->axis_valid[i]) { if (pointer->axis_valid[i]) {
/* Deliver pending axis event */ /* 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]); &pointer->axis_event[i]);
memset(&pointer->axis_event[i], 0, sizeof(pointer->axis_event[i])); memset(&pointer->axis_event[i], 0, sizeof(pointer->axis_event[i]));
pointer->axis_valid[i] = false; 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, static void virtual_pointer_axis_source(struct wl_client *client,