You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <libinput.h>
|
|
#include <wlr/backend/session.h>
|
|
#include <wlr/types/wlr_input_device.h>
|
|
#include <wlr/interfaces/wlr_keyboard.h>
|
|
#include <wlr/util/log.h>
|
|
#include "backend/libinput.h"
|
|
|
|
struct wlr_keyboard_state {
|
|
struct libinput_device *libinput_dev;
|
|
};
|
|
|
|
static void wlr_libinput_keyboard_set_leds(struct wlr_keyboard_state *kbstate, uint32_t leds) {
|
|
libinput_device_led_update(kbstate->libinput_dev, leds);
|
|
}
|
|
|
|
static void wlr_libinput_keyboard_destroy(struct wlr_keyboard_state *kbstate) {
|
|
libinput_device_unref(kbstate->libinput_dev);
|
|
free(kbstate);
|
|
}
|
|
|
|
struct wlr_keyboard_impl impl = {
|
|
.destroy = wlr_libinput_keyboard_destroy,
|
|
.led_update = wlr_libinput_keyboard_set_leds
|
|
};
|
|
|
|
struct wlr_keyboard *wlr_libinput_keyboard_create(
|
|
struct libinput_device *libinput_dev) {
|
|
assert(libinput_dev);
|
|
struct wlr_keyboard_state *kbstate = calloc(1, sizeof(struct wlr_keyboard_state));
|
|
kbstate->libinput_dev = libinput_dev;
|
|
libinput_device_ref(libinput_dev);
|
|
libinput_device_led_update(libinput_dev, 0);
|
|
return wlr_keyboard_create(&impl, kbstate);
|
|
}
|
|
|
|
void handle_keyboard_key(struct libinput_event *event,
|
|
struct libinput_device *libinput_dev) {
|
|
struct wlr_input_device *wlr_dev =
|
|
get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, libinput_dev);
|
|
if (!wlr_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_event_keyboard_key wlr_event = { 0 };
|
|
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(&wlr_dev->keyboard->events.key, &wlr_event);
|
|
}
|