20 #include "sdl_kbd.hpp"
21 #include "sdl_disp.hpp"
22 #include "sdl_freerdp.hpp"
23 #include "sdl_utils.hpp"
24 #include "sdl_prefs.hpp"
26 #include <SDL3/SDL_oldnames.h>
30 #include <freerdp/utils/string.h>
31 #include <freerdp/scancode.h>
33 #include <freerdp/log.h>
34 #define TAG CLIENT_TAG("SDL.kbd")
49 static const scancode_entry_t map[] = {
50 ENTRY(SDL_SCANCODE_UNKNOWN, RDP_SCANCODE_UNKNOWN),
51 ENTRY(SDL_SCANCODE_A, RDP_SCANCODE_KEY_A),
52 ENTRY(SDL_SCANCODE_B, RDP_SCANCODE_KEY_B),
53 ENTRY(SDL_SCANCODE_C, RDP_SCANCODE_KEY_C),
54 ENTRY(SDL_SCANCODE_D, RDP_SCANCODE_KEY_D),
55 ENTRY(SDL_SCANCODE_E, RDP_SCANCODE_KEY_E),
56 ENTRY(SDL_SCANCODE_F, RDP_SCANCODE_KEY_F),
57 ENTRY(SDL_SCANCODE_G, RDP_SCANCODE_KEY_G),
58 ENTRY(SDL_SCANCODE_H, RDP_SCANCODE_KEY_H),
59 ENTRY(SDL_SCANCODE_I, RDP_SCANCODE_KEY_I),
60 ENTRY(SDL_SCANCODE_J, RDP_SCANCODE_KEY_J),
61 ENTRY(SDL_SCANCODE_K, RDP_SCANCODE_KEY_K),
62 ENTRY(SDL_SCANCODE_L, RDP_SCANCODE_KEY_L),
63 ENTRY(SDL_SCANCODE_M, RDP_SCANCODE_KEY_M),
64 ENTRY(SDL_SCANCODE_N, RDP_SCANCODE_KEY_N),
65 ENTRY(SDL_SCANCODE_O, RDP_SCANCODE_KEY_O),
66 ENTRY(SDL_SCANCODE_P, RDP_SCANCODE_KEY_P),
67 ENTRY(SDL_SCANCODE_Q, RDP_SCANCODE_KEY_Q),
68 ENTRY(SDL_SCANCODE_R, RDP_SCANCODE_KEY_R),
69 ENTRY(SDL_SCANCODE_S, RDP_SCANCODE_KEY_S),
70 ENTRY(SDL_SCANCODE_T, RDP_SCANCODE_KEY_T),
71 ENTRY(SDL_SCANCODE_U, RDP_SCANCODE_KEY_U),
72 ENTRY(SDL_SCANCODE_V, RDP_SCANCODE_KEY_V),
73 ENTRY(SDL_SCANCODE_W, RDP_SCANCODE_KEY_W),
74 ENTRY(SDL_SCANCODE_X, RDP_SCANCODE_KEY_X),
75 ENTRY(SDL_SCANCODE_Y, RDP_SCANCODE_KEY_Y),
76 ENTRY(SDL_SCANCODE_Z, RDP_SCANCODE_KEY_Z),
77 ENTRY(SDL_SCANCODE_1, RDP_SCANCODE_KEY_1),
78 ENTRY(SDL_SCANCODE_2, RDP_SCANCODE_KEY_2),
79 ENTRY(SDL_SCANCODE_3, RDP_SCANCODE_KEY_3),
80 ENTRY(SDL_SCANCODE_4, RDP_SCANCODE_KEY_4),
81 ENTRY(SDL_SCANCODE_5, RDP_SCANCODE_KEY_5),
82 ENTRY(SDL_SCANCODE_6, RDP_SCANCODE_KEY_6),
83 ENTRY(SDL_SCANCODE_7, RDP_SCANCODE_KEY_7),
84 ENTRY(SDL_SCANCODE_8, RDP_SCANCODE_KEY_8),
85 ENTRY(SDL_SCANCODE_9, RDP_SCANCODE_KEY_9),
86 ENTRY(SDL_SCANCODE_0, RDP_SCANCODE_KEY_0),
87 ENTRY(SDL_SCANCODE_RETURN, RDP_SCANCODE_RETURN),
88 ENTRY(SDL_SCANCODE_ESCAPE, RDP_SCANCODE_ESCAPE),
89 ENTRY(SDL_SCANCODE_BACKSPACE, RDP_SCANCODE_BACKSPACE),
90 ENTRY(SDL_SCANCODE_TAB, RDP_SCANCODE_TAB),
91 ENTRY(SDL_SCANCODE_SPACE, RDP_SCANCODE_SPACE),
92 ENTRY(SDL_SCANCODE_MINUS, RDP_SCANCODE_OEM_MINUS),
93 ENTRY(SDL_SCANCODE_CAPSLOCK, RDP_SCANCODE_CAPSLOCK),
94 ENTRY(SDL_SCANCODE_F1, RDP_SCANCODE_F1),
95 ENTRY(SDL_SCANCODE_F2, RDP_SCANCODE_F2),
96 ENTRY(SDL_SCANCODE_F3, RDP_SCANCODE_F3),
97 ENTRY(SDL_SCANCODE_F4, RDP_SCANCODE_F4),
98 ENTRY(SDL_SCANCODE_F5, RDP_SCANCODE_F5),
99 ENTRY(SDL_SCANCODE_F6, RDP_SCANCODE_F6),
100 ENTRY(SDL_SCANCODE_F7, RDP_SCANCODE_F7),
101 ENTRY(SDL_SCANCODE_F8, RDP_SCANCODE_F8),
102 ENTRY(SDL_SCANCODE_F9, RDP_SCANCODE_F9),
103 ENTRY(SDL_SCANCODE_F10, RDP_SCANCODE_F10),
104 ENTRY(SDL_SCANCODE_F11, RDP_SCANCODE_F11),
105 ENTRY(SDL_SCANCODE_F12, RDP_SCANCODE_F12),
106 ENTRY(SDL_SCANCODE_F13, RDP_SCANCODE_F13),
107 ENTRY(SDL_SCANCODE_F14, RDP_SCANCODE_F14),
108 ENTRY(SDL_SCANCODE_F15, RDP_SCANCODE_F15),
109 ENTRY(SDL_SCANCODE_F16, RDP_SCANCODE_F16),
110 ENTRY(SDL_SCANCODE_F17, RDP_SCANCODE_F17),
111 ENTRY(SDL_SCANCODE_F18, RDP_SCANCODE_F18),
112 ENTRY(SDL_SCANCODE_F19, RDP_SCANCODE_F19),
113 ENTRY(SDL_SCANCODE_F20, RDP_SCANCODE_F20),
114 ENTRY(SDL_SCANCODE_F21, RDP_SCANCODE_F21),
115 ENTRY(SDL_SCANCODE_F22, RDP_SCANCODE_F22),
116 ENTRY(SDL_SCANCODE_F23, RDP_SCANCODE_F23),
117 ENTRY(SDL_SCANCODE_F24, RDP_SCANCODE_F24),
118 ENTRY(SDL_SCANCODE_NUMLOCKCLEAR, RDP_SCANCODE_NUMLOCK),
119 ENTRY(SDL_SCANCODE_KP_DIVIDE, RDP_SCANCODE_DIVIDE),
120 ENTRY(SDL_SCANCODE_KP_MULTIPLY, RDP_SCANCODE_MULTIPLY),
121 ENTRY(SDL_SCANCODE_KP_MINUS, RDP_SCANCODE_SUBTRACT),
122 ENTRY(SDL_SCANCODE_KP_PLUS, RDP_SCANCODE_ADD),
123 ENTRY(SDL_SCANCODE_KP_ENTER, RDP_SCANCODE_RETURN_KP),
124 ENTRY(SDL_SCANCODE_KP_1, RDP_SCANCODE_NUMPAD1),
125 ENTRY(SDL_SCANCODE_KP_2, RDP_SCANCODE_NUMPAD2),
126 ENTRY(SDL_SCANCODE_KP_3, RDP_SCANCODE_NUMPAD3),
127 ENTRY(SDL_SCANCODE_KP_4, RDP_SCANCODE_NUMPAD4),
128 ENTRY(SDL_SCANCODE_KP_5, RDP_SCANCODE_NUMPAD5),
129 ENTRY(SDL_SCANCODE_KP_6, RDP_SCANCODE_NUMPAD6),
130 ENTRY(SDL_SCANCODE_KP_7, RDP_SCANCODE_NUMPAD7),
131 ENTRY(SDL_SCANCODE_KP_8, RDP_SCANCODE_NUMPAD8),
132 ENTRY(SDL_SCANCODE_KP_9, RDP_SCANCODE_NUMPAD9),
133 ENTRY(SDL_SCANCODE_KP_0, RDP_SCANCODE_NUMPAD0),
134 ENTRY(SDL_SCANCODE_KP_PERIOD, RDP_SCANCODE_OEM_PERIOD),
135 ENTRY(SDL_SCANCODE_LCTRL, RDP_SCANCODE_LCONTROL),
136 ENTRY(SDL_SCANCODE_LSHIFT, RDP_SCANCODE_LSHIFT),
137 ENTRY(SDL_SCANCODE_LALT, RDP_SCANCODE_LMENU),
138 ENTRY(SDL_SCANCODE_LGUI, RDP_SCANCODE_LWIN),
139 ENTRY(SDL_SCANCODE_RCTRL, RDP_SCANCODE_RCONTROL),
140 ENTRY(SDL_SCANCODE_RSHIFT, RDP_SCANCODE_RSHIFT),
141 ENTRY(SDL_SCANCODE_RALT, RDP_SCANCODE_RMENU),
142 ENTRY(SDL_SCANCODE_RGUI, RDP_SCANCODE_RWIN),
143 ENTRY(SDL_SCANCODE_MODE, RDP_SCANCODE_APPS),
144 ENTRY(SDL_SCANCODE_MUTE, RDP_SCANCODE_VOLUME_MUTE),
145 ENTRY(SDL_SCANCODE_VOLUMEUP, RDP_SCANCODE_VOLUME_UP),
146 ENTRY(SDL_SCANCODE_VOLUMEDOWN, RDP_SCANCODE_VOLUME_DOWN),
147 ENTRY(SDL_SCANCODE_GRAVE, RDP_SCANCODE_OEM_3),
148 ENTRY(SDL_SCANCODE_COMMA, RDP_SCANCODE_OEM_COMMA),
149 ENTRY(SDL_SCANCODE_PERIOD, RDP_SCANCODE_OEM_PERIOD),
150 ENTRY(SDL_SCANCODE_SLASH, RDP_SCANCODE_OEM_2),
151 ENTRY(SDL_SCANCODE_BACKSLASH, RDP_SCANCODE_OEM_5),
152 ENTRY(SDL_SCANCODE_SCROLLLOCK, RDP_SCANCODE_SCROLLLOCK),
153 ENTRY(SDL_SCANCODE_INSERT, RDP_SCANCODE_INSERT),
154 ENTRY(SDL_SCANCODE_PRINTSCREEN, RDP_SCANCODE_PRINTSCREEN),
155 ENTRY(SDL_SCANCODE_HOME, RDP_SCANCODE_HOME),
156 ENTRY(SDL_SCANCODE_DELETE, RDP_SCANCODE_DELETE),
157 ENTRY(SDL_SCANCODE_RIGHT, RDP_SCANCODE_RIGHT),
158 ENTRY(SDL_SCANCODE_LEFT, RDP_SCANCODE_LEFT),
159 ENTRY(SDL_SCANCODE_DOWN, RDP_SCANCODE_DOWN),
160 ENTRY(SDL_SCANCODE_UP, RDP_SCANCODE_UP),
161 ENTRY(SDL_SCANCODE_SEMICOLON, RDP_SCANCODE_OEM_1),
162 ENTRY(SDL_SCANCODE_PAUSE, RDP_SCANCODE_PAUSE),
163 ENTRY(SDL_SCANCODE_PAGEUP, RDP_SCANCODE_PRIOR),
164 ENTRY(SDL_SCANCODE_END, RDP_SCANCODE_END),
165 ENTRY(SDL_SCANCODE_PAGEDOWN, RDP_SCANCODE_NEXT),
166 ENTRY(SDL_SCANCODE_MEDIA_NEXT_TRACK, RDP_SCANCODE_MEDIA_NEXT_TRACK),
167 ENTRY(SDL_SCANCODE_MEDIA_PREVIOUS_TRACK, RDP_SCANCODE_MEDIA_PREV_TRACK),
168 ENTRY(SDL_SCANCODE_MEDIA_STOP, RDP_SCANCODE_MEDIA_STOP),
169 ENTRY(SDL_SCANCODE_MEDIA_PLAY, RDP_SCANCODE_MEDIA_PLAY_PAUSE),
170 ENTRY(SDL_SCANCODE_MUTE, RDP_SCANCODE_VOLUME_MUTE),
171 ENTRY(SDL_SCANCODE_MEDIA_SELECT, RDP_SCANCODE_LAUNCH_MEDIA_SELECT),
172 ENTRY(SDL_SCANCODE_SYSREQ, RDP_SCANCODE_SYSREQ),
173 ENTRY(SDL_SCANCODE_LEFTBRACKET, RDP_SCANCODE_OEM_4),
174 ENTRY(SDL_SCANCODE_RIGHTBRACKET, RDP_SCANCODE_OEM_6),
175 ENTRY(SDL_SCANCODE_APOSTROPHE, RDP_SCANCODE_OEM_7),
176 ENTRY(SDL_SCANCODE_NONUSBACKSLASH, RDP_SCANCODE_OEM_102),
177 ENTRY(SDL_SCANCODE_SLEEP, RDP_SCANCODE_SLEEP),
178 ENTRY(SDL_SCANCODE_EQUALS, RDP_SCANCODE_OEM_PLUS),
179 ENTRY(SDL_SCANCODE_KP_COMMA, RDP_SCANCODE_DECIMAL),
180 ENTRY(SDL_SCANCODE_FIND, RDP_SCANCODE_BROWSER_SEARCH),
181 ENTRY(SDL_SCANCODE_RETURN2, RDP_SCANCODE_RETURN_KP),
182 ENTRY(SDL_SCANCODE_AC_SEARCH, RDP_SCANCODE_BROWSER_SEARCH),
183 ENTRY(SDL_SCANCODE_AC_HOME, RDP_SCANCODE_BROWSER_HOME),
184 ENTRY(SDL_SCANCODE_AC_BACK, RDP_SCANCODE_BROWSER_BACK),
185 ENTRY(SDL_SCANCODE_AC_FORWARD, RDP_SCANCODE_BROWSER_FORWARD),
186 ENTRY(SDL_SCANCODE_AC_STOP, RDP_SCANCODE_BROWSER_STOP),
189 ENTRY(SDL_SCANCODE_NONUSHASH, RDP_SCANCODE_UNKNOWN),
190 ENTRY(SDL_SCANCODE_APPLICATION, RDP_SCANCODE_UNKNOWN),
191 ENTRY(SDL_SCANCODE_POWER, RDP_SCANCODE_UNKNOWN),
192 ENTRY(SDL_SCANCODE_KP_EQUALS, RDP_SCANCODE_UNKNOWN),
193 ENTRY(SDL_SCANCODE_EXECUTE, RDP_SCANCODE_UNKNOWN),
194 ENTRY(SDL_SCANCODE_HELP, RDP_SCANCODE_UNKNOWN),
195 ENTRY(SDL_SCANCODE_MENU, RDP_SCANCODE_UNKNOWN),
196 ENTRY(SDL_SCANCODE_SELECT, RDP_SCANCODE_UNKNOWN),
197 ENTRY(SDL_SCANCODE_STOP, RDP_SCANCODE_UNKNOWN),
198 ENTRY(SDL_SCANCODE_AGAIN, RDP_SCANCODE_UNKNOWN),
199 ENTRY(SDL_SCANCODE_UNDO, RDP_SCANCODE_UNKNOWN),
200 ENTRY(SDL_SCANCODE_CUT, RDP_SCANCODE_UNKNOWN),
201 ENTRY(SDL_SCANCODE_COPY, RDP_SCANCODE_UNKNOWN),
202 ENTRY(SDL_SCANCODE_PASTE, RDP_SCANCODE_UNKNOWN),
203 ENTRY(SDL_SCANCODE_KP_EQUALSAS400, RDP_SCANCODE_UNKNOWN),
204 ENTRY(SDL_SCANCODE_INTERNATIONAL1, RDP_SCANCODE_UNKNOWN),
205 ENTRY(SDL_SCANCODE_INTERNATIONAL2, RDP_SCANCODE_UNKNOWN),
206 ENTRY(SDL_SCANCODE_INTERNATIONAL3, RDP_SCANCODE_UNKNOWN),
207 ENTRY(SDL_SCANCODE_INTERNATIONAL4, RDP_SCANCODE_UNKNOWN),
208 ENTRY(SDL_SCANCODE_INTERNATIONAL5, RDP_SCANCODE_UNKNOWN),
209 ENTRY(SDL_SCANCODE_INTERNATIONAL6, RDP_SCANCODE_UNKNOWN),
210 ENTRY(SDL_SCANCODE_INTERNATIONAL7, RDP_SCANCODE_UNKNOWN),
211 ENTRY(SDL_SCANCODE_INTERNATIONAL8, RDP_SCANCODE_UNKNOWN),
212 ENTRY(SDL_SCANCODE_INTERNATIONAL9, RDP_SCANCODE_UNKNOWN),
213 ENTRY(SDL_SCANCODE_LANG1, RDP_SCANCODE_UNKNOWN),
214 ENTRY(SDL_SCANCODE_LANG2, RDP_SCANCODE_UNKNOWN),
215 ENTRY(SDL_SCANCODE_LANG3, RDP_SCANCODE_UNKNOWN),
216 ENTRY(SDL_SCANCODE_LANG4, RDP_SCANCODE_UNKNOWN),
217 ENTRY(SDL_SCANCODE_LANG5, RDP_SCANCODE_UNKNOWN),
218 ENTRY(SDL_SCANCODE_LANG6, RDP_SCANCODE_UNKNOWN),
219 ENTRY(SDL_SCANCODE_LANG7, RDP_SCANCODE_UNKNOWN),
220 ENTRY(SDL_SCANCODE_LANG8, RDP_SCANCODE_UNKNOWN),
221 ENTRY(SDL_SCANCODE_LANG9, RDP_SCANCODE_UNKNOWN),
222 ENTRY(SDL_SCANCODE_ALTERASE, RDP_SCANCODE_UNKNOWN),
223 ENTRY(SDL_SCANCODE_CANCEL, RDP_SCANCODE_UNKNOWN),
224 ENTRY(SDL_SCANCODE_CLEAR, RDP_SCANCODE_UNKNOWN),
225 ENTRY(SDL_SCANCODE_PRIOR, RDP_SCANCODE_UNKNOWN),
226 ENTRY(SDL_SCANCODE_SEPARATOR, RDP_SCANCODE_UNKNOWN),
227 ENTRY(SDL_SCANCODE_OUT, RDP_SCANCODE_UNKNOWN),
228 ENTRY(SDL_SCANCODE_OPER, RDP_SCANCODE_UNKNOWN),
229 ENTRY(SDL_SCANCODE_CLEARAGAIN, RDP_SCANCODE_UNKNOWN),
230 ENTRY(SDL_SCANCODE_CRSEL, RDP_SCANCODE_UNKNOWN),
231 ENTRY(SDL_SCANCODE_EXSEL, RDP_SCANCODE_UNKNOWN),
232 ENTRY(SDL_SCANCODE_KP_00, RDP_SCANCODE_UNKNOWN),
233 ENTRY(SDL_SCANCODE_KP_000, RDP_SCANCODE_UNKNOWN),
234 ENTRY(SDL_SCANCODE_THOUSANDSSEPARATOR, RDP_SCANCODE_UNKNOWN),
235 ENTRY(SDL_SCANCODE_DECIMALSEPARATOR, RDP_SCANCODE_UNKNOWN),
236 ENTRY(SDL_SCANCODE_CURRENCYUNIT, RDP_SCANCODE_UNKNOWN),
237 ENTRY(SDL_SCANCODE_CURRENCYSUBUNIT, RDP_SCANCODE_UNKNOWN),
238 ENTRY(SDL_SCANCODE_KP_LEFTPAREN, RDP_SCANCODE_UNKNOWN),
239 ENTRY(SDL_SCANCODE_KP_RIGHTPAREN, RDP_SCANCODE_UNKNOWN),
240 ENTRY(SDL_SCANCODE_KP_LEFTBRACE, RDP_SCANCODE_UNKNOWN),
241 ENTRY(SDL_SCANCODE_KP_RIGHTBRACE, RDP_SCANCODE_UNKNOWN),
242 ENTRY(SDL_SCANCODE_KP_TAB, RDP_SCANCODE_UNKNOWN),
243 ENTRY(SDL_SCANCODE_KP_BACKSPACE, RDP_SCANCODE_UNKNOWN),
244 ENTRY(SDL_SCANCODE_KP_A, RDP_SCANCODE_UNKNOWN),
245 ENTRY(SDL_SCANCODE_KP_B, RDP_SCANCODE_UNKNOWN),
246 ENTRY(SDL_SCANCODE_KP_C, RDP_SCANCODE_UNKNOWN),
247 ENTRY(SDL_SCANCODE_KP_D, RDP_SCANCODE_UNKNOWN),
248 ENTRY(SDL_SCANCODE_KP_E, RDP_SCANCODE_UNKNOWN),
249 ENTRY(SDL_SCANCODE_KP_F, RDP_SCANCODE_UNKNOWN),
250 ENTRY(SDL_SCANCODE_KP_XOR, RDP_SCANCODE_UNKNOWN),
251 ENTRY(SDL_SCANCODE_KP_POWER, RDP_SCANCODE_UNKNOWN),
252 ENTRY(SDL_SCANCODE_KP_PERCENT, RDP_SCANCODE_UNKNOWN),
253 ENTRY(SDL_SCANCODE_KP_LESS, RDP_SCANCODE_UNKNOWN),
254 ENTRY(SDL_SCANCODE_KP_GREATER, RDP_SCANCODE_UNKNOWN),
255 ENTRY(SDL_SCANCODE_KP_AMPERSAND, RDP_SCANCODE_UNKNOWN),
256 ENTRY(SDL_SCANCODE_KP_DBLAMPERSAND, RDP_SCANCODE_UNKNOWN),
257 ENTRY(SDL_SCANCODE_KP_VERTICALBAR, RDP_SCANCODE_UNKNOWN),
258 ENTRY(SDL_SCANCODE_KP_DBLVERTICALBAR, RDP_SCANCODE_UNKNOWN),
259 ENTRY(SDL_SCANCODE_KP_COLON, RDP_SCANCODE_UNKNOWN),
260 ENTRY(SDL_SCANCODE_KP_HASH, RDP_SCANCODE_UNKNOWN),
261 ENTRY(SDL_SCANCODE_KP_SPACE, RDP_SCANCODE_UNKNOWN),
262 ENTRY(SDL_SCANCODE_KP_AT, RDP_SCANCODE_UNKNOWN),
263 ENTRY(SDL_SCANCODE_KP_EXCLAM, RDP_SCANCODE_UNKNOWN),
264 ENTRY(SDL_SCANCODE_KP_MEMSTORE, RDP_SCANCODE_UNKNOWN),
265 ENTRY(SDL_SCANCODE_KP_MEMRECALL, RDP_SCANCODE_UNKNOWN),
266 ENTRY(SDL_SCANCODE_KP_MEMCLEAR, RDP_SCANCODE_UNKNOWN),
267 ENTRY(SDL_SCANCODE_KP_MEMADD, RDP_SCANCODE_UNKNOWN),
268 ENTRY(SDL_SCANCODE_KP_MEMSUBTRACT, RDP_SCANCODE_UNKNOWN),
269 ENTRY(SDL_SCANCODE_KP_MEMMULTIPLY, RDP_SCANCODE_UNKNOWN),
270 ENTRY(SDL_SCANCODE_KP_MEMDIVIDE, RDP_SCANCODE_UNKNOWN),
271 ENTRY(SDL_SCANCODE_KP_PLUSMINUS, RDP_SCANCODE_UNKNOWN),
272 ENTRY(SDL_SCANCODE_KP_CLEAR, RDP_SCANCODE_UNKNOWN),
273 ENTRY(SDL_SCANCODE_KP_CLEARENTRY, RDP_SCANCODE_UNKNOWN),
274 ENTRY(SDL_SCANCODE_KP_BINARY, RDP_SCANCODE_UNKNOWN),
275 ENTRY(SDL_SCANCODE_KP_OCTAL, RDP_SCANCODE_UNKNOWN),
276 ENTRY(SDL_SCANCODE_KP_DECIMAL, RDP_SCANCODE_UNKNOWN),
277 ENTRY(SDL_SCANCODE_KP_HEXADECIMAL, RDP_SCANCODE_UNKNOWN),
278 ENTRY(SDL_SCANCODE_AC_REFRESH, RDP_SCANCODE_UNKNOWN),
279 ENTRY(SDL_SCANCODE_AC_BOOKMARKS, RDP_SCANCODE_UNKNOWN),
280 ENTRY(SDL_SCANCODE_MEDIA_EJECT, RDP_SCANCODE_UNKNOWN),
281 ENTRY(SDL_SCANCODE_MEDIA_REWIND, RDP_SCANCODE_UNKNOWN),
282 ENTRY(SDL_SCANCODE_MEDIA_FAST_FORWARD, RDP_SCANCODE_UNKNOWN)
286 static UINT32 sdl_get_kbd_flags()
290 SDL_Keymod mod = SDL_GetModState();
291 if ((mod & SDL_KMOD_NUM) != 0)
292 flags |= KBD_SYNC_NUM_LOCK;
293 if ((mod & SDL_KMOD_CAPS) != 0)
294 flags |= KBD_SYNC_CAPS_LOCK;
295 if ((mod & SDL_KMOD_SCROLL) != 0)
296 flags |= KBD_SYNC_SCROLL_LOCK;
303 BOOL sdlInput::keyboard_sync_state()
305 const UINT32 syncFlags = sdl_get_kbd_flags();
306 return freerdp_input_send_synchronize_event(_sdl->context()->input, syncFlags);
309 BOOL sdlInput::keyboard_focus_in()
311 auto input = _sdl->context()->input;
314 auto syncFlags = sdl_get_kbd_flags();
315 freerdp_input_send_focus_in_event(input, syncFlags);
322 if (XQueryPointer(xfc->display, xfc->window->handle, &w, &w, &d, &d, &x, &y, &state))
324 if ((x >= 0) && (x < xfc->window->width) && (y >= 0) && (y < xfc->window->height))
326 xf_event_adjust_coordinates(xfc, &x, &y);
327 freerdp_client_send_button_event(&xfc->common, FALSE, PTR_FLAGS_MOVE, x, y);
335 BOOL sdlInput::keyboard_set_indicators(rdpContext* context, UINT16 led_flags)
337 WINPR_UNUSED(context);
339 int state = SDL_KMOD_NONE;
341 if ((led_flags & KBD_SYNC_NUM_LOCK) != 0)
342 state |= SDL_KMOD_NUM;
343 if ((led_flags & KBD_SYNC_CAPS_LOCK) != 0)
344 state |= SDL_KMOD_CAPS;
345 if ((led_flags & KBD_SYNC_SCROLL_LOCK) != 0)
346 state |= SDL_KMOD_SCROLL;
350 SDL_SetModState(
static_cast<SDL_Keymod
>(state));
356 BOOL sdlInput::keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
363 "KeyboardSetImeStatus(unitId=%04" PRIx16
", imeState=%08" PRIx32
364 ", imeConvMode=%08" PRIx32
") ignored",
365 imeId, imeState, imeConvMode);
369 uint32_t sdlInput::prefToMask()
371 const std::map<std::string, uint32_t> mapping = {
372 {
"KMOD_LSHIFT", SDL_KMOD_LSHIFT }, {
"KMOD_RSHIFT", SDL_KMOD_RSHIFT },
373 {
"KMOD_LCTRL", SDL_KMOD_LCTRL }, {
"KMOD_RCTRL", SDL_KMOD_RCTRL },
374 {
"KMOD_LALT", SDL_KMOD_LALT }, {
"KMOD_RALT", SDL_KMOD_RALT },
375 {
"KMOD_LGUI", SDL_KMOD_LGUI }, {
"KMOD_RGUI", SDL_KMOD_RGUI },
376 {
"KMOD_NUM", SDL_KMOD_NUM }, {
"KMOD_CAPS", SDL_KMOD_CAPS },
377 {
"KMOD_MODE", SDL_KMOD_MODE }, {
"KMOD_SCROLL", SDL_KMOD_SCROLL },
378 {
"KMOD_CTRL", SDL_KMOD_CTRL }, {
"KMOD_SHIFT", SDL_KMOD_SHIFT },
379 {
"KMOD_ALT", SDL_KMOD_ALT }, {
"KMOD_GUI", SDL_KMOD_GUI }
381 uint32_t mod = SDL_KMOD_NONE;
382 for (
const auto& val : SdlPref::instance()->get_array(
"SDL_KeyModMask", {
"KMOD_RSHIFT" }))
384 auto it = mapping.find(val);
385 if (it != mapping.end())
393 static const char* sdl_scancode_name(Uint32 scancode)
395 for (
const auto& cur : map)
397 if (cur.sdl == scancode)
401 return "SDL_SCANCODE_UNKNOWN";
404 static Uint32 sdl_scancode_val(
const char* scancodeName)
406 for (
const auto& cur : map)
408 if (strcmp(cur.sdl_name, scancodeName) == 0)
412 return SDL_SCANCODE_UNKNOWN;
415 static const char* sdl_rdp_scancode_name(UINT32 scancode)
417 for (
const auto& cur : map)
419 if (cur.rdp == scancode)
423 return "RDP_SCANCODE_UNKNOWN";
426 static UINT32 sdl_rdp_scancode_val(
const char* scancodeName)
428 for (
const auto& cur : map)
430 if (strcmp(cur.rdp_name, scancodeName) == 0)
434 return RDP_SCANCODE_UNKNOWN;
437 static UINT32 sdl_scancode_to_rdp(Uint32 scancode)
439 UINT32 rdp = RDP_SCANCODE_UNKNOWN;
441 for (
const auto& cur : map)
443 if (cur.sdl == scancode)
450 #if defined(WITH_DEBUG_SDL_KBD_EVENTS)
451 auto code =
static_cast<SDL_Scancode
>(scancode);
452 WLog_DBG(TAG,
"got %s [%s] -> [%s]", SDL_GetScancodeName(code), sdl_scancode_name(scancode),
453 sdl_rdp_scancode_name(rdp));
458 uint32_t sdlInput::prefKeyValue(
const std::string& key, uint32_t fallback)
460 auto item = SdlPref::instance()->get_string(key);
463 auto val = sdl_scancode_val(item.c_str());
464 if (val == SDL_SCANCODE_UNKNOWN)
469 std::list<std::string> sdlInput::tokenize(
const std::string& data,
const std::string& delimiter)
473 std::list<std::string> list;
474 while ((pos = data.find(delimiter, lastpos)) != std::string::npos)
476 auto token = data.substr(lastpos, pos);
478 list.push_back(token);
480 auto token = data.substr(lastpos);
481 list.push_back(token);
485 bool sdlInput::extract(
const std::string& token, uint32_t& key, uint32_t& value)
487 return freerdp_extract_key_value(token.c_str(), &key, &value);
490 uint32_t sdlInput::remapScancode(uint32_t scancode)
492 if (!_remapInitialized.exchange(
true))
494 auto it = _remapList.find(scancode);
495 if (it != _remapList.end())
500 void sdlInput::remapInitialize()
504 auto context = _sdl->context();
505 WINPR_ASSERT(context);
506 auto KeyboardRemappingList =
508 if (!KeyboardRemappingList)
511 auto list = tokenize(KeyboardRemappingList);
512 for (
auto& token : list)
516 if (!extract(token, key, value))
518 _remapList.emplace(key, value);
522 BOOL sdlInput::keyboard_handle_event(
const SDL_KeyboardEvent* ev)
525 const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->scancode);
526 const SDL_Keymod mods = SDL_GetModState();
528 if ((mods & _hotkeyModmask) == _hotkeyModmask)
530 if (ev->type == SDL_EVENT_KEY_DOWN)
532 if (ev->scancode == _hotkeyFullscreen)
534 _sdl->update_fullscreen(!_sdl->fullscreen);
537 if (ev->scancode == _hotkeyResizable)
539 _sdl->update_resizeable(!_sdl->resizeable);
543 if (ev->scancode == _hotkeyGrab)
545 _sdl->grab_kbd_enabled = !_sdl->grab_kbd_enabled;
546 keyboard_grab(ev->windowID, _sdl->grab_kbd);
549 if (ev->scancode == _hotkeyDisconnect)
551 freerdp_abort_connect_context(_sdl->context());
554 if (ev->scancode == _hotkeyMinimize)
556 _sdl->update_minimize();
562 auto scancode = remapScancode(rdp_scancode);
563 return freerdp_input_send_keyboard_event_ex(
564 _sdl->context()->input, ev->type == SDL_EVENT_KEY_DOWN, ev->repeat, scancode);
567 BOOL sdlInput::keyboard_grab(Uint32 windowID,
bool enable)
569 auto it = _sdl->windows.find(windowID);
570 if (it == _sdl->windows.end())
572 auto status = enable && _sdl->grab_kbd_enabled;
573 _sdl->grab_kbd = status;
574 return it->second.grabKeyboard(status);
577 BOOL sdlInput::mouse_focus(Uint32 windowID)
579 if (_lastWindowID != windowID)
581 _lastWindowID = windowID;
582 auto it = _sdl->windows.find(windowID);
583 if (it == _sdl->windows.end())
591 BOOL sdlInput::mouse_grab(Uint32 windowID,
bool enable)
593 auto it = _sdl->windows.find(windowID);
594 if (it == _sdl->windows.end())
596 _sdl->grab_mouse = enable;
597 return it->second.grabMouse(enable);
601 : _sdl(sdl), _lastWindowID(UINT32_MAX), _hotkeyModmask(prefToMask())
604 _hotkeyFullscreen = prefKeyValue(
"SDL_Fullscreen", SDL_SCANCODE_RETURN);
605 _hotkeyResizable = prefKeyValue(
"SDL_Resizeable", SDL_SCANCODE_R);
606 _hotkeyGrab = prefKeyValue(
"SDL_Grab", SDL_SCANCODE_G);
607 _hotkeyDisconnect = prefKeyValue(
"SDL_Disconnect", SDL_SCANCODE_D);
608 _hotkeyMinimize = prefKeyValue(
"SDL_Minimize", SDL_SCANCODE_M);
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.