Merge pull request #10227 from mjt0k/sdl-kbd-config-once

SDL2: sdl_kbd: parse keyboard config once instead of at each keypress
This commit is contained in:
akallabeth 2024-06-03 11:38:16 +02:00 committed by GitHub
commit e569119fa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 20 deletions

View File

@ -554,33 +554,28 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
WINPR_ASSERT(ev);
const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->keysym.scancode);
const SDL_Keymod mods = SDL_GetModState();
const auto mask = prefToMask();
const auto valFullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN);
const auto valResizeable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R);
const auto valGrab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G);
const auto valDisconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D);
if ((mods & mask) == mask)
if ((mods & _hotkeyModmask) == _hotkeyModmask)
{
if (ev->type == SDL_KEYDOWN)
{
if (ev->keysym.scancode == valFullscreen)
if (ev->keysym.scancode == _hotkeyFullscreen)
{
_sdl->update_fullscreen(!_sdl->fullscreen);
return TRUE;
}
if (ev->keysym.scancode == valResizeable)
if (ev->keysym.scancode == _hotkeyResizable)
{
_sdl->update_resizeable(!_sdl->resizeable);
return TRUE;
}
if (ev->keysym.scancode == valGrab)
if (ev->keysym.scancode == _hotkeyGrab)
{
keyboard_grab(ev->windowID, _sdl->grab_kbd ? SDL_FALSE : SDL_TRUE);
return TRUE;
}
if (ev->keysym.scancode == valDisconnect)
if (ev->keysym.scancode == _hotkeyDisconnect)
{
freerdp_abort_connect_context(_sdl->context());
return TRUE;
@ -627,4 +622,9 @@ BOOL sdlInput::mouse_grab(Uint32 windowID, SDL_bool enable)
sdlInput::sdlInput(SdlContext* sdl) : _sdl(sdl), _lastWindowID(UINT32_MAX)
{
_hotkeyModmask = prefToMask();
_hotkeyFullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN);
_hotkeyResizable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R);
_hotkeyGrab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G);
_hotkeyDisconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D);
}

View File

@ -66,4 +66,11 @@ class sdlInput
Uint32 _lastWindowID;
std::map<uint32_t, uint32_t> _remapList;
std::atomic<bool> _remapInitialized = false;
// hotkey handling
uint32_t _hotkeyModmask; // modifier keys mask
uint32_t _hotkeyFullscreen;
uint32_t _hotkeyResizable;
uint32_t _hotkeyGrab;
uint32_t _hotkeyDisconnect;
};

View File

@ -540,33 +540,28 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
WINPR_ASSERT(ev);
const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->keysym.scancode);
const SDL_Keymod mods = SDL_GetModState();
const auto mask = prefToMask();
const auto valFullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN);
const auto valResizeable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R);
const auto valGrab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G);
const auto valDisconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D);
if ((mods & mask) == mask)
if ((mods & _hotkeyModmask) == _hotkeyModmask)
{
if (ev->type == SDL_EVENT_KEY_DOWN)
{
if (ev->keysym.scancode == valFullscreen)
if (ev->keysym.scancode == _hotkeyFullscreen)
{
_sdl->update_fullscreen(!_sdl->fullscreen);
return TRUE;
}
if (ev->keysym.scancode == valResizeable)
if (ev->keysym.scancode == _hotkeyResizable)
{
_sdl->update_resizeable(!_sdl->resizeable);
return TRUE;
}
if (ev->keysym.scancode == valGrab)
if (ev->keysym.scancode == _hotkeyGrab)
{
keyboard_grab(ev->windowID, _sdl->grab_kbd ? SDL_FALSE : SDL_TRUE);
return TRUE;
}
if (ev->keysym.scancode == valDisconnect)
if (ev->keysym.scancode == _hotkeyDisconnect)
{
freerdp_abort_connect_context(_sdl->context());
return TRUE;
@ -613,4 +608,9 @@ BOOL sdlInput::mouse_grab(Uint32 windowID, SDL_bool enable)
sdlInput::sdlInput(SdlContext* sdl) : _sdl(sdl), _lastWindowID(UINT32_MAX)
{
_hotkeyModmask = prefToMask();
_hotkeyFullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN);
_hotkeyResizable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R);
_hotkeyGrab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G);
_hotkeyDisconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D);
}

View File

@ -66,4 +66,11 @@ class sdlInput
Uint32 _lastWindowID;
std::map<uint32_t, uint32_t> _remapList;
std::atomic<bool> _remapInitialized = false;
// hotkey handling
uint32_t _hotkeyModmask; // modifier keys mask
uint32_t _hotkeyFullscreen;
uint32_t _hotkeyResizable;
uint32_t _hotkeyGrab;
uint32_t _hotkeyDisconnect;
};