From 98d703bfa8f746ff20da5b6681b5542e9c81f7c7 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Fri, 16 Oct 2020 22:46:56 +0200 Subject: [PATCH] Fix de-neo layout - Add possibility to specify layout variant with -k - - Add ISO_Level5_Shift and ISO_Level5_Lock to modifier keys --- include/keyboard.h | 2 +- src/keyboard.c | 5 ++++- src/main.c | 21 +++++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/keyboard.h b/include/keyboard.h index 23cc4ca..59b1d4b 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -39,6 +39,6 @@ struct keyboard { struct intset key_state; }; -int keyboard_init(struct keyboard* self, const char* layout); +int keyboard_init(struct keyboard* self, const char* layout, const char* variant); void keyboard_destroy(struct keyboard* self); void keyboard_feed(struct keyboard* self, xkb_keysym_t symbol, bool is_pressed); diff --git a/src/keyboard.c b/src/keyboard.c index bcea556..9a6f5b4 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -149,7 +149,7 @@ void keyboard_dump_lookup_table(const struct keyboard* self) keyboard__dump_entry(self, &self->lookup_table[i]); } -int keyboard_init(struct keyboard* self, const char* layout) +int keyboard_init(struct keyboard* self, const char* layout, const char* variant) { self->context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!self->context) @@ -161,6 +161,7 @@ int keyboard_init(struct keyboard* self, const char* layout) struct xkb_rule_names rule_names = { .layout = layout, .model = "pc105", + .variant = variant, }; self->keymap = xkb_keymap_new_from_names(self->context, &rule_names, 0); @@ -321,6 +322,8 @@ static bool keyboard_symbol_is_mod(xkb_keysym_t symbol) case XKB_KEY_Super_R: case XKB_KEY_Hyper_L: case XKB_KEY_Hyper_R: + case XKB_KEY_ISO_Level5_Shift: + case XKB_KEY_ISO_Level5_Lock: return true; } diff --git a/src/main.c b/src/main.c index 03cdd2e..89e1e98 100644 --- a/src/main.c +++ b/src/main.c @@ -98,6 +98,7 @@ struct wayvnc { struct pixman_region16 current_damage; const char* kb_layout; + const char* kb_variant; uint32_t damage_area_sum; uint32_t n_frames_captured; @@ -684,7 +685,7 @@ int wayvnc_usage(FILE* stream, int rc) "\n" " -C,--config= Select a config file.\n" " -o,--output= Select output to capture.\n" -" -k,--keyboard= Select keyboard layout.\n" +" -k,--keyboard=[-] Select keyboard layout with an optional variant.\n" " -s,--seat= Select seat by name.\n" " -r,--render-cursor Enable overlay cursor rendering.\n" " -f,--max-fps= Set the rate limit (default 30).\n" @@ -762,6 +763,18 @@ static void start_performance_ticker(struct wayvnc* self) aml_unref(ticker); } +void parse_keyboard_option(struct wayvnc* self, char* arg) +{ + // Find optional variant, separated by - + char* index = strchr(arg, '-'); + if (index != NULL) { + self->kb_variant = index + 1; + // layout needs to be 0-terminated, replace the - by 0 + *index = 0; + } + self->kb_layout = arg; +} + int show_version(void) { printf("wayvnc: %s\n", wayvnc_version); @@ -781,7 +794,7 @@ int main(int argc, char* argv[]) const char* output_name = NULL; const char* seat_name = NULL; - + bool overlay_cursor = false; bool show_performance = false; int max_rate = 30; @@ -815,7 +828,7 @@ int main(int argc, char* argv[]) output_name = optarg; break; case 'k': - self.kb_layout = optarg; + parse_keyboard_option(&self, optarg); break; case 's': seat_name = optarg; @@ -914,7 +927,7 @@ int main(int argc, char* argv[]) zwp_virtual_keyboard_manager_v1_create_virtual_keyboard( self.keyboard_manager, self.selected_seat->wl_seat); - keyboard_init(&self.keyboard_backend, self.kb_layout); + keyboard_init(&self.keyboard_backend, self.kb_layout, self.kb_variant); self.pointer_backend.vnc = self.nvnc; self.pointer_backend.output = self.selected_output;