|
|
@ -8,6 +8,22 @@
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static 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);
|
|
|
|
|
|
|
|
if (!devices) {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < devices->length; ++i) {
|
|
|
|
|
|
|
|
struct wlr_input_device *dev = devices->items[i];
|
|
|
|
|
|
|
|
if (dev->type == desired_type) {
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *state) {
|
|
|
|
static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *state) {
|
|
|
|
free(state);
|
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -22,10 +38,39 @@ static struct wlr_keyboard *wlr_libinput_keyboard_create(
|
|
|
|
struct wlr_keyboard_state *kbstate =
|
|
|
|
struct wlr_keyboard_state *kbstate =
|
|
|
|
calloc(1, sizeof(struct wlr_keyboard_state));
|
|
|
|
calloc(1, sizeof(struct wlr_keyboard_state));
|
|
|
|
kbstate->handle = device;
|
|
|
|
kbstate->handle = device;
|
|
|
|
|
|
|
|
libinput_device_ref(device);
|
|
|
|
return wlr_keyboard_create(&keyboard_impl, kbstate);
|
|
|
|
return wlr_keyboard_create(&keyboard_impl, kbstate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void device_added(struct wlr_backend_state *state,
|
|
|
|
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) {
|
|
|
|
struct libinput_device *device) {
|
|
|
|
assert(state && device);
|
|
|
|
assert(state && device);
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -73,7 +118,7 @@ static void device_added(struct wlr_backend_state *state,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void device_removed(struct wlr_backend_state *state,
|
|
|
|
static void handle_device_removed(struct wlr_backend_state *state,
|
|
|
|
struct libinput_device *device) {
|
|
|
|
struct libinput_device *device) {
|
|
|
|
wlr_log(L_DEBUG, "libinput device removed");
|
|
|
|
wlr_log(L_DEBUG, "libinput device removed");
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
@ -88,10 +133,13 @@ void wlr_libinput_event(struct wlr_backend_state *state,
|
|
|
|
(void)context;
|
|
|
|
(void)context;
|
|
|
|
switch (event_type) {
|
|
|
|
switch (event_type) {
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
device_added(state, device);
|
|
|
|
handle_device_added(state, device);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
|
|
|
device_removed(state, device);
|
|
|
|
handle_device_removed(state, device);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
|
|
|
|
|
|
|
handle_keyboard_key(event, device);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
wlr_log(L_DEBUG, "Unknown libinput event %d", event_type);
|
|
|
|
wlr_log(L_DEBUG, "Unknown libinput event %d", event_type);
|
|
|
|