aboutsummaryrefslogtreecommitdiff
path: root/backend/libinput/keyboard.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-10 11:58:25 -0400
committerDrew DeVault <sir@cmpwn.com>2017-06-13 08:10:36 -0400
commitf479b7c8c7aa93229c46287f774a30ac8324da1e (patch)
treece81612ee5088ed24ef231577f9e3436188099d3 /backend/libinput/keyboard.c
parent12612572ef9af9686e24bb9af81c31c82bb1f765 (diff)
Split keyboard code out into its own file
Diffstat (limited to 'backend/libinput/keyboard.c')
-rw-r--r--backend/libinput/keyboard.c56
1 files changed, 56 insertions, 0 deletions
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);
+}