From 15660cd4a71d7a8243e21ed0787b8695a4bfdcd3 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 7 Apr 2024 12:31:34 +0000 Subject: [PATCH] keyboard: Pass keyboard LED state to client --- include/keyboard.h | 3 +++ src/keyboard.c | 15 +++++++++++++++ src/main.c | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/include/keyboard.h b/include/keyboard.h index 558de390..1782eab7 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -19,11 +19,13 @@ #include #include #include +#include #include "intset.h" struct zwp_virtual_keyboard_v1; struct table_entry; +struct nvnc; struct keyboard { struct zwp_virtual_keyboard_v1* virtual_keyboard; @@ -44,3 +46,4 @@ void keyboard_destroy(struct keyboard* self); void keyboard_feed(struct keyboard* self, xkb_keysym_t symbol, bool is_pressed); void keyboard_feed_code(struct keyboard* self, xkb_keycode_t code, bool is_pressed); +enum nvnc_keyboard_led_state keyboard_get_led_state(const struct keyboard*); diff --git a/src/keyboard.c b/src/keyboard.c index 79fb1f38..2e90f95e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -436,3 +436,18 @@ void keyboard_feed_code(struct keyboard* self, xkb_keycode_t code, send_key(self, code, is_pressed); } } + +enum nvnc_keyboard_led_state keyboard_get_led_state( + const struct keyboard* self) +{ + enum nvnc_keyboard_led_state led_state = 0; + + if (xkb_state_led_name_is_active(self->state, XKB_LED_NAME_SCROLL)) + led_state |= NVNC_KEYBOARD_LED_SCROLL_LOCK; + if (xkb_state_led_name_is_active(self->state, XKB_LED_NAME_NUM)) + led_state |= NVNC_KEYBOARD_LED_NUM_LOCK; + if (xkb_state_led_name_is_active(self->state, XKB_LED_NAME_CAPS)) + led_state |= NVNC_KEYBOARD_LED_CAPS_LOCK; + + return led_state; +} diff --git a/src/main.c b/src/main.c index b47d21bd..8f541840 100644 --- a/src/main.c +++ b/src/main.c @@ -760,6 +760,9 @@ static void on_key_event(struct nvnc_client* client, uint32_t symbol, } keyboard_feed(&wv_client->keyboard, symbol, is_pressed); + + nvnc_client_set_led_state(wv_client->nvnc_client, + keyboard_get_led_state(&wv_client->keyboard)); } static void on_key_code_event(struct nvnc_client* client, uint32_t code, @@ -771,6 +774,9 @@ static void on_key_code_event(struct nvnc_client* client, uint32_t code, } keyboard_feed_code(&wv_client->keyboard, code + 8, is_pressed); + + nvnc_client_set_led_state(wv_client->nvnc_client, + keyboard_get_led_state(&wv_client->keyboard)); } static void on_client_cut_text(struct nvnc_client* nvnc_client,