diff options
author | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-01-31 10:53:58 -0500 |
---|---|---|
committer | Kirill Primak <vyivel@eclair.cafe> | 2022-02-21 17:11:32 +0000 |
commit | 0f3b38365d07bb3e65b5ce2ec265453115276d1d (patch) | |
tree | f427995f384fd7fca1d1289cfdb067a92138afa8 | |
parent | d5480efc7a03641600df411dea93308e5edc8b27 (diff) |
types/wlr_switch: add base wlr_input_device
wlr_switch owns its wlr_input_device. It will be initialized when the
switch is initialized, and finished when the switch is destroyed.
-rw-r--r-- | backend/libinput/switch.c | 7 | ||||
-rw-r--r-- | include/wlr/interfaces/wlr_switch.h | 2 | ||||
-rw-r--r-- | include/wlr/types/wlr_switch.h | 2 | ||||
-rw-r--r-- | types/wlr_switch.c | 8 |
4 files changed, 15 insertions, 4 deletions
diff --git a/backend/libinput/switch.c b/backend/libinput/switch.c index a9c33d3a..9562e185 100644 --- a/backend/libinput/switch.c +++ b/backend/libinput/switch.c @@ -16,8 +16,11 @@ struct wlr_switch *create_libinput_switch( wlr_log(WLR_ERROR, "Unable to allocate wlr_switch"); return NULL; } - wlr_switch_init(wlr_switch, NULL); - wlr_log(WLR_DEBUG, "Created switch for device %s", libinput_device_get_name(libinput_dev)); + const char *name = libinput_device_get_name(libinput_dev); + wlr_switch_init(wlr_switch, NULL, 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); return wlr_switch; } diff --git a/include/wlr/interfaces/wlr_switch.h b/include/wlr/interfaces/wlr_switch.h index 83a1365b..cce55f98 100644 --- a/include/wlr/interfaces/wlr_switch.h +++ b/include/wlr/interfaces/wlr_switch.h @@ -16,7 +16,7 @@ struct wlr_switch_impl { }; void wlr_switch_init(struct wlr_switch *switch_device, - struct wlr_switch_impl *impl); + struct wlr_switch_impl *impl, const char *name); void wlr_switch_destroy(struct wlr_switch *switch_device); #endif diff --git a/include/wlr/types/wlr_switch.h b/include/wlr/types/wlr_switch.h index 93db04c5..a0b9562f 100644 --- a/include/wlr/types/wlr_switch.h +++ b/include/wlr/types/wlr_switch.h @@ -16,6 +16,8 @@ struct wlr_switch_impl; struct wlr_switch { + struct wlr_input_device base; + struct wlr_switch_impl *impl; struct { diff --git a/types/wlr_switch.c b/types/wlr_switch.c index 248997a0..44a004e2 100644 --- a/types/wlr_switch.c +++ b/types/wlr_switch.c @@ -1,11 +1,16 @@ #include <stdlib.h> #include <string.h> #include <wayland-server-core.h> +#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_switch.h> #include <wlr/types/wlr_switch.h> void wlr_switch_init(struct wlr_switch *switch_device, - struct wlr_switch_impl *impl) { + struct wlr_switch_impl *impl, const char *name) { + wlr_input_device_init(&switch_device->base, WLR_INPUT_DEVICE_SWITCH, NULL, + name); + switch_device->base.switch_device = switch_device; + switch_device->impl = impl; wl_signal_init(&switch_device->events.toggle); } @@ -14,6 +19,7 @@ void wlr_switch_destroy(struct wlr_switch *switch_device) { if (!switch_device) { return; } + wlr_input_device_finish(&switch_device->base); if (switch_device->impl && switch_device->impl->destroy) { switch_device->impl->destroy(switch_device); } else { |