Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Notify on all keyboard events with keysym #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct nvnc {
void* userdata;
nvnc_key_fn key_fn;
nvnc_key_fn key_code_fn;
nvnc_key_ext_fn key_ext_fn;
nvnc_pointer_fn pointer_fn;
nvnc_fb_req_fn fb_req_fn;
nvnc_client_fn new_client_fn;
Expand Down
11 changes: 11 additions & 0 deletions include/neatvnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ enum nvnc_auth_flags {
NVNC_AUTH_REQUIRE_ENCRYPTION = 1 << 1,
};

enum nvnc_keyboard_event_type {
NVNC_KEYBOARD_EVENT_TYPE_REGULAR = 0,
NVNC_KEYBOARD_EVENT_TYPE_QEMU = 1,
};

struct nvnc_log_data {
enum nvnc_log_level level;
const char* file;
Expand All @@ -123,6 +128,11 @@ struct nvnc_log_data {

typedef void (*nvnc_key_fn)(struct nvnc_client*, uint32_t key,
bool is_pressed);
typedef void (*nvnc_key_ext_fn)(struct nvnc_client*,
enum nvnc_keyboard_event_type event_type,
uint32_t key,
uint32_t keysym,
bool is_pressed);
typedef void (*nvnc_pointer_fn)(struct nvnc_client*, uint16_t x, uint16_t y,
enum nvnc_button_mask);
typedef void (*nvnc_fb_req_fn)(struct nvnc_client*, bool is_incremental,
Expand Down Expand Up @@ -192,6 +202,7 @@ void nvnc_set_name(struct nvnc* self, const char* name);

void nvnc_set_key_fn(struct nvnc* self, nvnc_key_fn);
void nvnc_set_key_code_fn(struct nvnc* self, nvnc_key_fn);
void nvnc_set_key_ext_fn(struct nvnc* self, nvnc_key_ext_fn);
void nvnc_set_pointer_fn(struct nvnc* self, nvnc_pointer_fn);
void nvnc_set_fb_req_fn(struct nvnc* self, nvnc_fb_req_fn);
void nvnc_set_new_client_fn(struct nvnc* self, nvnc_client_fn);
Expand Down
15 changes: 15 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,10 @@ static int on_client_key_event(struct nvnc_client* client)
if (fn)
fn(client, keysym, !!down_flag);

nvnc_key_ext_fn ext_fn = server->key_ext_fn;
if (ext_fn)
ext_fn(client, NVNC_KEYBOARD_EVENT_TYPE_REGULAR, 0, keysym, !!down_flag);

return sizeof(*msg);
}

Expand All @@ -1044,6 +1048,7 @@ static int on_client_qemu_key_event(struct nvnc_client* client)

int down_flag = msg->down_flag;
uint32_t xt_keycode = ntohl(msg->keycode);
uint32_t keysym = ntohl(msg->keysym);

uint32_t evdev_keycode = code_map_qnum_to_linux[xt_keycode];
if (!evdev_keycode)
Expand All @@ -1053,6 +1058,10 @@ static int on_client_qemu_key_event(struct nvnc_client* client)
if (fn)
fn(client, evdev_keycode, !!down_flag);

nvnc_key_ext_fn ext_fn = server->key_ext_fn;
if (ext_fn)
ext_fn(client, NVNC_KEYBOARD_EVENT_TYPE_QEMU, evdev_keycode, keysym, !!down_flag);

return sizeof(*msg);
}

Expand Down Expand Up @@ -2688,6 +2697,12 @@ void nvnc_set_key_code_fn(struct nvnc* self, nvnc_key_fn fn)
self->key_code_fn = fn;
}

EXPORT
void nvnc_set_key_ext_fn(struct nvnc* self, nvnc_key_ext_fn fn)
{
self->key_ext_fn = fn;
}

EXPORT
void nvnc_set_pointer_fn(struct nvnc* self, nvnc_pointer_fn fn)
{
Expand Down