From e8ac71263b5575c6b71555229d5ccc92f4f66338 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 25 Nov 2017 23:24:29 +1100 Subject: [PATCH] [client] dont send up events if we didn't send a down event --- client/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client/main.c b/client/main.c index 54bca0c9..4b07293c 100644 --- a/client/main.c +++ b/client/main.c @@ -435,6 +435,9 @@ int eventThread(void * arg) { bool serverMode = false; bool realignGuest = true; + bool keyDown[SDL_NUM_SCANCODES]; + + memset(keyDown, 0, sizeof(keyDown)); // ensure mouse acceleration is identical in server mode SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE); @@ -451,6 +454,7 @@ int eventThread(void * arg) state.running = false; break; } + continue; } if (event.type == SDL_QUIT) @@ -485,7 +489,9 @@ int eventThread(void * arg) if (scancode == 0) break; - if (!spice_key_down(scancode)) + if (spice_key_down(scancode)) + keyDown[sc] = true; + else { DEBUG_ERROR("SDL_KEYDOWN: failed to send message"); break; @@ -499,12 +505,17 @@ int eventThread(void * arg) if (sc == SDL_SCANCODE_SCROLLLOCK) break; + // avoid sending key up events when we didn't send a down + if (!keyDown[sc]) + break; uint32_t scancode = mapScancode(sc); if (scancode == 0) break; - if (!spice_key_up(scancode)) + if (spice_key_up(scancode)) + keyDown[sc] = false; + else { DEBUG_ERROR("SDL_KEYUP: failed to send message"); break;