diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 13:59:04 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 15:01:09 -0500 |
commit | 609f63934ab3eb925741450aa7f78db1c11bdd37 (patch) | |
tree | dec4a8477166fda0557589fdeec5a30a2ccc025a /sway/input/keyboard.c | |
parent | remove pointer device (diff) | |
download | sway-609f63934ab3eb925741450aa7f78db1c11bdd37.tar.gz sway-609f63934ab3eb925741450aa7f78db1c11bdd37.tar.zst sway-609f63934ab3eb925741450aa7f78db1c11bdd37.zip |
basic keyboard
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r-- | sway/input/keyboard.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c new file mode 100644 index 00000000..59f81e62 --- /dev/null +++ b/sway/input/keyboard.c | |||
@@ -0,0 +1,57 @@ | |||
1 | #include "sway/input/seat.h" | ||
2 | #include "sway/input/keyboard.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | static void handle_keyboard_key(struct wl_listener *listener, void *data) { | ||
6 | struct sway_keyboard *keyboard = | ||
7 | wl_container_of(listener, keyboard, keyboard_key); | ||
8 | struct wlr_event_keyboard_key *event = data; | ||
9 | wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device); | ||
10 | wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec, | ||
11 | event->keycode, event->state); | ||
12 | } | ||
13 | |||
14 | static void handle_keyboard_modifiers(struct wl_listener *listener, | ||
15 | void *data) { | ||
16 | struct sway_keyboard *keyboard = | ||
17 | wl_container_of(listener, keyboard, keyboard_modifiers); | ||
18 | wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device); | ||
19 | wlr_seat_keyboard_notify_modifiers(keyboard->seat->seat); | ||
20 | } | ||
21 | |||
22 | struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | ||
23 | struct wlr_input_device *device) { | ||
24 | struct sway_keyboard *keyboard = | ||
25 | calloc(1, sizeof(struct sway_keyboard)); | ||
26 | if (!sway_assert(keyboard, "could not allocate sway keyboard")) { | ||
27 | return NULL; | ||
28 | } | ||
29 | |||
30 | keyboard->device = device; | ||
31 | keyboard->seat = seat; | ||
32 | |||
33 | // TODO keyboard config | ||
34 | struct xkb_rule_names rules; | ||
35 | memset(&rules, 0, sizeof(rules)); | ||
36 | rules.rules = getenv("XKB_DEFAULT_RULES"); | ||
37 | rules.model = getenv("XKB_DEFAULT_MODEL"); | ||
38 | rules.layout = getenv("XKB_DEFAULT_LAYOUT"); | ||
39 | rules.variant = getenv("XKB_DEFAULT_VARIANT"); | ||
40 | rules.options = getenv("XKB_DEFAULT_OPTIONS"); | ||
41 | struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); | ||
42 | if (!sway_assert(context, "cannot create XKB context")) { | ||
43 | return NULL; | ||
44 | } | ||
45 | |||
46 | wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, | ||
47 | &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); | ||
48 | xkb_context_unref(context); | ||
49 | |||
50 | wl_signal_add(&device->keyboard->events.key, &keyboard->keyboard_key); | ||
51 | keyboard->keyboard_key.notify = handle_keyboard_key; | ||
52 | |||
53 | wl_signal_add(&device->keyboard->events.modifiers, &keyboard->keyboard_modifiers); | ||
54 | keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers; | ||
55 | |||
56 | return keyboard; | ||
57 | } | ||