aboutsummaryrefslogtreecommitdiff
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
parent12612572ef9af9686e24bb9af81c31c82bb1f765 (diff)
Split keyboard code out into its own file
-rw-r--r--backend/CMakeLists.txt1
-rw-r--r--backend/libinput/backend.c2
-rw-r--r--backend/libinput/events.c50
-rw-r--r--backend/libinput/keyboard.c56
-rw-r--r--include/backend/libinput.h (renamed from include/backend/libinput/backend.h)10
5 files changed, 70 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);
+}
diff --git a/include/backend/libinput/backend.h b/include/backend/libinput.h
index 6f2fa2a0..a59ab401 100644
--- a/include/backend/libinput/backend.h
+++ b/include/backend/libinput.h
@@ -5,6 +5,7 @@
#include <wlr/common/list.h>
#include <wayland-server-core.h>
#include "backend/udev.h"
+#include "types.h"
struct wlr_backend_state {
struct wlr_backend *backend;
@@ -21,8 +22,17 @@ struct wlr_backend_state {
void wlr_libinput_event(struct wlr_backend_state *state,
struct libinput_event *event);
+struct wlr_input_device *get_appropriate_device(
+ enum wlr_input_device_type desired_type,
+ struct libinput_device *device);
+
struct wlr_keyboard_state {
struct libinput_device *handle;
};
+void handle_keyboard_key(struct libinput_event *event,
+ struct libinput_device *device);
+struct wlr_keyboard *wlr_libinput_keyboard_create(
+ struct libinput_device *device);
+
#endif