From bbcaaccdcc3bd63e241fb0ba593809431c557fd0 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 29 Nov 2020 07:12:19 +1100 Subject: [PATCH] [client] added new option input:grabKeyboardOnFocus --- client/src/config.c | 18 +++++++++++++----- client/src/main.c | 6 ++++++ client/src/main.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/client/src/config.c b/client/src/config.c index 293b5494..f83509f1 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -244,6 +244,13 @@ static struct Option options[] = .type = OPTION_TYPE_BOOL, .value.x_bool = true, }, + { + .module = "input", + .name = "grabKeyboardOnFocus", + .description = "Grab the keyboard when focused", + .type = OPTION_TYPE_BOOL, + .value.x_bool = true, + }, { .module = "input", .name = "escapeKey", @@ -433,11 +440,12 @@ bool config_load(int argc, char * argv[]) params.showAlerts = option_get_bool ("win", "alerts" ); params.quickSplash = option_get_bool ("win", "quickSplash" ); - params.grabKeyboard = option_get_bool ("input", "grabKeyboard"); - params.escapeKey = option_get_int ("input", "escapeKey" ); - params.hideMouse = option_get_bool ("input", "hideCursor" ); - params.mouseSens = option_get_int ("input", "mouseSens" ); - params.mouseRedraw = option_get_bool ("input", "mouseRedraw" ); + params.grabKeyboard = option_get_bool ("input", "grabKeyboard" ); + params.grabKeyboardOnFocus = option_get_bool ("input", "grabKeyboardOnFocus"); + params.escapeKey = option_get_int ("input", "escapeKey" ); + params.hideMouse = option_get_bool ("input", "hideCursor" ); + params.mouseSens = option_get_int ("input", "mouseSens" ); + params.mouseRedraw = option_get_bool ("input", "mouseRedraw" ); params.minimizeOnFocusLoss = option_get_bool("win", "minimizeOnFocusLoss"); diff --git a/client/src/main.c b/client/src/main.c index 4d106f4a..d21b7cd0 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -928,6 +928,9 @@ static void handleWindowEnter() // only called for X11 static void keyboardGrab() { + if (!params.grabKeyboardOnFocus) + return; + // grab the keyboard so we can intercept WM keys XGrabKeyboard( state.wminfo.info.x11.display, @@ -942,6 +945,9 @@ static void keyboardGrab() // only called for X11 static void keyboardUngrab() { + if (!params.grabKeyboardOnFocus) + return; + // ungrab the keyboard XUngrabKeyboard( state.wminfo.info.x11.display, diff --git a/client/src/main.h b/client/src/main.h index 312240d6..89f6c4ac 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -151,6 +151,7 @@ struct AppParams bool ignoreQuit; bool noScreensaver; bool grabKeyboard; + bool grabKeyboardOnFocus; SDL_Scancode escapeKey; bool showAlerts; bool captureOnStart;