aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/shared.c19
-rw-r--r--example/shared.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/example/shared.c b/example/shared.c
index 56cb89af..be1bdee7 100644
--- a/example/shared.c
+++ b/example/shared.c
@@ -12,6 +12,16 @@
#include <wlr/types.h>
#include "shared.h"
+static void keyboard_led_update(struct keyboard_state *kbstate) {
+ uint32_t leds = 0;
+ for (uint32_t i = 0; i < WLR_LED_LAST; ++i) {
+ if (xkb_state_led_index_is_active(kbstate->xkb_state, kbstate->leds[i])) {
+ leds |= (1 << i);
+ }
+ }
+ wlr_keyboard_led_update(kbstate->device->keyboard, leds);
+}
+
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
struct wlr_keyboard_key *event = data;
struct keyboard_state *kbstate = wl_container_of(listener, kbstate, key);
@@ -33,6 +43,7 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
}
xkb_state_update_key(kbstate->xkb_state, keycode,
event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP);
+ keyboard_led_update(kbstate);
}
static void keyboard_add(struct wlr_input_device *device, struct compositor_state *state) {
@@ -68,6 +79,14 @@ static void keyboard_add(struct wlr_input_device *device, struct compositor_stat
fprintf(stderr, "Failed to create XKB state\n");
exit(1);
}
+ const char *led_names[3] = {
+ XKB_LED_NAME_NUM,
+ XKB_LED_NAME_CAPS,
+ XKB_LED_NAME_SCROLL
+ };
+ for (uint32_t i = 0; i < 3; ++i) {
+ kbstate->leds[i] = xkb_map_led_get_index(kbstate->keymap, led_names[i]);
+ }
}
static void pointer_motion_notify(struct wl_listener *listener, void *data) {
diff --git a/example/shared.h b/example/shared.h
index 173a5719..6d533443 100644
--- a/example/shared.h
+++ b/example/shared.h
@@ -25,6 +25,7 @@ struct keyboard_state {
struct wl_list link;
struct xkb_keymap *keymap;
struct xkb_state *xkb_state;
+ xkb_led_index_t leds[WLR_LED_LAST];
void *data;
};