[client,sdl] use keyboard_layout_remap*

use keyboard layout remap functions from core library
This commit is contained in:
akallabeth
2024-12-17 13:16:19 +01:00
parent c29e93f4b2
commit 375e28f5cb
4 changed files with 26 additions and 80 deletions

View File

@@ -511,38 +511,6 @@ bool sdlInput::extract(const std::string& token, uint32_t& key, uint32_t& value)
return freerdp_extract_key_value(token.c_str(), &key, &value);
}
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);
@@ -583,7 +551,7 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
}
}
auto scancode = remapScancode(rdp_scancode);
auto scancode = freerdp_keyboard_remap_key(_remapTable, rdp_scancode);
return freerdp_input_send_keyboard_event_ex(_sdl->context()->input, ev->type == SDL_KEYDOWN,
ev->repeat, scancode);
}
@@ -625,10 +593,18 @@ BOOL sdlInput::mouse_grab(Uint32 windowID, SDL_bool enable)
sdlInput::sdlInput(SdlContext* sdl)
: _sdl(sdl), _lastWindowID(UINT32_MAX), _hotkeyModmask(prefToMask())
{
auto list =
freerdp_settings_get_string(_sdl->context()->settings, FreeRDP_KeyboardRemappingList);
_remapTable = freerdp_keyboard_remap_string_to_list(list);
assert(_remapTable);
_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);
_hotkeyMinimize = prefKeyValue("SDL_Minimize", SDL_SCANCODE_M);
}
sdlInput::~sdlInput()
{
freerdp_keyboard_remap_free(_remapTable);
}

View File

@@ -26,6 +26,7 @@
#include <winpr/wtypes.h>
#include <freerdp/freerdp.h>
#include <freerdp/locale/keyboard.h>
#include <SDL.h>
#include "sdl_types.hpp"
@@ -36,7 +37,7 @@ class sdlInput
explicit sdlInput(SdlContext* sdl);
sdlInput(const sdlInput& other) = delete;
sdlInput(sdlInput&& other) = delete;
~sdlInput() = default;
~sdlInput();
sdlInput& operator=(const sdlInput& other) = delete;
sdlInput& operator=(sdlInput&& other) = delete;
@@ -62,13 +63,8 @@ class sdlInput
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();
SdlContext* _sdl;
Uint32 _lastWindowID;
std::map<uint32_t, uint32_t> _remapList;
std::atomic<bool> _remapInitialized = false;
// hotkey handling
uint32_t _hotkeyModmask; // modifier keys mask
@@ -77,4 +73,5 @@ class sdlInput
uint32_t _hotkeyGrab;
uint32_t _hotkeyDisconnect;
uint32_t _hotkeyMinimize;
FREERDP_REMAP_TABLE* _remapTable;
};

View File

@@ -487,38 +487,6 @@ bool sdlInput::extract(const std::string& token, uint32_t& key, uint32_t& value)
return freerdp_extract_key_value(token.c_str(), &key, &value);
}
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);
@@ -559,7 +527,7 @@ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
}
}
auto scancode = remapScancode(rdp_scancode);
auto scancode = freerdp_keyboard_remap_key(_remapTable, rdp_scancode);
return freerdp_input_send_keyboard_event_ex(
_sdl->context()->input, ev->type == SDL_EVENT_KEY_DOWN, ev->repeat, scancode);
}
@@ -600,10 +568,18 @@ BOOL sdlInput::mouse_grab(Uint32 windowID, bool enable)
sdlInput::sdlInput(SdlContext* sdl)
: _sdl(sdl), _lastWindowID(UINT32_MAX), _hotkeyModmask(prefToMask())
{
auto list =
freerdp_settings_get_string(_sdl->context()->settings, FreeRDP_KeyboardRemappingList);
_remapTable = freerdp_keyboard_remap_string_to_list(list);
assert(_remapTable);
_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);
_hotkeyMinimize = prefKeyValue("SDL_Minimize", SDL_SCANCODE_M);
}
sdlInput::~sdlInput()
{
freerdp_keyboard_remap_free(_remapTable);
}

View File

@@ -26,6 +26,7 @@
#include <winpr/wtypes.h>
#include <freerdp/freerdp.h>
#include <freerdp/locale/keyboard.h>
#include <SDL3/SDL.h>
#include "sdl_types.hpp"
@@ -36,7 +37,7 @@ class sdlInput
explicit sdlInput(SdlContext* sdl);
sdlInput(const sdlInput& other) = delete;
sdlInput(sdlInput&& other) = delete;
~sdlInput() = default;
~sdlInput();
sdlInput& operator=(const sdlInput& other) = delete;
sdlInput& operator=(sdlInput&& other) = delete;
@@ -62,13 +63,8 @@ class sdlInput
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();
SdlContext* _sdl;
Uint32 _lastWindowID;
std::map<uint32_t, uint32_t> _remapList;
std::atomic<bool> _remapInitialized = false;
// hotkey handling
uint32_t _hotkeyModmask; // modifier keys mask
@@ -77,4 +73,5 @@ class sdlInput
uint32_t _hotkeyGrab;
uint32_t _hotkeyDisconnect;
uint32_t _hotkeyMinimize;
FREERDP_REMAP_TABLE* _remapTable;
};