From cdc8d6210858d55a7a2d6b39a149d20728a01615 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 3 Jun 2024 10:57:54 +0200 Subject: [PATCH] [client,sdl] move parsing of hotkeys to constructor * implement that for SDL3 just like for SDL2 * rename members to conform to style of file --- client/SDL/SDL2/sdl_kbd.cpp | 20 ++++++++++---------- client/SDL/SDL2/sdl_kbd.hpp | 7 +++++-- client/SDL/SDL3/sdl_kbd.cpp | 20 ++++++++++---------- client/SDL/SDL3/sdl_kbd.hpp | 7 +++++++ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/client/SDL/SDL2/sdl_kbd.cpp b/client/SDL/SDL2/sdl_kbd.cpp index 059990b31..c3ba14d7c 100644 --- a/client/SDL/SDL2/sdl_kbd.cpp +++ b/client/SDL/SDL2/sdl_kbd.cpp @@ -555,27 +555,27 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev) const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->keysym.scancode); const SDL_Keymod mods = SDL_GetModState(); - if ((mods & hotkey_modmask) == hotkey_modmask) + if ((mods & _hotkeyModmask) == _hotkeyModmask) { if (ev->type == SDL_KEYDOWN) { - if (ev->keysym.scancode == hotkey_fullscreen) + if (ev->keysym.scancode == _hotkeyFullscreen) { _sdl->update_fullscreen(!_sdl->fullscreen); return TRUE; } - if (ev->keysym.scancode == hotkey_resizable) + if (ev->keysym.scancode == _hotkeyResizable) { _sdl->update_resizeable(!_sdl->resizeable); return TRUE; } - if (ev->keysym.scancode == hotkey_grab) + if (ev->keysym.scancode == _hotkeyGrab) { keyboard_grab(ev->windowID, _sdl->grab_kbd ? SDL_FALSE : SDL_TRUE); return TRUE; } - if (ev->keysym.scancode == hotkey_disconnect) + if (ev->keysym.scancode == _hotkeyDisconnect) { freerdp_abort_connect_context(_sdl->context()); return TRUE; @@ -622,9 +622,9 @@ BOOL sdlInput::mouse_grab(Uint32 windowID, SDL_bool enable) sdlInput::sdlInput(SdlContext* sdl) : _sdl(sdl), _lastWindowID(UINT32_MAX) { - hotkey_modmask = prefToMask(); - hotkey_fullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN); - hotkey_resizable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R); - hotkey_grab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G); - hotkey_disconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D); + _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); } diff --git a/client/SDL/SDL2/sdl_kbd.hpp b/client/SDL/SDL2/sdl_kbd.hpp index b486571be..3126d0a7b 100644 --- a/client/SDL/SDL2/sdl_kbd.hpp +++ b/client/SDL/SDL2/sdl_kbd.hpp @@ -68,6 +68,9 @@ class sdlInput std::atomic _remapInitialized = false; // hotkey handling - uint32_t hotkey_modmask; // modifier keys mask - uint32_t hotkey_fullscreen, hotkey_resizable, hotkey_grab, hotkey_disconnect; + uint32_t _hotkeyModmask; // modifier keys mask + uint32_t _hotkeyFullscreen; + uint32_t _hotkeyResizable; + uint32_t _hotkeyGrab; + uint32_t _hotkeyDisconnect; }; diff --git a/client/SDL/SDL3/sdl_kbd.cpp b/client/SDL/SDL3/sdl_kbd.cpp index e3635c256..211a94117 100644 --- a/client/SDL/SDL3/sdl_kbd.cpp +++ b/client/SDL/SDL3/sdl_kbd.cpp @@ -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); } diff --git a/client/SDL/SDL3/sdl_kbd.hpp b/client/SDL/SDL3/sdl_kbd.hpp index a60f4e7b1..24940a3b5 100644 --- a/client/SDL/SDL3/sdl_kbd.hpp +++ b/client/SDL/SDL3/sdl_kbd.hpp @@ -66,4 +66,11 @@ class sdlInput Uint32 _lastWindowID; std::map _remapList; std::atomic _remapInitialized = false; + + // hotkey handling + uint32_t _hotkeyModmask; // modifier keys mask + uint32_t _hotkeyFullscreen; + uint32_t _hotkeyResizable; + uint32_t _hotkeyGrab; + uint32_t _hotkeyDisconnect; };