[client,sdl] keep hotkey state of keyboard grab

keep the keyboard grab state from:
1. +/-grab-keyboard command line as default
2. toggle this state by hotkey later on
This commit is contained in:
akallabeth 2024-06-08 09:25:44 +02:00
parent a6abca5e89
commit 221a442270
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
6 changed files with 16 additions and 4 deletions

View File

@ -1693,6 +1693,8 @@ SdlContext::SdlContext(rdpContext* context)
: _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
primary(nullptr, SDL_FreeSurface), primary_format(nullptr, SDL_FreeFormat)
{
WINPR_ASSERT(context);
grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
}
rdpContext* SdlContext::context() const

View File

@ -58,6 +58,7 @@ class SdlContext
bool resizeable = false;
bool grab_mouse = false;
bool grab_kbd = false;
bool grab_kbd_enabled = true;
std::map<Uint32, SdlWindow> windows;

View File

@ -572,6 +572,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);
return TRUE;
}
@ -593,8 +594,10 @@ BOOL sdlInput::keyboard_grab(Uint32 windowID, SDL_bool enable)
auto it = _sdl->windows.find(windowID);
if (it == _sdl->windows.end())
return FALSE;
_sdl->grab_kbd = enable;
return it->second.grabKeyboard(enable);
auto status = enable && _sdl->grab_kbd_enabled;
_sdl->grab_kbd = status;
return it->second.grabKeyboard(status);
}
BOOL sdlInput::mouse_focus(Uint32 windowID)

View File

@ -1687,6 +1687,9 @@ SdlContext::SdlContext(rdpContext* context)
input(this), primary(nullptr, SDL_DestroySurface),
primary_format(nullptr, SDL_DestroyPixelFormat)
{
WINPR_ASSERT(context);
grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
`: w
}
rdpContext* SdlContext::context() const

View File

@ -59,6 +59,7 @@ class SdlContext
bool resizeable = false;
bool grab_mouse = false;
bool grab_kbd = false;
bool grab_kbd_enabled = true;
std::map<Uint32, SdlWindow> windows;

View File

@ -558,6 +558,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);
return TRUE;
}
@ -579,8 +580,9 @@ BOOL sdlInput::keyboard_grab(Uint32 windowID, SDL_bool enable)
auto it = _sdl->windows.find(windowID);
if (it == _sdl->windows.end())
return FALSE;
_sdl->grab_kbd = enable;
return it->second.grabKeyboard(enable);
auto status = enable && _sdl->grab_kbd_enabled;
_sdl->grab_kbd = status;
return it->second.grabKeyboard(status);
}
BOOL sdlInput::mouse_focus(Uint32 windowID)