From 36d29e58af293b5ec0c372358bc1bcc4c9804a75 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 17 Feb 2025 05:02:48 +0100 Subject: [PATCH] [client,sdl] fix keyboard grab * on grab key toggle state * only update grab state in sdlInput::keyboard_grab --- client/SDL/SDL2/sdl_disp.cpp | 4 ++-- client/SDL/SDL2/sdl_kbd.cpp | 5 ++--- client/SDL/SDL2/sdl_kbd.hpp | 2 +- client/SDL/SDL3/sdl_kbd.cpp | 3 +-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/client/SDL/SDL2/sdl_disp.cpp b/client/SDL/SDL2/sdl_disp.cpp index 744260226..c24c78aea 100644 --- a/client/SDL/SDL2/sdl_disp.cpp +++ b/client/SDL/SDL2/sdl_disp.cpp @@ -373,11 +373,11 @@ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev) case SDL_WINDOWEVENT_LEAVE: WINPR_ASSERT(_sdl); - _sdl->input.keyboard_grab(ev->windowID, SDL_FALSE); + _sdl->input.keyboard_grab(ev->windowID, false); return TRUE; case SDL_WINDOWEVENT_ENTER: WINPR_ASSERT(_sdl); - _sdl->input.keyboard_grab(ev->windowID, SDL_TRUE); + _sdl->input.keyboard_grab(ev->windowID, true); return _sdl->input.keyboard_focus_in(); case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_TAKE_FOCUS: diff --git a/client/SDL/SDL2/sdl_kbd.cpp b/client/SDL/SDL2/sdl_kbd.cpp index cbeb26a2d..7648a4dd0 100644 --- a/client/SDL/SDL2/sdl_kbd.cpp +++ b/client/SDL/SDL2/sdl_kbd.cpp @@ -503,8 +503,7 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev) if (ev->keysym.scancode == _hotkeyGrab) { - _sdl->grab_kbd_enabled = !_sdl->grab_kbd_enabled; - keyboard_grab(ev->windowID, _sdl->grab_kbd ? SDL_FALSE : SDL_TRUE); + keyboard_grab(ev->windowID, !_sdl->grab_kbd); return TRUE; } if (ev->keysym.scancode == _hotkeyDisconnect) @@ -525,7 +524,7 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev) ev->repeat, scancode); } -BOOL sdlInput::keyboard_grab(Uint32 windowID, SDL_bool enable) +BOOL sdlInput::keyboard_grab(Uint32 windowID, bool enable) { auto it = _sdl->windows.find(windowID); if (it == _sdl->windows.end()) diff --git a/client/SDL/SDL2/sdl_kbd.hpp b/client/SDL/SDL2/sdl_kbd.hpp index e8bcdef43..802e077af 100644 --- a/client/SDL/SDL2/sdl_kbd.hpp +++ b/client/SDL/SDL2/sdl_kbd.hpp @@ -47,7 +47,7 @@ class sdlInput BOOL keyboard_handle_event(const SDL_KeyboardEvent* ev); - BOOL keyboard_grab(Uint32 windowID, SDL_bool enable); + BOOL keyboard_grab(Uint32 windowID, bool enable); BOOL mouse_focus(Uint32 windowID); BOOL mouse_grab(Uint32 windowID, SDL_bool enable); diff --git a/client/SDL/SDL3/sdl_kbd.cpp b/client/SDL/SDL3/sdl_kbd.cpp index 52fa4f9aa..edd99784a 100644 --- a/client/SDL/SDL3/sdl_kbd.cpp +++ b/client/SDL/SDL3/sdl_kbd.cpp @@ -475,8 +475,7 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev) if (ev->scancode == _hotkeyGrab) { - _sdl->grab_kbd_enabled = !_sdl->grab_kbd_enabled; - keyboard_grab(ev->windowID, _sdl->grab_kbd); + keyboard_grab(ev->windowID, !_sdl->grab_kbd); return TRUE; } if (ev->scancode == _hotkeyDisconnect)