From 59ea957d0d1f92d11d43542f000ed7f05b906f45 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 8 Jan 2021 20:26:32 +1100 Subject: [PATCH] [client] spice: don't grab the keyboard input unless we are focused --- client/src/main.c | 33 ++++++++++++++++++++------------- client/src/main.h | 1 + 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index e0a28d37..0ce4c116 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -899,20 +899,23 @@ static void handleMouseNormal(double ex, double ey) if (inView) { - /* the cursor moved in, enable grab mode */ - g_cursor.inView = true; - g_cursor.warpState = WARP_STATE_ON; + if (g_state.focused) + { + /* the cursor moved in, enable grab mode */ + g_cursor.inView = true; + g_cursor.warpState = WARP_STATE_ON; - XGrabPointer( - g_state.wminfo.info.x11.display, - g_state.wminfo.info.x11.window, - true, - None, - GrabModeAsync, - GrabModeAsync, - g_state.wminfo.info.x11.window, - None, - CurrentTime); + XGrabPointer( + g_state.wminfo.info.x11.display, + g_state.wminfo.info.x11.window, + true, + None, + GrabModeAsync, + GrabModeAsync, + g_state.wminfo.info.x11.window, + None, + CurrentTime); + } struct DoublePoint guest = { @@ -1314,6 +1317,8 @@ int eventFilter(void * userdata, SDL_Event * event) } case FocusIn: + g_state.focused = true; + if (!params.useSpiceInput) break; @@ -1323,6 +1328,8 @@ int eventFilter(void * userdata, SDL_Event * event) break; case FocusOut: + g_state.focused = false; + if (!params.useSpiceInput) break; diff --git a/client/src/main.h b/client/src/main.h index 874095e2..e1c40c6b 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -50,6 +50,7 @@ struct AppState SDL_Point windowPos; int windowW, windowH; int windowCX, windowCY; + bool focused; SDL_Rect border; SDL_Point srcSize; LG_RendererRect dstRect;