aboutsummaryrefslogtreecommitdiff
path: root/backend/libinput/keyboard.c
blob: 9ad41a78ea04055e4b0561ee50c049594df4ce2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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"

struct wlr_keyboard *wlr_libinput_keyboard_create(
		struct libinput_device *device) {
	assert(device);
	libinput_device_led_update(device, 0);
	return wlr_keyboard_create(NULL, NULL);
}

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);
}