diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:25:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:25:37 +0000 |
commit | 3c206f96fd1e102a13b2971778060fef4be7afbc (patch) | |
tree | 26d54f12b25a491844130c7934c60d97c85807b7 /client/SDL | |
parent | Releasing progress-linux version 3.5.0+dfsg1-1~progress7.99u1. (diff) | |
download | freerdp3-3c206f96fd1e102a13b2971778060fef4be7afbc.tar.xz freerdp3-3c206f96fd1e102a13b2971778060fef4be7afbc.zip |
Merging upstream version 3.5.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'client/SDL')
-rw-r--r-- | client/SDL/dialogs/sdl_connection_dialog.hpp | 14 | ||||
-rw-r--r-- | client/SDL/sdl_disp.cpp | 5 | ||||
-rw-r--r-- | client/SDL/sdl_kbd.cpp | 65 | ||||
-rw-r--r-- | client/SDL/sdl_kbd.hpp | 13 |
4 files changed, 88 insertions, 9 deletions
diff --git a/client/SDL/dialogs/sdl_connection_dialog.hpp b/client/SDL/dialogs/sdl_connection_dialog.hpp index f21f538..57e5596 100644 --- a/client/SDL/dialogs/sdl_connection_dialog.hpp +++ b/client/SDL/dialogs/sdl_connection_dialog.hpp @@ -89,15 +89,15 @@ class SDLConnectionDialog private: struct widget_cfg_t { - SDL_Color fgcolor; - SDL_Color bgcolor; + SDL_Color fgcolor = {}; + SDL_Color bgcolor = {}; SdlWidget widget; }; private: - rdpContext* _context; - SDL_Window* _window; - SDL_Renderer* _renderer; + rdpContext* _context = nullptr; + SDL_Window* _window = nullptr; + SDL_Renderer* _renderer = nullptr; mutable std::mutex _mux; std::string _title; std::string _msg; @@ -124,6 +124,6 @@ class SDLConnectionDialogHider SDLConnectionDialog* get(rdpContext* context); private: - SDLConnectionDialog* _dialog; - bool _visible; + SDLConnectionDialog* _dialog = nullptr; + bool _visible = false; }; diff --git a/client/SDL/sdl_disp.cpp b/client/SDL/sdl_disp.cpp index ffd13c8..34863ba 100644 --- a/client/SDL/sdl_disp.cpp +++ b/client/SDL/sdl_disp.cpp @@ -142,6 +142,8 @@ static BOOL sdl_disp_check_context(void* context, SdlContext** ppsdl, sdlDispCon return FALSE; auto sdl = get_context(context); + if (!sdl) + return FALSE; if (!sdl->context()->settings) return FALSE; @@ -200,6 +202,9 @@ Uint32 sdlDispContext::OnTimer(Uint32 interval, void* param) return 0; SdlContext* sdl = ctx->_sdl; + if (!sdl) + return 0; + sdlDispContext* sdlDisp = nullptr; rdpSettings* settings = nullptr; diff --git a/client/SDL/sdl_kbd.cpp b/client/SDL/sdl_kbd.cpp index 984614e..c6e668d 100644 --- a/client/SDL/sdl_kbd.cpp +++ b/client/SDL/sdl_kbd.cpp @@ -488,6 +488,66 @@ uint32_t sdlInput::prefKeyValue(const std::string& key, uint32_t fallback) return val; } +std::list<std::string> sdlInput::tokenize(const std::string& data, const std::string& delimiter) +{ + size_t lastpos = 0; + size_t pos = 0; + std::list<std::string> list; + while ((pos = data.find(delimiter, lastpos)) != std::string::npos) + { + auto token = data.substr(lastpos, pos); + lastpos = pos + 1; + list.push_back(token); + } + auto token = data.substr(lastpos); + list.push_back(token); + return list; +} + +bool sdlInput::extract(const std::string& token, uint32_t& key, uint32_t& value) +{ + int rc = sscanf(token.c_str(), "%" PRIu32 "=%" PRIu32, &key, &value); + if (rc != 2) + rc = sscanf(token.c_str(), "%" PRIx32 "=%" PRIx32 "", &key, &value); + if (rc != 2) + rc = sscanf(token.c_str(), "%" PRIu32 "=%" PRIx32, &key, &value); + if (rc != 2) + rc = sscanf(token.c_str(), "%" PRIx32 "=%" PRIu32, &key, &value); + return (rc == 2); +} + +uint32_t sdlInput::remapScancode(uint32_t scancode) +{ + if (!_remapInitialized.exchange(true)) + remapInitialize(); + auto it = _remapList.find(scancode); + if (it != _remapList.end()) + return it->second; + return scancode; +} + +void sdlInput::remapInitialize() +{ + WINPR_ASSERT(_sdl); + + auto context = _sdl->context(); + WINPR_ASSERT(context); + auto KeyboardRemappingList = + freerdp_settings_get_string(context->settings, FreeRDP_KeyboardRemappingList); + if (!KeyboardRemappingList) + return; + + auto list = tokenize(KeyboardRemappingList); + for (auto& token : list) + { + uint32_t key = 0; + uint32_t value = 0; + if (!extract(token, key, value)) + continue; + _remapList.emplace(key, value); + } +} + BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev) { WINPR_ASSERT(ev); @@ -526,8 +586,10 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev) } } } + + auto scancode = remapScancode(rdp_scancode); return freerdp_input_send_keyboard_event_ex(_sdl->context()->input, ev->type == SDL_KEYDOWN, - ev->repeat, rdp_scancode); + ev->repeat, scancode); } BOOL sdlInput::keyboard_grab(Uint32 windowID, SDL_bool enable) @@ -564,5 +626,4 @@ BOOL sdlInput::mouse_grab(Uint32 windowID, SDL_bool enable) sdlInput::sdlInput(SdlContext* sdl) : _sdl(sdl), _lastWindowID(UINT32_MAX) { - WINPR_ASSERT(_sdl); } diff --git a/client/SDL/sdl_kbd.hpp b/client/SDL/sdl_kbd.hpp index 2a6c7fa..c75da4d 100644 --- a/client/SDL/sdl_kbd.hpp +++ b/client/SDL/sdl_kbd.hpp @@ -20,6 +20,9 @@ #pragma once #include <string> +#include <map> +#include <list> +#include <atomic> #include <winpr/wtypes.h> #include <freerdp/freerdp.h> @@ -51,6 +54,16 @@ class sdlInput static uint32_t prefKeyValue(const std::string& key, uint32_t fallback = SDL_SCANCODE_UNKNOWN); private: + static std::list<std::string> tokenize(const std::string& data, + const std::string& delimiter = ","); + static bool extract(const std::string& token, uint32_t& key, uint32_t& value); + + uint32_t remapScancode(uint32_t scancode); + void remapInitialize(); + + private: SdlContext* _sdl; Uint32 _lastWindowID; + std::map<uint32_t, uint32_t> _remapList; + std::atomic<bool> _remapInitialized = false; }; |