diff options
author | emersion <contact@emersion.fr> | 2018-12-15 19:54:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-15 19:54:25 +0100 |
commit | 6d4bfa3226123e958ff2bdc4f226489cba49f84d (patch) | |
tree | 256c7c3ded68d4b95ed09f7a2fbfd5bc67dbcee9 /backend | |
parent | 8a56b96c5516ee089b7561949aac4f83e5b94808 (diff) | |
parent | f8129ecbc5147a62d93d6bac5e61e5ce79d89667 (diff) |
Merge pull request #1377 from tokyovigilante/switch-events
Add support for libinput_switch input devices
Diffstat (limited to 'backend')
-rw-r--r-- | backend/headless/input_device.c | 8 | ||||
-rw-r--r-- | backend/libinput/events.c | 15 | ||||
-rw-r--r-- | backend/libinput/switch.c | 55 | ||||
-rw-r--r-- | backend/meson.build | 1 |
4 files changed, 78 insertions, 1 deletions
diff --git a/backend/headless/input_device.c b/backend/headless/input_device.c index ba251dd7..827c6ee4 100644 --- a/backend/headless/input_device.c +++ b/backend/headless/input_device.c @@ -6,6 +6,7 @@ #include <wlr/interfaces/wlr_tablet_pad.h> #include <wlr/interfaces/wlr_tablet_tool.h> #include <wlr/interfaces/wlr_touch.h> +#include <wlr/interfaces/wlr_switch.h> #include <wlr/util/log.h> #include "backend/headless.h" #include "util/signal.h" @@ -76,6 +77,13 @@ struct wlr_input_device *wlr_headless_add_input_device( } wlr_tablet_pad_init(wlr_device->tablet_pad, NULL); break; + case WLR_INPUT_DEVICE_SWITCH: + wlr_device->lid_switch = calloc(1, sizeof(struct wlr_switch)); + if (wlr_device->lid_switch == NULL) { + wlr_log(WLR_ERROR, "Unable to allocate wlr_switch"); + goto error; + } + wlr_switch_init(wlr_device->lid_switch, NULL); } wl_list_insert(&backend->input_devices, &wlr_device->link); diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 9ce62d6f..a7a6c114 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -169,7 +169,17 @@ static void handle_device_added(struct wlr_libinput_backend *backend, } if (libinput_device_has_capability( libinput_dev, LIBINPUT_DEVICE_CAP_SWITCH)) { - // TODO + struct wlr_input_device *wlr_dev = allocate_device(backend, + libinput_dev, wlr_devices, WLR_INPUT_DEVICE_SWITCH); + if (!wlr_dev) { + goto fail; + } + wlr_dev->lid_switch = create_libinput_switch(libinput_dev); + if (!wlr_dev->lid_switch) { + free(wlr_dev); + goto fail; + } + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } if (!wl_list_empty(wlr_devices)) { @@ -274,6 +284,9 @@ void handle_libinput_event(struct wlr_libinput_backend *backend, case LIBINPUT_EVENT_TABLET_PAD_STRIP: handle_tablet_pad_strip(event, libinput_dev); break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + handle_switch_toggle(event, libinput_dev); + break; default: wlr_log(WLR_DEBUG, "Unknown libinput event %d", event_type); break; diff --git a/backend/libinput/switch.c b/backend/libinput/switch.c new file mode 100644 index 00000000..393460b0 --- /dev/null +++ b/backend/libinput/switch.c @@ -0,0 +1,55 @@ +#include <assert.h> +#include <libinput.h> +#include <stdlib.h> +#include <wlr/backend/session.h> +#include <wlr/interfaces/wlr_switch.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/util/log.h> +#include "backend/libinput.h" +#include "util/signal.h" + +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; + } + wlr_switch_init(wlr_switch, NULL); + wlr_log(WLR_DEBUG, "Created switch for device %s", libinput_device_get_name(libinput_dev)); + return wlr_switch; +} + +void handle_switch_toggle(struct libinput_event *event, + struct libinput_device *libinput_dev) { + 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 = + libinput_event_get_switch_event (event); + struct wlr_event_switch_toggle wlr_event = { 0 }; + wlr_event.device = wlr_dev; + switch (libinput_event_switch_get_switch(sevent)) { + case LIBINPUT_SWITCH_LID: + wlr_event.switch_type = WLR_SWITCH_TYPE_LID; + break; + case LIBINPUT_SWITCH_TABLET_MODE: + wlr_event.switch_type = WLR_SWITCH_TYPE_TABLET_MODE; + break; + } + switch (libinput_event_switch_get_switch_state(sevent)) { + case LIBINPUT_SWITCH_STATE_OFF: + wlr_event.switch_state = WLR_SWITCH_STATE_OFF; + break; + case LIBINPUT_SWITCH_STATE_ON: + wlr_event.switch_state = WLR_SWITCH_STATE_ON; + break; + } + wlr_event.time_msec = + usec_to_msec(libinput_event_switch_get_time_usec(sevent)); + wlr_signal_emit_safe(&wlr_dev->lid_switch->events.toggle, &wlr_event); +} diff --git a/backend/meson.build b/backend/meson.build index 03f8ea7d..bf9b4f83 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -15,6 +15,7 @@ backend_files = files( 'libinput/events.c', 'libinput/keyboard.c', 'libinput/pointer.c', + 'libinput/switch.c', 'libinput/tablet_pad.c', 'libinput/tablet_tool.c', 'libinput/touch.c', |