backend/libinput: remove wlr_input_device_impl

master
Simon Zeni 3 years ago
parent 887516d004
commit 91ba28e020

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

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

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

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

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

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

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

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

@ -5,7 +5,12 @@
#include <wayland-server-core.h>
#include <wlr/backend/interface.h>
#include <wlr/backend/libinput.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_switch.h>
#include <wlr/interfaces/wlr_tablet_pad.h>
#include <wlr/interfaces/wlr_tablet_tool.h>
#include <wlr/interfaces/wlr_touch.h>
#include <wlr/types/wlr_input_device.h>
struct wlr_libinput_backend {
@ -39,6 +44,15 @@ struct wlr_input_device *get_appropriate_device(
enum wlr_input_device_type desired_type,
struct libinput_device *device);
void destroy_libinput_input_device(struct wlr_libinput_input_device *dev);
extern const struct wlr_keyboard_impl libinput_keyboard_impl;
extern const struct wlr_pointer_impl libinput_pointer_impl;
extern const struct wlr_switch_impl libinput_switch_impl;
extern const struct wlr_tablet_impl libinput_tablet_impl;
extern const struct wlr_tablet_pad_impl libinput_tablet_pad_impl;
extern const struct wlr_touch_impl libinput_touch_impl;
struct wlr_keyboard *create_libinput_keyboard(
struct libinput_device *device);
void handle_keyboard_key(struct libinput_event *event,

Loading…
Cancel
Save