backend/libinput: rework switch interface
The wlr_libinput_input_device now owns its wlr_switch, instead of creating a new wlr_libinput_input_device for it.
This commit is contained in:
parent
d60cdad3ea
commit
d750c5ac67
|
@ -246,6 +246,9 @@ struct libinput_device *wlr_libinput_get_device_handle(
|
||||||
case WLR_INPUT_DEVICE_POINTER:
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
dev = device_from_pointer(wlr_dev->pointer);
|
dev = device_from_pointer(wlr_dev->pointer);
|
||||||
break;
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_SWITCH:
|
||||||
|
dev = device_from_switch(wlr_dev->switch_device);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dev = (struct wlr_libinput_input_device *)wlr_dev;
|
dev = (struct wlr_libinput_input_device *)wlr_dev;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -43,6 +43,9 @@ void destroy_libinput_input_device(struct wlr_libinput_input_device *dev)
|
||||||
if (dev->pointer.impl) {
|
if (dev->pointer.impl) {
|
||||||
wlr_pointer_destroy(&dev->pointer);
|
wlr_pointer_destroy(&dev->pointer);
|
||||||
}
|
}
|
||||||
|
if (dev->switch_device.impl) {
|
||||||
|
wlr_switch_destroy(&dev->switch_device);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libinput_device_unref(dev->handle);
|
libinput_device_unref(dev->handle);
|
||||||
|
@ -140,6 +143,14 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
|
||||||
dev_used = true;
|
dev_used = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (libinput_device_has_capability(
|
||||||
|
libinput_dev, LIBINPUT_DEVICE_CAP_SWITCH)) {
|
||||||
|
init_device_switch(dev);
|
||||||
|
wlr_signal_emit_safe(&backend->backend.events.new_input,
|
||||||
|
&dev->switch_device.base);
|
||||||
|
dev_used = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (dev_used) {
|
if (dev_used) {
|
||||||
wl_list_insert(&backend->devices, &dev->link);
|
wl_list_insert(&backend->devices, &dev->link);
|
||||||
return;
|
return;
|
||||||
|
@ -201,20 +212,6 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
|
||||||
libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) {
|
libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
if (libinput_device_has_capability(
|
|
||||||
libinput_dev, LIBINPUT_DEVICE_CAP_SWITCH)) {
|
|
||||||
struct wlr_input_device *wlr_dev = allocate_device(backend,
|
|
||||||
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_SWITCH);
|
|
||||||
if (!wlr_dev) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
wlr_dev->switch_device = create_libinput_switch(libinput_dev);
|
|
||||||
if (!wlr_dev->switch_device) {
|
|
||||||
free(wlr_dev);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wl_list_empty(wlr_devices)) {
|
if (!wl_list_empty(wlr_devices)) {
|
||||||
struct wl_list **dst = wl_array_add(&backend->wlr_device_lists, sizeof(wlr_devices));
|
struct wl_list **dst = wl_array_add(&backend->wlr_device_lists, sizeof(wlr_devices));
|
||||||
|
@ -343,7 +340,7 @@ void handle_libinput_event(struct wlr_libinput_backend *backend,
|
||||||
handle_tablet_pad_strip(event, libinput_dev);
|
handle_tablet_pad_strip(event, libinput_dev);
|
||||||
break;
|
break;
|
||||||
case LIBINPUT_EVENT_SWITCH_TOGGLE:
|
case LIBINPUT_EVENT_SWITCH_TOGGLE:
|
||||||
handle_switch_toggle(event, libinput_dev);
|
handle_switch_toggle(event, &dev->switch_device);
|
||||||
break;
|
break;
|
||||||
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
|
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
|
||||||
handle_pointer_swipe_begin(event, &dev->pointer);
|
handle_pointer_swipe_begin(event, &dev->pointer);
|
||||||
|
|
|
@ -1,43 +1,40 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libinput.h>
|
#include <libinput.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <wlr/backend/session.h>
|
|
||||||
#include <wlr/interfaces/wlr_switch.h>
|
#include <wlr/interfaces/wlr_switch.h>
|
||||||
#include <wlr/types/wlr_input_device.h>
|
|
||||||
#include <wlr/util/log.h>
|
|
||||||
#include "backend/libinput.h"
|
#include "backend/libinput.h"
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
const struct wlr_switch_impl libinput_switch_impl;
|
static void switch_destroy(struct wlr_switch *wlr_switch) {
|
||||||
|
/* wlr_switch belongs to the wlr_libinput_input_device */
|
||||||
struct wlr_switch *create_libinput_switch(
|
|
||||||
struct libinput_device *libinput_dev) {
|
|
||||||
assert(libinput_dev);
|
|
||||||
struct wlr_switch *wlr_switch = calloc(1, sizeof(struct wlr_switch));
|
|
||||||
if (!wlr_switch) {
|
|
||||||
wlr_log(WLR_ERROR, "Unable to allocate wlr_switch");
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
const char *name = libinput_device_get_name(libinput_dev);
|
|
||||||
|
const struct wlr_switch_impl libinput_switch_impl = {
|
||||||
|
.destroy = switch_destroy,
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_device_switch(struct wlr_libinput_input_device *dev) {
|
||||||
|
const char *name = libinput_device_get_name(dev->handle);
|
||||||
|
struct wlr_switch *wlr_switch = &dev->switch_device;
|
||||||
wlr_switch_init(wlr_switch, &libinput_switch_impl, 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(dev->handle);
|
||||||
wlr_switch->base.vendor = libinput_device_get_id_vendor(libinput_dev);
|
wlr_switch->base.product = libinput_device_get_id_product(dev->handle);
|
||||||
wlr_switch->base.product = libinput_device_get_id_product(libinput_dev);
|
}
|
||||||
return wlr_switch;
|
|
||||||
|
struct wlr_libinput_input_device *device_from_switch(
|
||||||
|
struct wlr_switch *wlr_switch) {
|
||||||
|
assert(wlr_switch->impl == &libinput_switch_impl);
|
||||||
|
|
||||||
|
struct wlr_libinput_input_device *dev =
|
||||||
|
wl_container_of(wlr_switch, dev, switch_device);
|
||||||
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_switch_toggle(struct libinput_event *event,
|
void handle_switch_toggle(struct libinput_event *event,
|
||||||
struct libinput_device *libinput_dev) {
|
struct wlr_switch *wlr_switch) {
|
||||||
struct wlr_input_device *wlr_dev =
|
|
||||||
get_appropriate_device(WLR_INPUT_DEVICE_SWITCH, libinput_dev);
|
|
||||||
if (!wlr_dev) {
|
|
||||||
wlr_log(WLR_DEBUG, "Got a switch event for a device with no switch?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
struct libinput_event_switch *sevent =
|
struct libinput_event_switch *sevent =
|
||||||
libinput_event_get_switch_event (event);
|
libinput_event_get_switch_event (event);
|
||||||
struct wlr_event_switch_toggle wlr_event = { 0 };
|
struct wlr_event_switch_toggle wlr_event = { 0 };
|
||||||
wlr_event.device = wlr_dev;
|
wlr_event.device = &wlr_switch->base;
|
||||||
switch (libinput_event_switch_get_switch(sevent)) {
|
switch (libinput_event_switch_get_switch(sevent)) {
|
||||||
case LIBINPUT_SWITCH_LID:
|
case LIBINPUT_SWITCH_LID:
|
||||||
wlr_event.switch_type = WLR_SWITCH_TYPE_LID;
|
wlr_event.switch_type = WLR_SWITCH_TYPE_LID;
|
||||||
|
@ -56,5 +53,5 @@ void handle_switch_toggle(struct libinput_event *event,
|
||||||
}
|
}
|
||||||
wlr_event.time_msec =
|
wlr_event.time_msec =
|
||||||
usec_to_msec(libinput_event_switch_get_time_usec(sevent));
|
usec_to_msec(libinput_event_switch_get_time_usec(sevent));
|
||||||
wlr_signal_emit_safe(&wlr_dev->switch_device->events.toggle, &wlr_event);
|
wlr_signal_emit_safe(&wlr_switch->events.toggle, &wlr_event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct wlr_libinput_input_device {
|
||||||
|
|
||||||
struct wlr_keyboard keyboard;
|
struct wlr_keyboard keyboard;
|
||||||
struct wlr_pointer pointer;
|
struct wlr_pointer pointer;
|
||||||
|
struct wlr_switch switch_device;
|
||||||
|
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
@ -89,10 +90,11 @@ void handle_pointer_hold_begin(struct libinput_event *event,
|
||||||
void handle_pointer_hold_end(struct libinput_event *event,
|
void handle_pointer_hold_end(struct libinput_event *event,
|
||||||
struct wlr_pointer *pointer);
|
struct wlr_pointer *pointer);
|
||||||
|
|
||||||
struct wlr_switch *create_libinput_switch(
|
void init_device_switch(struct wlr_libinput_input_device *dev);
|
||||||
struct libinput_device *device);
|
struct wlr_libinput_input_device *device_from_switch(
|
||||||
|
struct wlr_switch *switch_device);
|
||||||
void handle_switch_toggle(struct libinput_event *event,
|
void handle_switch_toggle(struct libinput_event *event,
|
||||||
struct libinput_device *device);
|
struct wlr_switch *switch_device);
|
||||||
|
|
||||||
struct wlr_touch *create_libinput_touch(
|
struct wlr_touch *create_libinput_touch(
|
||||||
struct libinput_device *device);
|
struct libinput_device *device);
|
||||||
|
|
Loading…
Reference in New Issue