diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/CMakeLists.txt | 1 | ||||
-rw-r--r-- | backend/libinput/backend.c | 2 | ||||
-rw-r--r-- | backend/libinput/events.c | 50 | ||||
-rw-r--r-- | backend/libinput/keyboard.c | 56 |
4 files changed, 60 insertions, 49 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index e22032c3..5505e417 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -16,6 +16,7 @@ add_library(wlr-backend libinput/backend.c libinput/events.c + libinput/keyboard.c backend.c egl.c diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index dc018b10..9b0a6d8c 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -4,7 +4,7 @@ #include <wlr/session.h> #include <wlr/backend/interface.h> #include "backend/udev.h" -#include "backend/libinput/backend.h" +#include "backend/libinput.h" #include "common/log.h" static int wlr_libinput_open_restricted(const char *path, diff --git a/backend/libinput/events.c b/backend/libinput/events.c index c31632b5..3c623de4 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -4,11 +4,11 @@ #include <wlr/session.h> #include <wlr/types.h> #include <wlr/common/list.h> -#include "backend/libinput/backend.h" +#include "backend/libinput.h" #include "common/log.h" #include "types.h" -static struct wlr_input_device *get_appropriate_device( +struct wlr_input_device *get_appropriate_device( enum wlr_input_device_type desired_type, struct libinput_device *device) { list_t *devices = libinput_device_get_user_data(device); @@ -24,52 +24,6 @@ static struct wlr_input_device *get_appropriate_device( return NULL; } -static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *state) { - free(state); -} - -static struct wlr_keyboard_impl keyboard_impl = { - .destroy = wlr_libinput_keyboard_destroy -}; - -static struct wlr_keyboard *wlr_libinput_keyboard_create( - struct libinput_device *device) { - assert(device); - struct wlr_keyboard_state *kbstate = - calloc(1, sizeof(struct wlr_keyboard_state)); - kbstate->handle = device; - libinput_device_ref(device); - return wlr_keyboard_create(&keyboard_impl, kbstate); -} - -static void handle_keyboard_key(struct libinput_event *event, - struct libinput_device *device) { - struct wlr_input_device *dev = - get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, device); - if (!dev) { - wlr_log(L_DEBUG, "Got a keyboard event for a device with no keyboards?"); - return; - } - struct libinput_event_keyboard *kbevent = - libinput_event_get_keyboard_event(event); - struct wlr_keyboard_key *wlr_event = - calloc(1, sizeof(struct wlr_keyboard_key)); - wlr_event->time_sec = libinput_event_keyboard_get_time(kbevent); - wlr_event->time_usec = libinput_event_keyboard_get_time_usec(kbevent); - wlr_event->keycode = libinput_event_keyboard_get_key(kbevent); - enum libinput_key_state state = - libinput_event_keyboard_get_key_state(kbevent); - switch (state) { - case LIBINPUT_KEY_STATE_RELEASED: - wlr_event->state = WLR_KEY_RELEASED; - break; - case LIBINPUT_KEY_STATE_PRESSED: - wlr_event->state = WLR_KEY_PRESSED; - break; - } - wl_signal_emit(&dev->keyboard->events.key, wlr_event); -} - static void handle_device_added(struct wlr_backend_state *state, struct libinput_device *device) { assert(state && device); diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c new file mode 100644 index 00000000..afae960e --- /dev/null +++ b/backend/libinput/keyboard.c @@ -0,0 +1,56 @@ +#include <stdlib.h> +#include <assert.h> +#include <libinput.h> +#include <wlr/session.h> +#include <wlr/types.h> +#include <wlr/common/list.h> +#include "backend/libinput.h" +#include "common/log.h" +#include "types.h" + +static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *state) { + libinput_device_unref(state->handle); + free(state); +} + +static struct wlr_keyboard_impl keyboard_impl = { + .destroy = wlr_libinput_keyboard_destroy +}; + +struct wlr_keyboard *wlr_libinput_keyboard_create( + struct libinput_device *device) { + assert(device); + struct wlr_keyboard_state *kbstate = + calloc(1, sizeof(struct wlr_keyboard_state)); + kbstate->handle = device; + libinput_device_ref(device); + return wlr_keyboard_create(&keyboard_impl, kbstate); +} + +void handle_keyboard_key(struct libinput_event *event, + struct libinput_device *device) { + struct wlr_input_device *dev = + get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, device); + if (!dev) { + wlr_log(L_DEBUG, "Got a keyboard event for a device with no keyboards?"); + return; + } + struct libinput_event_keyboard *kbevent = + libinput_event_get_keyboard_event(event); + struct wlr_keyboard_key *wlr_event = + calloc(1, sizeof(struct wlr_keyboard_key)); + wlr_event->time_sec = libinput_event_keyboard_get_time(kbevent); + wlr_event->time_usec = libinput_event_keyboard_get_time_usec(kbevent); + wlr_event->keycode = libinput_event_keyboard_get_key(kbevent); + enum libinput_key_state state = + libinput_event_keyboard_get_key_state(kbevent); + switch (state) { + case LIBINPUT_KEY_STATE_RELEASED: + wlr_event->state = WLR_KEY_RELEASED; + break; + case LIBINPUT_KEY_STATE_PRESSED: + wlr_event->state = WLR_KEY_PRESSED; + break; + } + wl_signal_emit(&dev->keyboard->events.key, wlr_event); +} |