FreeRDP
Loading...
Searching...
No Matches
sdlInput Class Reference

#include <sdl_kbd.hpp>

Public Member Functions

 sdlInput (SdlContext *sdl)
 
 sdlInput (const sdlInput &other)=delete
 
 sdlInput (sdlInput &&other)=delete
 
sdlInputoperator= (const sdlInput &other)=delete
 
sdlInputoperator= (sdlInput &&other)=delete
 
BOOL keyboard_sync_state ()
 
BOOL keyboard_focus_in ()
 
BOOL keyboard_handle_event (const SDL_KeyboardEvent *ev)
 
BOOL keyboard_grab (Uint32 windowID, bool enable)
 
BOOL mouse_focus (Uint32 windowID)
 
BOOL mouse_grab (Uint32 windowID, SDL_bool enable)
 
 sdlInput (SdlContext *sdl)
 
 sdlInput (const sdlInput &other)=delete
 
 sdlInput (sdlInput &&other)=delete
 
sdlInputoperator= (const sdlInput &other)=delete
 
sdlInputoperator= (sdlInput &&other)=delete
 
BOOL keyboard_sync_state ()
 
BOOL keyboard_focus_in ()
 
BOOL keyboard_handle_event (const SDL_KeyboardEvent *ev)
 
BOOL keyboard_grab (Uint32 windowID, bool enable)
 
BOOL mouse_focus (Uint32 windowID)
 
BOOL mouse_grab (Uint32 windowID, bool enable)
 

Static Public Member Functions

static BOOL keyboard_set_indicators (rdpContext *context, UINT16 led_flags)
 
static BOOL keyboard_set_ime_status (rdpContext *context, UINT16 imeId, UINT32 imeState, UINT32 imeConvMode)
 
static uint32_t prefToMask ()
 
static uint32_t prefKeyValue (const std::string &key, uint32_t fallback=SDL_SCANCODE_UNKNOWN)
 
static BOOL keyboard_set_indicators (rdpContext *context, UINT16 led_flags)
 
static BOOL keyboard_set_ime_status (rdpContext *context, UINT16 imeId, UINT32 imeState, UINT32 imeConvMode)
 
static uint32_t prefToMask ()
 
static uint32_t prefKeyValue (const std::string &key, uint32_t fallback=SDL_SCANCODE_UNKNOWN)
 

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Client keyboard helper

Copyright 2022 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 34 of file SDL2/sdl_kbd.hpp.

Constructor & Destructor Documentation

◆ sdlInput()

sdlInput::sdlInput ( SdlContext sdl)
explicit

Definition at line 558 of file SDL2/sdl_kbd.cpp.

559 : _sdl(sdl), _lastWindowID(UINT32_MAX), _hotkeyModmask(prefToMask())
560{
561 auto list =
562 freerdp_settings_get_string(_sdl->context()->settings, FreeRDP_KeyboardRemappingList);
563 _remapTable = freerdp_keyboard_remap_string_to_list(list);
564 assert(_remapTable);
565 _hotkeyFullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN);
566 _hotkeyResizable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R);
567 _hotkeyGrab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G);
568 _hotkeyDisconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D);
569 _hotkeyMinimize = prefKeyValue("SDL_Minimize", SDL_SCANCODE_M);
570}
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.

◆ ~sdlInput()

sdlInput::~sdlInput ( )

Definition at line 572 of file SDL2/sdl_kbd.cpp.

573{
574 freerdp_keyboard_remap_free(_remapTable);
575}

Member Function Documentation

◆ keyboard_focus_in()

BOOL sdlInput::keyboard_focus_in ( )

Definition at line 323 of file SDL2/sdl_kbd.cpp.

324{
325 auto input = _sdl->context()->input;
326 WINPR_ASSERT(input);
327
328 auto syncFlags = sdl_get_kbd_flags();
329 freerdp_input_send_focus_in_event(input, WINPR_ASSERTING_INT_CAST(UINT16, syncFlags));
330
331 /* finish with a mouse pointer position like mstsc.exe if required */
332 // TODO: fullscreen/remote app
333 int x = 0;
334 int y = 0;
335 if (_sdl->fullscreen)
336 {
337 SDL_GetGlobalMouseState(&x, &y);
338 }
339 else
340 {
341 SDL_GetMouseState(&x, &y);
342 }
343 auto w = SDL_GetMouseFocus();
344 if (w)
345 {
346 auto id = SDL_GetWindowID(w);
347 sdl_scale_coordinates(_sdl, id, &x, &y, TRUE, TRUE);
348 }
349 return freerdp_client_send_button_event(_sdl->common(), FALSE, PTR_FLAGS_MOVE, x, y);
350}

◆ keyboard_grab()

BOOL sdlInput::keyboard_grab ( Uint32  windowID,
bool  enable 
)

Definition at line 524 of file SDL2/sdl_kbd.cpp.

525{
526 auto it = _sdl->windows.find(windowID);
527 if (it == _sdl->windows.end())
528 return FALSE;
529
530 auto status = enable && _sdl->grab_kbd_enabled;
531 _sdl->grab_kbd = status;
532 return it->second.grabKeyboard(status);
533}

◆ keyboard_handle_event()

BOOL sdlInput::keyboard_handle_event ( const SDL_KeyboardEvent *  ev)

Definition at line 480 of file SDL2/sdl_kbd.cpp.

481{
482 WINPR_ASSERT(ev);
483 const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->keysym.scancode);
484 const SDL_Keymod mods = SDL_GetModState();
485
486 if ((mods & _hotkeyModmask) == _hotkeyModmask)
487 {
488 if (ev->type == SDL_KEYDOWN)
489 {
490 if (ev->keysym.scancode == _hotkeyFullscreen)
491 {
492 _sdl->update_fullscreen(!_sdl->fullscreen);
493 return TRUE;
494 }
495 if (ev->keysym.scancode == _hotkeyResizable)
496 {
497 _sdl->update_resizeable(!_sdl->resizeable);
498 return TRUE;
499 }
500
501 if (ev->keysym.scancode == _hotkeyGrab)
502 {
503 keyboard_grab(ev->windowID, !_sdl->grab_kbd);
504 return TRUE;
505 }
506 if (ev->keysym.scancode == _hotkeyDisconnect)
507 {
508 freerdp_abort_connect_context(_sdl->context());
509 return TRUE;
510 }
511 if (ev->keysym.scancode == _hotkeyMinimize)
512 {
513 _sdl->update_minimize();
514 return TRUE;
515 }
516 }
517 }
518
519 auto scancode = freerdp_keyboard_remap_key(_remapTable, rdp_scancode);
520 return freerdp_input_send_keyboard_event_ex(_sdl->context()->input, ev->type == SDL_KEYDOWN,
521 ev->repeat, scancode);
522}

◆ keyboard_set_ime_status()

BOOL sdlInput::keyboard_set_ime_status ( rdpContext *  context,
UINT16  imeId,
UINT32  imeState,
UINT32  imeConvMode 
)
static

Definition at line 376 of file SDL2/sdl_kbd.cpp.

378{
379 if (!context)
380 return FALSE;
381
382 WLog_WARN(TAG,
383 "KeyboardSetImeStatus(unitId=%04" PRIx16 ", imeState=%08" PRIx32
384 ", imeConvMode=%08" PRIx32 ") ignored",
385 imeId, imeState, imeConvMode);
386 return TRUE;
387}

◆ keyboard_set_indicators()

BOOL sdlInput::keyboard_set_indicators ( rdpContext *  context,
UINT16  led_flags 
)
static

Definition at line 353 of file SDL2/sdl_kbd.cpp.

354{
355 WINPR_UNUSED(context);
356
357 int state = KMOD_NONE;
358
359 if ((led_flags & KBD_SYNC_NUM_LOCK) != 0)
360 state |= KMOD_NUM;
361 if ((led_flags & KBD_SYNC_CAPS_LOCK) != 0)
362 state |= KMOD_CAPS;
363#if SDL_VERSION_ATLEAST(2, 0, 18)
364 if ((led_flags & KBD_SYNC_SCROLL_LOCK) != 0)
365 state |= KMOD_SCROLL;
366#endif
367
368 // TODO: KBD_SYNC_KANA_LOCK
369
370 SDL_SetModState(static_cast<SDL_Keymod>(state));
371
372 return TRUE;
373}

◆ keyboard_sync_state()

BOOL sdlInput::keyboard_sync_state ( )

Definition at line 317 of file SDL2/sdl_kbd.cpp.

318{
319 const auto syncFlags = sdl_get_kbd_flags();
320 return freerdp_input_send_synchronize_event(_sdl->context()->input, syncFlags);
321}

◆ mouse_focus()

BOOL sdlInput::mouse_focus ( Uint32  windowID)

Definition at line 535 of file SDL2/sdl_kbd.cpp.

536{
537 if (_lastWindowID != windowID)
538 {
539 _lastWindowID = windowID;
540 auto it = _sdl->windows.find(windowID);
541 if (it == _sdl->windows.end())
542 return FALSE;
543
544 it->second.raise();
545 }
546 return TRUE;
547}

◆ mouse_grab() [1/2]

BOOL sdlInput::mouse_grab ( Uint32  windowID,
bool  enable 
)

Definition at line 617 of file SDL3/sdl_kbd.cpp.

618{
619 auto it = _sdl->windows.find(windowID);
620 if (it == _sdl->windows.end())
621 return FALSE;
622 _sdl->grab_mouse = enable;
623 return it->second.grabMouse(enable);
624}

◆ mouse_grab() [2/2]

BOOL sdlInput::mouse_grab ( Uint32  windowID,
SDL_bool  enable 
)

Definition at line 549 of file SDL2/sdl_kbd.cpp.

550{
551 auto it = _sdl->windows.find(windowID);
552 if (it == _sdl->windows.end())
553 return FALSE;
554 _sdl->grab_mouse = enable;
555 return it->second.grabMouse(enable);
556}

◆ prefKeyValue()

uint32_t sdlInput::prefKeyValue ( const std::string &  key,
uint32_t  fallback = SDL_SCANCODE_UNKNOWN 
)
static

Definition at line 448 of file SDL2/sdl_kbd.cpp.

449{
450 auto item = SdlPref::instance()->get_string(key);
451 if (item.empty())
452 return fallback;
453 auto val = sdl_scancode_val(item.c_str());
454 if (val == SDL_SCANCODE_UNKNOWN)
455 return fallback;
456 return val;
457}

◆ prefToMask()

uint32_t sdlInput::prefToMask ( )
static

Definition at line 389 of file SDL2/sdl_kbd.cpp.

390{
391 const std::map<std::string, uint32_t> mapping = {
392 { "KMOD_LSHIFT", KMOD_LSHIFT }, { "KMOD_RSHIFT", KMOD_RSHIFT },
393 { "KMOD_LCTRL", KMOD_LCTRL }, { "KMOD_RCTRL", KMOD_RCTRL },
394 { "KMOD_LALT", KMOD_LALT }, { "KMOD_RALT", KMOD_RALT },
395 { "KMOD_LGUI", KMOD_LGUI }, { "KMOD_RGUI", KMOD_RGUI },
396 { "KMOD_NUM", KMOD_NUM }, { "KMOD_CAPS", KMOD_CAPS },
397 { "KMOD_MODE", KMOD_MODE },
398#if SDL_VERSION_ATLEAST(2, 0, 18)
399 { "KMOD_SCROLL", KMOD_SCROLL },
400#endif
401 { "KMOD_CTRL", KMOD_CTRL }, { "KMOD_SHIFT", KMOD_SHIFT },
402 { "KMOD_ALT", KMOD_ALT }, { "KMOD_GUI", KMOD_GUI }
403 };
404 uint32_t mod = KMOD_NONE;
405 for (const auto& val : SdlPref::instance()->get_array("SDL_KeyModMask", { "KMOD_RSHIFT" }))
406 {
407 auto it = mapping.find(val);
408 if (it != mapping.end())
409 {
410 mod |= it->second;
411 }
412 }
413 return mod;
414}

The documentation for this class was generated from the following files: