From 8fd08cdd7930ede417a44dc5ac87241d04b58781 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 4 Jan 2021 18:22:39 +1100 Subject: [PATCH] [client] spice: add option to ignore the windows key If active this will prevent the client from sending keyboard events for the windows key. The idea is to allow people to keep the windows key bound to their WMs default action without causing the Windows start menu to open --- client/src/config.c | 8 ++++++++ client/src/main.c | 14 +++++++++++++- client/src/main.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/client/src/config.c b/client/src/config.c index f83509f1..c62e0638 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -260,6 +260,13 @@ static struct Option options[] = .value.x_int = SDL_SCANCODE_SCROLLLOCK, .toString = optScancodeToString }, + { + .module = "input", + .name = "ignoreWindowsKeys", + .description = "Do not pass events for the windows keys to the guest", + .type = OPTION_TYPE_BOOL, + .value.x_bool = false + }, { .module = "input", .name = "hideCursor", @@ -443,6 +450,7 @@ bool config_load(int argc, char * argv[]) params.grabKeyboard = option_get_bool ("input", "grabKeyboard" ); params.grabKeyboardOnFocus = option_get_bool ("input", "grabKeyboardOnFocus"); params.escapeKey = option_get_int ("input", "escapeKey" ); + params.ignoreWindowsKeys = option_get_bool ("input", "ignoreWindowsKeys" ); params.hideMouse = option_get_bool ("input", "hideCursor" ); params.mouseSens = option_get_int ("input", "mouseSens" ); params.mouseRedraw = option_get_bool ("input", "mouseRedraw" ); diff --git a/client/src/main.c b/client/src/main.c index dd11b22b..97c86bfd 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1213,7 +1213,7 @@ int eventFilter(void * userdata, SDL_Event * event) case SDL_KEYDOWN: { SDL_Scancode sc = event->key.keysym.scancode; - if (sc == params.escapeKey) + if (sc == params.escapeKey && !g_state.escapeActive) { g_state.escapeActive = true; g_state.escapeAction = -1; @@ -1229,6 +1229,11 @@ int eventFilter(void * userdata, SDL_Event * event) if (g_state.ignoreInput || !params.useSpiceInput) break; + if (params.ignoreWindowsKeys && + (sc == SDL_SCANCODE_LGUI || sc == SDL_SCANCODE_RGUI)) + break; + + uint32_t scancode = mapScancode(sc); if (scancode == 0) break; @@ -1299,7 +1304,10 @@ int eventFilter(void * userdata, SDL_Event * event) { KeybindHandle handle = g_state.bindings[sc]; if (handle) + { handle->callback(sc, handle->opaque); + break; + } } if (sc == params.escapeKey) @@ -1313,6 +1321,10 @@ int eventFilter(void * userdata, SDL_Event * event) if (!g_state.keyDown[sc]) break; + if (params.ignoreWindowsKeys && + (sc == SDL_SCANCODE_LGUI || sc == SDL_SCANCODE_RGUI)) + break; + uint32_t scancode = mapScancode(sc); if (scancode == 0) break; diff --git a/client/src/main.h b/client/src/main.h index d8eba2fb..89d86add 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -121,6 +121,7 @@ struct AppParams bool grabKeyboard; bool grabKeyboardOnFocus; SDL_Scancode escapeKey; + bool ignoreWindowsKeys; bool showAlerts; bool captureOnStart; bool quickSplash;