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 /rootston/seat.c | |
parent | 8a56b96c5516ee089b7561949aac4f83e5b94808 (diff) | |
parent | f8129ecbc5147a62d93d6bac5e61e5ce79d89667 (diff) |
Merge pull request #1377 from tokyovigilante/switch-events
Add support for libinput_switch input devices
Diffstat (limited to 'rootston/seat.c')
-rw-r--r-- | rootston/seat.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/rootston/seat.c b/rootston/seat.c index e91278c5..dda2f8df 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -9,6 +9,7 @@ #include <wlr/config.h> #include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_layer_shell_v1.h> +#include "wlr/types/wlr_switch.h" #include <wlr/types/wlr_tablet_v2.h> #include <wlr/types/wlr_xcursor_manager.h> #include <wlr/util/log.h> @@ -75,6 +76,15 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { roots_cursor_handle_axis(cursor, event); } +static void handle_switch_toggle(struct wl_listener *listener, void *data) { + struct roots_switch *lid_switch = + wl_container_of(listener, lid_switch, toggle); + struct roots_desktop *desktop = lid_switch->seat->input->server->desktop; + wlr_idle_notify_activity(desktop->idle, lid_switch->seat->seat); + struct wlr_event_switch_toggle *event = data; + roots_switch_handle_toggle(lid_switch, event); +} + static void handle_touch_down(struct wl_listener *listener, void *data) { struct roots_cursor *cursor = wl_container_of(listener, cursor, touch_down); @@ -587,6 +597,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->touch); wl_list_init(&seat->tablets); wl_list_init(&seat->tablet_pads); + wl_list_init(&seat->switches); wl_list_init(&seat->views); wl_list_init(&seat->drag_icons); @@ -710,6 +721,36 @@ static void seat_add_pointer(struct roots_seat *seat, roots_seat_configure_cursor(seat); } +static void handle_switch_destroy(struct wl_listener *listener, void *data) { + struct roots_switch *lid_switch = + wl_container_of(listener, lid_switch, device_destroy); + struct roots_seat *seat = lid_switch->seat; + + wl_list_remove(&lid_switch->link); + wl_list_remove(&lid_switch->device_destroy.link); + free(lid_switch); + + seat_update_capabilities(seat); +} + +static void seat_add_switch(struct roots_seat *seat, + struct wlr_input_device *device) { + assert(device->type == WLR_INPUT_DEVICE_SWITCH); + struct roots_switch *lid_switch = calloc(1, sizeof(struct roots_switch)); + if (!lid_switch) { + wlr_log(WLR_ERROR, "could not allocate switch for seat"); + return; + } + device->data = lid_switch; + lid_switch->device = device; + lid_switch->seat = seat; + wl_list_insert(&seat->switches, &lid_switch->link); + lid_switch->device_destroy.notify = handle_switch_destroy; + + lid_switch->toggle.notify = handle_switch_toggle; + wl_signal_add(&lid_switch->device->lid_switch->events.toggle, &lid_switch->toggle); +} + static void handle_touch_destroy(struct wl_listener *listener, void *data) { struct roots_pointer *touch = wl_container_of(listener, touch, device_destroy); @@ -953,6 +994,9 @@ void roots_seat_add_device(struct roots_seat *seat, case WLR_INPUT_DEVICE_POINTER: seat_add_pointer(seat, device); break; + case WLR_INPUT_DEVICE_SWITCH: + seat_add_switch(seat, device); + break; case WLR_INPUT_DEVICE_TOUCH: seat_add_touch(seat, device); break; |