Skip to content

Commit

Permalink
keyboard: Pass keyboard LED state to client
Browse files Browse the repository at this point in the history
  • Loading branch information
any1 committed Apr 7, 2024
1 parent fbd98ed commit 15660cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#include <stdlib.h>
#include <xkbcommon/xkbcommon.h>
#include <stdbool.h>
#include <neatvnc.h>

#include "intset.h"

struct zwp_virtual_keyboard_v1;
struct table_entry;
struct nvnc;

struct keyboard {
struct zwp_virtual_keyboard_v1* virtual_keyboard;
Expand All @@ -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*);
15 changes: 15 additions & 0 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 15660cd

Please sign in to comment.