FreeRDP
Loading...
Searching...
No Matches
SdlContext Class Reference
Collaboration diagram for SdlContext:

Public Types

enum  CursorType { CURSOR_NULL , CURSOR_DEFAULT , CURSOR_IMAGE }
 

Public Member Functions

 SdlContext (rdpContext *context)
 
 SdlContext (const SdlContext &other)=delete
 
 SdlContext (SdlContext &&other)=delete
 
SdlContextoperator= (const SdlContext &other)=delete
 
SdlContextoperator= (SdlContext &&other)=delete
 
BOOL update_resizeable (BOOL enable)
 
BOOL update_fullscreen (BOOL enter)
 
BOOL update_minimize ()
 
rdpContext * context () const
 
rdpClientContext * common () const
 
std::shared_ptr< SdlAadAuthHelper > & getAadAuthHelper ()
 
 SdlContext (rdpContext *context)
 
 SdlContext (const SdlContext &other)=delete
 
 SdlContext (SdlContext &&other)=delete
 
SdlContextoperator= (const SdlContext &other)=delete
 
SdlContextoperator= (SdlContext &&other)=delete
 
bool redraw (bool suppress=false) const
 
void setConnected (bool val)
 
bool isConnected () const
 
void cleanup ()
 
bool resizeable () const
 
bool toggleResizeable ()
 
bool setResizeable (bool enable)
 
bool fullscreen () const
 
bool toggleFullscreen ()
 
bool setFullscreen (bool enter, bool forceOriginalDisplay=false)
 
bool setMinimized ()
 
bool grabMouse () const
 
bool toggleGrabMouse ()
 
bool setGrabMouse (bool enter)
 
bool grabKeyboard () const
 
bool toggleGrabKeyboard ()
 
bool setGrabKeyboard (bool enter)
 
rdpContext * context () const
 
rdpClientContext * common () const
 
bool setCursor (CursorType type)
 
bool setCursor (const rdpPointer *cursor)
 
rdpPointer * cursor () const
 
bool restoreCursor ()
 
void setMonitorIds (const std::vector< SDL_DisplayID > &ids)
 
const std::vector< SDL_DisplayID > & monitorIds () const
 
int64_t monitorId (uint32_t index) const
 
void push (std::vector< SDL_Rect > &&rects)
 
std::vector< SDL_Rect > pop ()
 
void setHasCursor (bool val)
 
bool hasCursor () const
 
void setMetadata ()
 
int start ()
 
int join ()
 
bool shallAbort (bool ignoreDialogs=false)
 
bool createWindows ()
 
bool updateWindowList ()
 
bool updateWindow (SDL_WindowID id)
 
bool drawToWindows (const std::vector< SDL_Rect > &rects={})
 
bool drawToWindow (SdlWindow &window, const std::vector< SDL_Rect > &rects={})
 
bool minimizeAllWindows ()
 
int exitCode () const
 
SDL_PixelFormat pixelFormat () const
 
const SdlWindowgetWindowForId (SDL_WindowID id) const
 
SdlWindowgetWindowForId (SDL_WindowID id)
 
SdlWindowgetFirstWindow ()
 
bool addDisplayWindow (SDL_DisplayID id)
 
bool removeDisplayWindow (SDL_DisplayID id)
 
bool detectDisplays ()
 
rdpMonitor getDisplay (SDL_DisplayID id) const
 
std::vector< SDL_DisplayID > getDisplayIds () const
 
sdlDispContextgetDisplayChannelContext ()
 
sdlInputgetInputChannelContext ()
 
sdlClipgetClipboardChannelContext ()
 
SdlRailgetRailChannelContext ()
 
SdlConnectionDialogWrappergetDialog ()
 
wLog * getWLog ()
 
bool moveMouseTo (const SDL_FPoint &pos)
 
SDL_FPoint screenToPixel (SDL_WindowID id, const SDL_FPoint &pos)
 
SDL_FPoint pixelToScreen (SDL_WindowID id, const SDL_FPoint &pos)
 
SDL_FRect pixelToScreen (SDL_WindowID id, const SDL_FRect &pos, bool round=false)
 
bool handleEvent (const SDL_Event &ev)
 
COMMAND_LINE_ARGUMENT_Aargs ()
 
size_t argsCount () const
 
CriticalSectionlock ()
 
std::vector< rdpPointer * > & pointers ()
 
bool contains (const rdpPointer *ptr) const
 
bool credentialsRead () const
 
void setCredentialsRead ()
 
std::shared_ptr< SdlAadAuthHelper > & getAadAuthHelper ()
 

Static Public Member Functions

static int argumentHandler (const COMMAND_LINE_ARGUMENT_A *arg, void *custom)
 

Data Fields

wLog * log
 
bool fullscreen = false
 
bool resizeable = false
 
bool grab_mouse = false
 
bool grab_kbd = false
 
bool grab_kbd_enabled = true
 
std::map< Uint32, SdlWindowwindows
 
CriticalSection critical
 
std::thread thread
 
WinPREvent initialize
 
WinPREvent initialized
 
WinPREvent update_complete
 
WinPREvent windows_created
 
int exit_code = -1
 
sdlDispContext disp
 
sdlInput input
 
SDLSurfacePtr primary
 
SDLPixelFormatPtr primary_format
 
Uint32 sdl_pixel_format = 0
 
std::unique_ptr< SDLConnectionDialogconnection_dialog
 
std::atomic< bool > rdp_thread_running
 

Detailed Description

Definition at line 48 of file SDL2/sdl_freerdp.hpp.

Member Enumeration Documentation

◆ CursorType

enum SdlContext::CursorType

Definition at line 49 of file sdl_context.hpp.

50 {
51 CURSOR_NULL,
52 CURSOR_DEFAULT,
53 CURSOR_IMAGE
54 };

Constructor & Destructor Documentation

◆ SdlContext()

SdlContext::SdlContext ( rdpContext *  context)
explicit

Definition at line 1790 of file SDL2/sdl_freerdp.cpp.

1791 : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1792 primary(nullptr, SDL_FreeSurface), primary_format(nullptr, SDL_FreeFormat),
1793 rdp_thread_running(false)
1794{
1795 WINPR_ASSERT(context);
1796 grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
1797}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.

Member Function Documentation

◆ addDisplayWindow()

bool SdlContext::addDisplayWindow ( SDL_DisplayID  id)

Definition at line 965 of file sdl_context.cpp.

966{
967 const auto flags =
968 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
969 auto title = sdl::utils::windowTitle(context()->settings);
970 auto w = SdlWindow::create(id, title, flags);
971 _windows.emplace(w.id(), std::move(w));
972 return true;
973}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1550 of file sdl_context.cpp.

1551{
1552 return _args.data();
1553}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1555 of file sdl_context.cpp.

1556{
1557 if (_args.size() <= 1)
1558 return 0;
1559 return _args.size() - 1;
1560}

◆ argumentHandler()

int SdlContext::argumentHandler ( const COMMAND_LINE_ARGUMENT_A arg,
void *  custom 
)
static

Definition at line 1562 of file sdl_context.cpp.

1563{
1564 auto sdl = static_cast<SdlContext*>(custom);
1565 if (!sdl)
1566 return -1;
1567
1568 if (arg->Name)
1569 {
1570 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1571 {
1572 if (arg->Value != nullptr)
1573 {
1574 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1575 {
1576 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1577 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1578 SDL_GetError());
1579 return -2;
1580 }
1581 }
1582 }
1583 }
1584 return 0;
1585}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 115 of file sdl_context.cpp.

116{
117 std::unique_lock lock(_critical);
118 _windows.clear();
119 _dialog.destroy();
120 _primary.reset();
121}

◆ common()

rdpClientContext * SdlContext::common ( ) const

Definition at line 1804 of file SDL2/sdl_freerdp.cpp.

1805{
1806 return reinterpret_cast<rdpClientContext*>(_context);
1807}

◆ contains()

bool SdlContext::contains ( const rdpPointer *  ptr) const

Definition at line 1597 of file sdl_context.cpp.

1598{
1599 for (const auto& cur : _valid_pointers)
1600 {
1601 if (cur == ptr)
1602 return true;
1603 }
1604 return false;
1605}

◆ context()

rdpContext * SdlContext::context ( ) const

Definition at line 1799 of file SDL2/sdl_freerdp.cpp.

1800{
1801 return _context;
1802}

◆ createWindows()

bool SdlContext::createWindows ( )

Definition at line 381 of file sdl_context.cpp.

382{
383 auto settings = context()->settings;
384 const auto& title = windowTitle();
385
386 ScopeGuard guard1([&]() { _windowsCreatedEvent.set(); });
387
388 UINT32 windowCount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
389
390 Sint32 originX = 0;
391 Sint32 originY = 0;
392 for (UINT32 x = 0; x < windowCount; x++)
393 {
394 auto id = monitorId(x);
395 if (id < 0)
396 return false;
397
398 auto monitor = static_cast<rdpMonitor*>(
399 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
400
401 originX = std::min<Sint32>(monitor->x, originX);
402 originY = std::min<Sint32>(monitor->y, originY);
403 }
404
405 for (UINT32 x = 0; x < windowCount; x++)
406 {
407 auto id = monitorId(x);
408 if (id < 0)
409 return false;
410
411 auto monitor = static_cast<rdpMonitor*>(
412 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
413
414 Uint32 w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
415 Uint32 h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
416 if (!(freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) ||
417 freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)))
418 {
419 if (_windowWidth > 0)
420 w = _windowWidth;
421 else
422 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
423
424 if (_windowHeight > 0)
425 h = _windowHeight;
426 else
427 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
428 }
429
430 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
431
432 if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
433 !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
434 {
435 flags |= SDL_WINDOW_FULLSCREEN;
436 }
437
438 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
439 {
440 flags |= SDL_WINDOW_BORDERLESS;
441 }
442
443 if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
444 flags |= SDL_WINDOW_BORDERLESS;
445
446 auto did = WINPR_ASSERTING_INT_CAST(SDL_DisplayID, id);
447 auto window = SdlWindow::create(did, title, flags, w, h);
448
449 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
450 {
451 window.setOffsetX(originX - monitor->x);
452 window.setOffsetY(originY - monitor->y);
453 }
454
455 _windows.insert({ window.id(), std::move(window) });
456 }
457
458 return true;
459}
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.

◆ credentialsRead()

bool SdlContext::credentialsRead ( ) const

Definition at line 1607 of file sdl_context.cpp.

1608{
1609 return _credentialsRead;
1610}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1794 of file sdl_context.cpp.

1795{
1796 return _cursor.get();
1797}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 985 of file sdl_context.cpp.

986{
987 int count = 0;
988 auto display = SDL_GetDisplays(&count);
989 if (!display)
990 return false;
991 for (int x = 0; x < count; x++)
992 {
993 const auto id = display[x];
994 addOrUpdateDisplay(id);
995 }
996 SDL_free(display);
997 return true;
998}

◆ drawToWindow()

bool SdlContext::drawToWindow ( SdlWindow window,
const std::vector< SDL_Rect > &  rects = {} 
)

Definition at line 904 of file sdl_context.cpp.

905{
906 if (!isConnected())
907 return true;
908
909 auto gdi = context()->gdi;
910 WINPR_ASSERT(gdi);
911
912 auto size = window.rect();
913
914 std::unique_lock lock(_critical);
915 auto surface = _primary.get();
916
917 if (useLocalScale())
918 {
919 window.setOffsetX(0);
920 window.setOffsetY(0);
921 if (gdi->width < size.w)
922 {
923 window.setOffsetX((size.w - gdi->width) / 2);
924 }
925 if (gdi->height < size.h)
926 {
927 window.setOffsetY((size.h - gdi->height) / 2);
928 }
929
930 _localScale = { static_cast<float>(size.w) / static_cast<float>(gdi->width),
931 static_cast<float>(size.h) / static_cast<float>(gdi->height) };
932 if (!window.drawScaledRects(surface, _localScale, rects))
933 return false;
934 }
935 else
936 {
937 SDL_Point offset{ 0, 0 };
938 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
939 offset = { window.offsetX(), window.offsetY() };
940 if (!window.drawRects(surface, offset, rects))
941 return false;
942 }
943
944 window.updateSurface();
945 return true;
946}

◆ drawToWindows()

bool SdlContext::drawToWindows ( const std::vector< SDL_Rect > &  rects = {})

Definition at line 1645 of file sdl_context.cpp.

1646{
1647 /* RAIL damage is per-window (_gfxDamage), not in the rects queue: repaint every tick. */
1648 if (_rail.enabled())
1649 {
1650 for (auto& window : _windows)
1651 {
1652 if ((SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN) == 0)
1653 SDL_HideWindow(window.second.window());
1654 }
1655
1656 std::unique_lock lock(_critical);
1657 _rail.paint(_primary.get(), pixelFormat(), rects);
1658 return true;
1659 }
1660
1661 /* Non-RAIL mode (e.g. Non-Monitored Desktop during UAC / Consent UI): show the desktop window.
1662 */
1663 bool firstShow = false;
1664 for (auto& window : _windows)
1665 {
1666 if (SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN)
1667 {
1668 SDL_ShowWindow(window.second.window());
1669 SDL_RaiseWindow(window.second.window());
1670 firstShow = true;
1671 }
1672 }
1673
1674 if (rects.empty() && !firstShow)
1675 return true;
1676
1677 std::vector<SDL_Rect> drawRects = rects;
1678 {
1679 std::unique_lock lock(_critical);
1680 if ((drawRects.empty() || firstShow) && _primary)
1681 drawRects = { { 0, 0, _primary->w, _primary->h } };
1682 }
1683
1684 for (auto& window : _windows)
1685 {
1686 if (!drawToWindow(window.second, drawRects))
1687 return false;
1688 }
1689
1690 return true;
1691}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 955 of file sdl_context.cpp.

956{
957 return _exitCode;
958}

◆ getAadAuthHelper()

std::shared_ptr< SdlAadAuthHelper > & SdlContext::getAadAuthHelper ( )

Definition at line 1809 of file SDL2/sdl_freerdp.cpp.

1810{
1811 return _aadAuthHelper;
1812}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1049 of file sdl_context.cpp.

1050{
1051 return _clip;
1052}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1059 of file sdl_context.cpp.

1060{
1061 return _dialog;
1062}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 1000 of file sdl_context.cpp.

1001{
1002 return _displays.at(id);
1003}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1039 of file sdl_context.cpp.

1040{
1041 return _disp;
1042}

◆ getDisplayIds()

std::vector< SDL_DisplayID > SdlContext::getDisplayIds ( ) const

Definition at line 1005 of file sdl_context.cpp.

1006{
1007 std::vector<SDL_DisplayID> keys;
1008 keys.reserve(_displays.size());
1009 for (const auto& entry : _displays)
1010 {
1011 keys.push_back(entry.first);
1012 }
1013 return keys;
1014}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1032 of file sdl_context.cpp.

1033{
1034 if (_windows.empty())
1035 return nullptr;
1036 return &_windows.begin()->second;
1037}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1044 of file sdl_context.cpp.

1045{
1046 return _input;
1047}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )

Definition at line 1054 of file sdl_context.cpp.

1055{
1056 return _rail;
1057}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1024 of file sdl_context.cpp.

1025{
1026 auto it = _windows.find(id);
1027 if (it == _windows.end())
1028 return nullptr;
1029 return &it->second;
1030}

◆ getWindowForId() [2/2]

const SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id) const

Definition at line 1016 of file sdl_context.cpp.

1017{
1018 auto it = _windows.find(id);
1019 if (it == _windows.end())
1020 return nullptr;
1021 return &it->second;
1022}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1064 of file sdl_context.cpp.

1065{
1066 return _log;
1067}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1915 of file sdl_context.cpp.

1916{
1917 return _grabKeyboard;
1918}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1899 of file sdl_context.cpp.

1900{
1901 return _grabMouse;
1902}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1483 of file sdl_context.cpp.

1484{
1485 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1486 {
1487 const auto& dev = ev.display;
1488 return handleEvent(dev);
1489 }
1490 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1491 {
1492 const auto& wev = ev.window;
1493 return handleEvent(wev);
1494 }
1495 switch (ev.type)
1496 {
1497 case SDL_EVENT_RENDER_TARGETS_RESET:
1498 case SDL_EVENT_RENDER_DEVICE_RESET:
1499 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1500 return redraw();
1501 default:
1502 break;
1503 }
1504
1505 if (!isConnected())
1506 return true;
1507
1508 switch (ev.type)
1509 {
1510 case SDL_EVENT_FINGER_DOWN:
1511 case SDL_EVENT_FINGER_UP:
1512 case SDL_EVENT_FINGER_MOTION:
1513 {
1514 const auto& cev = ev.tfinger;
1515 return handleEvent(cev);
1516 }
1517 case SDL_EVENT_MOUSE_MOTION:
1518
1519 {
1520 const auto& cev = ev.motion;
1521 return handleEvent(cev);
1522 }
1523 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1524 case SDL_EVENT_MOUSE_BUTTON_UP:
1525 {
1526 const auto& cev = ev.button;
1527 return handleEvent(cev);
1528 }
1529 case SDL_EVENT_MOUSE_WHEEL:
1530 {
1531 const auto& cev = ev.wheel;
1532 return handleEvent(cev);
1533 }
1534 case SDL_EVENT_CLIPBOARD_UPDATE:
1535 {
1536 const auto& cev = ev.clipboard;
1537 return getClipboardChannelContext().handleEvent(cev);
1538 }
1539 case SDL_EVENT_KEY_DOWN:
1540 case SDL_EVENT_KEY_UP:
1541 {
1542 const auto& cev = ev.key;
1543 return getInputChannelContext().handleEvent(cev);
1544 }
1545 default:
1546 return true;
1547 }
1548}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 77 of file sdl_context.cpp.

78{
79 return _cursor_visible;
80}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1762 of file sdl_context.cpp.

1763{
1764 return _connected;
1765}

◆ join()

int SdlContext::join ( )

Definition at line 103 of file sdl_context.cpp.

104{
105 /* We do not want to use freerdp_abort_connect_context here.
106 * It would change the exit code and we do not want that. */
107 HANDLE event = freerdp_abort_event(context());
108 if (!SetEvent(event))
109 return -1;
110
111 _thread.join();
112 return 0;
113}

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1587 of file sdl_context.cpp.

1588{
1589 return _critical;
1590}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 948 of file sdl_context.cpp.

949{
950 for (auto& w : _windows)
951 w.second.minimize();
952 return true;
953}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1855 of file sdl_context.cpp.

1856{
1857 if (index >= _monitorIds.size())
1858 {
1859 return -1;
1860 }
1861 return _monitorIds.at(index);
1862}

◆ monitorIds()

const std::vector< SDL_DisplayID > & SdlContext::monitorIds ( ) const

Definition at line 1850 of file sdl_context.cpp.

1851{
1852 return _monitorIds;
1853}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1069 of file sdl_context.cpp.

1070{
1071 auto window = SDL_GetMouseFocus();
1072 if (!window)
1073 return true;
1074
1075 const auto id = SDL_GetWindowID(window);
1076 const auto spos = pixelToScreen(id, pos);
1077 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1078 return true;
1079}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 960 of file sdl_context.cpp.

961{
962 return _sdlPixelFormat;
963}

◆ pixelToScreen() [1/2]

SDL_FPoint SdlContext::pixelToScreen ( SDL_WindowID  id,
const SDL_FPoint &  pos 
)

Definition at line 1447 of file sdl_context.cpp.

1448{
1449 auto w = getWindowForId(id);
1450 if (!w)
1451 {
1452 if (_rail.enabled() && _rail.ownsWindow(id))
1453 return pos;
1454 return {};
1455 }
1456
1457 /* Ignore errors here, sometimes SDL has no renderer */
1458 auto renderer = w->renderer();
1459 if (!renderer)
1460 return pos;
1461
1462 SDL_FPoint rpos{};
1463 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1464 return {};
1465 return applyLocalScaling(rpos);
1466}

◆ pixelToScreen() [2/2]

SDL_FRect SdlContext::pixelToScreen ( SDL_WindowID  id,
const SDL_FRect &  pos,
bool  round = false 
)

Definition at line 1468 of file sdl_context.cpp.

1469{
1470 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1471 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1472 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1473 if (round)
1474 {
1475 r.w = std::ceil(r.w);
1476 r.h = std::ceil(r.h);
1477 r.x = std::floor(r.x);
1478 r.y = std::floor(r.y);
1479 }
1480 return r;
1481}

◆ pointers()

std::vector< rdpPointer * > & SdlContext::pointers ( )

Definition at line 1592 of file sdl_context.cpp.

1593{
1594 return _valid_pointers;
1595}

◆ pop()

std::vector< SDL_Rect > SdlContext::pop ( )

Definition at line 1870 of file sdl_context.cpp.

1871{
1872 std::unique_lock lock(_queue_mux);
1873 if (_queue.empty())
1874 {
1875 return {};
1876 }
1877 auto val = std::move(_queue.front());
1878 _queue.pop();
1879 return val;
1880}

◆ push()

void SdlContext::push ( std::vector< SDL_Rect > &&  rects)

Definition at line 1864 of file sdl_context.cpp.

1865{
1866 std::unique_lock lock(_queue_mux);
1867 _queue.emplace(std::move(rects));
1868}

◆ redraw()

bool SdlContext::redraw ( bool  suppress = false) const

Definition at line 1743 of file sdl_context.cpp.

1744{
1745 if (!_connected)
1746 return true;
1747
1748 /* In RAIL mode, hiding the desktop window must not suppress server output. */
1749 if (suppress && _rail.enabled())
1750 return true;
1751
1752 auto gdi = context()->gdi;
1753 WINPR_ASSERT(gdi);
1754 return gdi_send_suppress_output(gdi, suppress);
1755}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 975 of file sdl_context.cpp.

976{
977 for (auto& w : _windows)
978 {
979 if (w.second.displayIndex() == id)
980 _windows.erase(w.first);
981 }
982 return true;
983}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1799 of file sdl_context.cpp.

1800{
1801 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
1802 switch (_cursorType)
1803 {
1804 case CURSOR_NULL:
1805 if (!SDL_HideCursor())
1806 {
1807 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1808 return false;
1809 }
1810
1811 setHasCursor(false);
1812 return true;
1813
1814 case CURSOR_DEFAULT:
1815 {
1816 auto def = SDL_GetDefaultCursor();
1817 if (!SDL_SetCursor(def))
1818 {
1819 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1820 static_cast<void*>(def));
1821 return false;
1822 }
1823 if (!SDL_ShowCursor())
1824 {
1825 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1826 return false;
1827 }
1828 setHasCursor(true);
1829 return true;
1830 }
1831 case CURSOR_IMAGE:
1832 setHasCursor(true);
1833 return sdl_Pointer_Set_Process(this);
1834 default:
1835 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1836 sdl::utils::toString(_cursorType).c_str());
1837 return false;
1838 }
1839}

◆ screenToPixel()

SDL_FPoint SdlContext::screenToPixel ( SDL_WindowID  id,
const SDL_FPoint &  pos 
)

Definition at line 1424 of file sdl_context.cpp.

1425{
1426 auto w = getWindowForId(id);
1427 if (!w)
1428 {
1429 /* RAIL windows are server-authoritative 1:1 (no local scaling) and not in _windows. */
1430 if (_rail.enabled() && _rail.ownsWindow(id))
1431 return pos;
1432 return {};
1433 }
1434
1435 /* Ignore errors here, sometimes SDL has no renderer */
1436 auto renderer = w->renderer();
1437 if (!renderer)
1438 return pos;
1439
1440 SDL_FPoint rpos{};
1441 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1442 return {};
1443 removeLocalScaling(rpos.x, rpos.y);
1444 return rpos;
1445}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1757 of file sdl_context.cpp.

1758{
1759 _connected = val;
1760}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1612 of file sdl_context.cpp.

1613{
1614 _credentialsRead = true;
1615}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1784 of file sdl_context.cpp.

1785{
1786 std::unique_lock lock(_critical);
1787 if (!contains(cursor))
1788 return true;
1789
1790 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1791 return setCursor(CURSOR_IMAGE);
1792}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1778 of file sdl_context.cpp.

1779{
1780 _cursorType = type;
1781 return restoreCursor();
1782}

◆ setFullscreen()

bool SdlContext::setFullscreen ( bool  enter,
bool  forceOriginalDisplay = false 
)

Definition at line 1882 of file sdl_context.cpp.

1883{
1884 for (const auto& window : _windows)
1885 {
1886 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1887 forceOriginalDisplay))
1888 return false;
1889 }
1890 _fullscreen = enter;
1891 return true;
1892}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1925 of file sdl_context.cpp.

1926{
1927 _grabKeyboard = enter;
1928 return true;
1929}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1909 of file sdl_context.cpp.

1910{
1911 _grabMouse = enter;
1912 return true;
1913}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 72 of file sdl_context.cpp.

73{
74 this->_cursor_visible = val;
75}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 82 of file sdl_context.cpp.

83{
84 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
85 if (!wmclass || (strlen(wmclass) == 0))
86 wmclass = SDL_CLIENT_UUID;
87
88 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
89 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
90 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
91 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
92 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
93 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
94 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
95}
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.

◆ setMinimized()

bool SdlContext::setMinimized ( )

Definition at line 1894 of file sdl_context.cpp.

1895{
1896 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1897}

◆ setMonitorIds()

void SdlContext::setMonitorIds ( const std::vector< SDL_DisplayID > &  ids)

Definition at line 1841 of file sdl_context.cpp.

1842{
1843 _monitorIds.clear();
1844 for (auto id : ids)
1845 {
1846 _monitorIds.push_back(id);
1847 }
1848}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1931 of file sdl_context.cpp.

1932{
1933 const auto settings = context()->settings;
1934 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1935 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1936 bool use = (dyn && enable) || smart;
1937
1938 for (const auto& window : _windows)
1939 {
1940 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1941 return false;
1942 }
1943 _resizeable = use;
1944
1945 return true;
1946}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 123 of file sdl_context.cpp.

124{
125 std::unique_lock lock(_critical);
126 if (freerdp_shall_disconnect_context(context()))
127 {
128 if (ignoreDialogs)
129 return true;
130 if (_rdpThreadRunning)
131 return false;
132 return !getDialog().isRunning();
133 }
134 return false;
135}

◆ start()

int SdlContext::start ( )

Definition at line 97 of file sdl_context.cpp.

98{
99 _thread = std::thread(rdpThreadRun, this);
100 return 0;
101}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1963 of file sdl_context.cpp.

1964{
1965 return setFullscreen(!fullscreen());
1966}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1920 of file sdl_context.cpp.

1921{
1922 return setGrabKeyboard(!grabKeyboard());
1923}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1904 of file sdl_context.cpp.

1905{
1906 return setGrabMouse(!grabMouse());
1907}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1953 of file sdl_context.cpp.

1954{
1955 return setResizeable(!resizeable());
1956}

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL  enter)

Definition at line 1753 of file SDL2/sdl_freerdp.cpp.

1754{
1755 std::scoped_lock lock(critical);
1756 for (const auto& window : windows)
1757 {
1758 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, &window.second, enter))
1759 return FALSE;
1760 }
1761 fullscreen = enter;
1762 return TRUE;
1763}

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

Definition at line 1765 of file SDL2/sdl_freerdp.cpp.

1766{
1767 std::scoped_lock lock(critical);
1768 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1769}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL  enable)

Definition at line 1771 of file SDL2/sdl_freerdp.cpp.

1772{
1773 std::scoped_lock lock(critical);
1774
1775 const auto settings = context()->settings;
1776 const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1777 const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1778 BOOL use = (dyn && enable) || smart;
1779
1780 for (const auto& window : windows)
1781 {
1782 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_RESIZEABLE, &window.second, use))
1783 return FALSE;
1784 }
1785 resizeable = use;
1786
1787 return TRUE;
1788}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID  id)

Definition at line 479 of file sdl_context.cpp.

480{
481 if (freerdp_settings_get_bool(_context->settings, FreeRDP_Fullscreen) ||
482 freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
483 return true;
484
485 auto& w = _windows.at(id);
486 auto m = w.monitor(true);
487 auto r = w.rect();
488 m.width = r.w;
489 m.height = r.h;
490 m.attributes.physicalWidth = static_cast<UINT32>(r.w);
491 m.attributes.physicalHeight = static_cast<UINT32>(r.h);
492 w.setMonitor(m);
493 return true;
494}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 461 of file sdl_context.cpp.

462{
463 std::vector<rdpMonitor> list;
464 list.reserve(_windows.size());
465 for (const auto& win : _windows)
466 list.push_back(win.second.monitor(_windows.size() == 1));
467
468 // /monitors: subset may exclude the SDL primary. The library requires
469 // the array to mark one monitor as primary, so promote the first when
470 // none of the kept windows cover the original primary.
471 if (!list.empty() &&
472 std::none_of(list.cbegin(), list.cend(), [](const rdpMonitor& m) { return m.is_primary; }))
473 list.at(0).is_primary = true;
474
475 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
476 list.size());
477}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_monitor_def_array_sorted(rdpSettings *settings, const rdpMonitor *monitors, size_t count)
Sort monitor array according to:

Field Documentation

◆ connection_dialog

std::unique_ptr<SDLConnectionDialog> SdlContext::connection_dialog

Definition at line 90 of file SDL2/sdl_freerdp.hpp.

◆ critical

CriticalSection SdlContext::critical

Definition at line 74 of file SDL2/sdl_freerdp.hpp.

◆ disp

sdlDispContext SdlContext::disp

Definition at line 82 of file SDL2/sdl_freerdp.hpp.

◆ exit_code

int SdlContext::exit_code = -1

Definition at line 80 of file SDL2/sdl_freerdp.hpp.

◆ fullscreen

bool SdlContext::fullscreen = false

Definition at line 66 of file SDL2/sdl_freerdp.hpp.

◆ grab_kbd

bool SdlContext::grab_kbd = false

Definition at line 69 of file SDL2/sdl_freerdp.hpp.

◆ grab_kbd_enabled

bool SdlContext::grab_kbd_enabled = true

Definition at line 70 of file SDL2/sdl_freerdp.hpp.

◆ grab_mouse

bool SdlContext::grab_mouse = false

Definition at line 68 of file SDL2/sdl_freerdp.hpp.

◆ initialize

WinPREvent SdlContext::initialize

Definition at line 76 of file SDL2/sdl_freerdp.hpp.

◆ initialized

WinPREvent SdlContext::initialized

Definition at line 77 of file SDL2/sdl_freerdp.hpp.

◆ input

sdlInput SdlContext::input

Definition at line 83 of file SDL2/sdl_freerdp.hpp.

◆ log

wLog* SdlContext::log

Definition at line 63 of file SDL2/sdl_freerdp.hpp.

◆ primary

SDLSurfacePtr SdlContext::primary

Definition at line 85 of file SDL2/sdl_freerdp.hpp.

◆ primary_format

SDLPixelFormatPtr SdlContext::primary_format

Definition at line 86 of file SDL2/sdl_freerdp.hpp.

◆ rdp_thread_running

std::atomic<bool> SdlContext::rdp_thread_running

Definition at line 92 of file SDL2/sdl_freerdp.hpp.

◆ resizeable

bool SdlContext::resizeable = false

Definition at line 67 of file SDL2/sdl_freerdp.hpp.

◆ sdl_pixel_format

Uint32 SdlContext::sdl_pixel_format = 0

Definition at line 88 of file SDL2/sdl_freerdp.hpp.

◆ thread

std::thread SdlContext::thread

Definition at line 75 of file SDL2/sdl_freerdp.hpp.

◆ update_complete

WinPREvent SdlContext::update_complete

Definition at line 78 of file SDL2/sdl_freerdp.hpp.

◆ windows

std::map<Uint32, SdlWindow> SdlContext::windows

Definition at line 72 of file SDL2/sdl_freerdp.hpp.

◆ windows_created

WinPREvent SdlContext::windows_created

Definition at line 79 of file SDL2/sdl_freerdp.hpp.


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