diff options
author | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-02-09 16:03:12 -0500 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-02-21 16:48:43 -0500 |
commit | 91ba28e020092089eb9cc960530355de68c60a3d (patch) | |
tree | fee441c8caab6771d875abeac46aa776edeabc0e /backend | |
parent | 887516d004ca5c5f35e99fd36f4b30f649f1c2f8 (diff) |
backend/libinput: remove wlr_input_device_impl
Diffstat (limited to 'backend')
-rw-r--r-- | backend/libinput/backend.c | 2 | ||||
-rw-r--r-- | backend/libinput/events.c | 46 | ||||
-rw-r--r-- | backend/libinput/keyboard.c | 9 | ||||
-rw-r--r-- | backend/libinput/pointer.c | 5 | ||||
-rw-r--r-- | backend/libinput/switch.c | 4 | ||||
-rw-r--r-- | backend/libinput/tablet_pad.c | 4 | ||||
-rw-r--r-- | backend/libinput/tablet_tool.c | 9 | ||||
-rw-r--r-- | backend/libinput/touch.c | 4 |
8 files changed, 49 insertions, 34 deletions
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 4191f350..8023807f 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -145,7 +145,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { wl_array_for_each(wlr_devices_ptr, &backend->wlr_device_lists) { struct wlr_libinput_input_device *dev, *tmp; wl_list_for_each_safe(dev, tmp, *wlr_devices_ptr, link) { - wlr_input_device_destroy(&dev->wlr_input_device); + destroy_libinput_input_device(dev); } free(*wlr_devices_ptr); } diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 1f28b94a..67ca49d5 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -10,12 +10,6 @@ #include "util/array.h" #include "util/signal.h" -static struct wlr_libinput_input_device *get_libinput_device_from_device( - struct wlr_input_device *wlr_dev) { - assert(wlr_input_device_is_libinput(wlr_dev)); - return (struct wlr_libinput_input_device *)wlr_dev; -} - struct wlr_input_device *get_appropriate_device( enum wlr_input_device_type desired_type, struct libinput_device *libinput_dev) { @@ -32,18 +26,23 @@ struct wlr_input_device *get_appropriate_device( return NULL; } -static void input_device_destroy(struct wlr_input_device *wlr_dev) { - struct wlr_libinput_input_device *dev = - get_libinput_device_from_device(wlr_dev); +void destroy_libinput_input_device(struct wlr_libinput_input_device *dev) +{ + /** + * TODO remove the redundant wlr_input_device from wlr_libinput_input_device + * wlr_libinput_input_device::wlr_input_device is not owned by its input + * device type, which means we have 2 wlr_input_device to cleanup + */ + if (dev->wlr_input_device._device) { + wlr_input_device_destroy(&dev->wlr_input_device); + } + wlr_input_device_finish(&dev->wlr_input_device); + libinput_device_unref(dev->handle); wl_list_remove(&dev->link); free(dev); } -static const struct wlr_input_device_impl input_device_impl = { - .destroy = input_device_destroy, -}; - static struct wlr_input_device *allocate_device( struct wlr_libinput_backend *backend, struct libinput_device *libinput_dev, struct wl_list *wlr_devices, @@ -64,14 +63,29 @@ static struct wlr_input_device *allocate_device( wl_list_insert(wlr_devices, &dev->link); dev->handle = libinput_dev; libinput_device_ref(libinput_dev); - wlr_input_device_init(wlr_dev, type, &input_device_impl, name); + wlr_input_device_init(wlr_dev, type, NULL, name); wlr_dev->vendor = libinput_device_get_id_vendor(libinput_dev); wlr_dev->product = libinput_device_get_id_product(libinput_dev); return wlr_dev; } bool wlr_input_device_is_libinput(struct wlr_input_device *wlr_dev) { - return wlr_dev->impl == &input_device_impl; + switch (wlr_dev->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + return wlr_dev->keyboard->impl == &libinput_keyboard_impl; + case WLR_INPUT_DEVICE_POINTER: + return wlr_dev->pointer->impl == &libinput_pointer_impl; + case WLR_INPUT_DEVICE_TOUCH: + return wlr_dev->touch->impl == &libinput_touch_impl; + case WLR_INPUT_DEVICE_TABLET_TOOL: + return wlr_dev->tablet->impl == &libinput_tablet_impl; + case WLR_INPUT_DEVICE_TABLET_PAD: + return wlr_dev->tablet_pad->impl == &libinput_tablet_pad_impl; + case WLR_INPUT_DEVICE_SWITCH: + return wlr_dev->switch_device->impl == &libinput_switch_impl; + default: + return false; + } } static void handle_device_added(struct wlr_libinput_backend *backend, @@ -216,7 +230,7 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, } struct wlr_libinput_input_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) { - wlr_input_device_destroy(&dev->wlr_input_device); + destroy_libinput_input_device(dev); } size_t i = 0; struct wl_list **ptr; diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index be5faf3e..9127217a 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -2,7 +2,6 @@ #include <libinput.h> #include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/interfaces/wlr_keyboard.h> #include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" @@ -12,11 +11,9 @@ struct wlr_libinput_keyboard { struct libinput_device *libinput_dev; }; -static const struct wlr_keyboard_impl impl; - static struct wlr_libinput_keyboard *get_libinput_keyboard_from_keyboard( struct wlr_keyboard *wlr_kb) { - assert(wlr_kb->impl == &impl); + assert(wlr_kb->impl == &libinput_keyboard_impl); return (struct wlr_libinput_keyboard *)wlr_kb; } @@ -33,7 +30,7 @@ static void keyboard_destroy(struct wlr_keyboard *wlr_kb) { free(kb); } -static const struct wlr_keyboard_impl impl = { +const struct wlr_keyboard_impl libinput_keyboard_impl = { .destroy = keyboard_destroy, .led_update = keyboard_set_leds }; @@ -50,7 +47,7 @@ struct wlr_keyboard *create_libinput_keyboard( libinput_device_led_update(libinput_dev, 0); struct wlr_keyboard *wlr_kb = &kb->wlr_keyboard; const char *name = libinput_device_get_name(libinput_dev); - wlr_keyboard_init(wlr_kb, &impl, name); + wlr_keyboard_init(wlr_kb, &libinput_keyboard_impl, name); wlr_kb->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_kb->base.product = libinput_device_get_id_product(libinput_dev); return wlr_kb; diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 305c43d9..706ace7b 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -2,12 +2,13 @@ #include <libinput.h> #include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/interfaces/wlr_pointer.h> #include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" #include "util/signal.h" +const struct wlr_pointer_impl libinput_pointer_impl = {0}; + struct wlr_pointer *create_libinput_pointer( struct libinput_device *libinput_dev) { assert(libinput_dev); @@ -17,7 +18,7 @@ struct wlr_pointer *create_libinput_pointer( return NULL; } const char *name = libinput_device_get_name(libinput_dev); - wlr_pointer_init(wlr_pointer, NULL, name); + wlr_pointer_init(wlr_pointer, &libinput_pointer_impl, name); wlr_pointer->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_pointer->base.product = libinput_device_get_id_product(libinput_dev); return wlr_pointer; diff --git a/backend/libinput/switch.c b/backend/libinput/switch.c index 9562e185..0e710f09 100644 --- a/backend/libinput/switch.c +++ b/backend/libinput/switch.c @@ -8,6 +8,8 @@ #include "backend/libinput.h" #include "util/signal.h" +const struct wlr_switch_impl libinput_switch_impl; + struct wlr_switch *create_libinput_switch( struct libinput_device *libinput_dev) { assert(libinput_dev); @@ -17,7 +19,7 @@ struct wlr_switch *create_libinput_switch( return NULL; } const char *name = libinput_device_get_name(libinput_dev); - wlr_switch_init(wlr_switch, NULL, name); + wlr_switch_init(wlr_switch, &libinput_switch_impl, name); wlr_log(WLR_DEBUG, "Created switch for device %s", name); wlr_switch->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_switch->base.product = libinput_device_get_id_product(libinput_dev); diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 2f1da363..50b8ad6e 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -66,6 +66,8 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad, wl_list_insert(&pad->groups, &group->link); } +const struct wlr_tablet_pad_impl libinput_tablet_pad_impl; + struct wlr_tablet_pad *create_libinput_tablet_pad( struct libinput_device *libinput_dev) { assert(libinput_dev); @@ -76,7 +78,7 @@ struct wlr_tablet_pad *create_libinput_tablet_pad( return NULL; } const char *name = libinput_device_get_name(libinput_dev); - wlr_tablet_pad_init(wlr_tablet_pad, NULL, name); + wlr_tablet_pad_init(wlr_tablet_pad, &libinput_tablet_pad_impl, name); wlr_tablet_pad->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_tablet_pad->base.product = libinput_device_get_id_product(libinput_dev); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 31803e81..373f87d7 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -14,10 +14,8 @@ #include "util/array.h" #include "util/signal.h" -static const struct wlr_tablet_impl tablet_impl; - static bool tablet_is_libinput(struct wlr_tablet *tablet) { - return tablet->impl == &tablet_impl; + return tablet->impl == &libinput_tablet_impl; } struct wlr_libinput_tablet_tool { @@ -42,7 +40,6 @@ static void destroy_tool(struct wlr_libinput_tablet_tool *tool) { free(tool); } - static void destroy_tablet(struct wlr_tablet *wlr_tablet) { assert(tablet_is_libinput(wlr_tablet)); struct wlr_libinput_tablet *tablet = @@ -60,7 +57,7 @@ static void destroy_tablet(struct wlr_tablet *wlr_tablet) { free(tablet); } -static const struct wlr_tablet_impl tablet_impl = { +const struct wlr_tablet_impl libinput_tablet_impl = { .destroy = destroy_tablet, }; @@ -77,7 +74,7 @@ struct wlr_tablet *create_libinput_tablet( struct wlr_tablet *wlr_tablet = &libinput_tablet->wlr_tablet; const char *name = libinput_device_get_name(libinput_dev); - wlr_tablet_init(wlr_tablet, &tablet_impl, name); + wlr_tablet_init(wlr_tablet, &libinput_tablet_impl, name); wlr_tablet->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_tablet->base.product = libinput_device_get_id_product(libinput_dev); diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index d1f99611..2e22a97a 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -8,6 +8,8 @@ #include "backend/libinput.h" #include "util/signal.h" +const struct wlr_touch_impl libinput_touch_impl; + struct wlr_touch *create_libinput_touch( struct libinput_device *libinput_dev) { assert(libinput_dev); @@ -17,7 +19,7 @@ struct wlr_touch *create_libinput_touch( return NULL; } const char *name = libinput_device_get_name(libinput_dev); - wlr_touch_init(wlr_touch, NULL, name); + wlr_touch_init(wlr_touch, &libinput_touch_impl, name); wlr_touch->base.vendor = libinput_device_get_id_vendor(libinput_dev); wlr_touch->base.product = libinput_device_get_id_product(libinput_dev); return wlr_touch; |