From b19518a1f86efaa2b79ea7fb75d77ea2bafd536a Mon Sep 17 00:00:00 2001 From: williamvds Date: Mon, 4 Jun 2018 18:32:21 +0100 Subject: [PATCH] [client] Allow keyboard capture (#26) --- client/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/main.c b/client/main.c index ebf1fe75..310b7611 100644 --- a/client/main.c +++ b/client/main.c @@ -101,6 +101,7 @@ struct AppParams bool hideMouse; bool ignoreQuit; bool allowScreensaver; + bool grabKeyboard; SDL_Scancode captureKey; bool forceRenderer; @@ -134,6 +135,7 @@ struct AppParams params = .ignoreQuit = false, .allowScreensaver = true, .captureKey = SDL_SCANCODE_SCROLLLOCK, + .grabKeyboard = true, .forceRenderer = false }; @@ -526,6 +528,7 @@ int eventFilter(void * userdata, SDL_Event * event) serverMode = !serverMode; spice_mouse_mode(serverMode); SDL_SetRelativeMouseMode(serverMode); + SDL_SetWindowGrab(state.window, serverMode); DEBUG_INFO("Server Mode: %s", serverMode ? "on" : "off"); if (state.lgr) @@ -1070,6 +1073,7 @@ void doHelp(char * app) " -b HEIGHT Initial window height [current: %u]\n" " -Q Ignore requests to quit (ie: Alt+F4)\n" " -S Disable the screensaver\n" + " -G Don't capture the keyboard in capture mode\n" " -m CODE Specify the capture key [current: %u (%s)]\n" " See https://wiki.libsdl.org/SDLScancodeLookup for valid values\n" "\n" @@ -1314,7 +1318,7 @@ int main(int argc, char * argv[]) for(;;) { - switch(getopt(argc, argv, "hC:f:L:sc:p:jMvK:kg:o:anrdFx:y:w:b:QSm:l")) + switch(getopt(argc, argv, "hC:f:L:sc:p:jMvK:kg:o:anrdFx:y:w:b:QSGm:l")) { case '?': case 'h': @@ -1539,6 +1543,10 @@ int main(int argc, char * argv[]) params.allowScreensaver = false; continue; + case 'G': + params.grabKeyboard = false; + continue; + case 'm': params.captureKey = atoi(optarg); continue; @@ -1557,6 +1565,11 @@ int main(int argc, char * argv[]) return -1; } + if (params.grabKeyboard) + { + SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); + } + const int ret = run(); free(params.shmFile); @@ -1570,4 +1583,4 @@ int main(int argc, char * argv[]) } return ret; -} \ No newline at end of file +}