aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-09 17:52:11 -0400
committerDrew DeVault <sir@cmpwn.com>2017-06-13 08:10:36 -0400
commit59ceaf507e9a7c80e04460d1ae4946ce7b6f56ac (patch)
treedf3b5fcc06b47ca3a1beb9ecff01cbf4527473d4 /example
parent0e75d157f52db45a1af350574bd95cccbd09fa57 (diff)
Handle key presses
Diffstat (limited to 'example')
-rw-r--r--example/simple.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/example/simple.c b/example/simple.c
index 3206b3fa..660c56a6 100644
--- a/example/simple.c
+++ b/example/simple.c
@@ -97,6 +97,13 @@ void output_remove(struct wl_listener *listener, void *data) {
wl_list_remove(&ostate->frame.link);
}
+static void keyboard_key(struct wl_listener *listener, void *data) {
+ struct wlr_keyboard_key *event = data;
+ struct keyboard_state *kbstate = wl_container_of(listener, kbstate, key);
+ fprintf(stderr, "Key event: %u %s\n", event->keycode,
+ event->state == WLR_KEY_PRESSED ? "pressed" : "released");
+}
+
void input_add(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data;
struct state *state = wl_container_of(listener, state, input_add);
@@ -109,6 +116,8 @@ void input_add(struct wl_listener *listener, void *data) {
kbstate->device = device;
wl_list_init(&kbstate->key.link);
wl_list_init(&kbstate->mods.link);
+ kbstate->key.notify = keyboard_key;
+ wl_signal_add(&device->keyboard->events.key, &kbstate->key);
wl_list_insert(&state->keyboards, &kbstate->link);
}