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

#include <sdl_context.hpp>

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
 
SdlContext & operator= (const SdlContext &other)=delete
 
SdlContext & operator= (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
 
SdlContext & operator= (const SdlContext &other)=delete
 
SdlContext & operator= (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 SdlWindow * getWindowForId (SDL_WindowID id) const
 
SdlWindow * getWindowForId (SDL_WindowID id)
 
SdlWindow * getFirstWindow ()
 
bool addDisplayWindow (SDL_DisplayID id)
 
bool removeDisplayWindow (SDL_DisplayID id)
 
bool detectDisplays ()
 
rdpMonitor getDisplay (SDL_DisplayID id) const
 
std::vector< SDL_DisplayID > getDisplayIds () const
 
sdlDispContext & getDisplayChannelContext ()
 
sdlInput & getInputChannelContext ()
 
sdlClip & getClipboardChannelContext ()
 
SdlRail & getRailChannelContext ()
 
SdlConnectionDialogWrapper & getDialog ()
 
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_A * args ()
 
size_t argsCount () const
 
CriticalSection & lock ()
 
std::vector< rdpPointer * > & pointers ()
 
bool contains (const rdpPointer *ptr) const
 
bool credentialsRead () const
 
void setCredentialsRead ()
 

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, SdlWindow > windows
 
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< SDLConnectionDialog > connection_dialog
 
std::atomic< bool > rdp_thread_running
 

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Client

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 48 of file SDL2/sdl_freerdp.hpp.

Member Enumeration Documentation

◆ CursorType

enum SdlContext::CursorType

Definition at line 47 of file sdl_context.hpp.

48 {
49 CURSOR_NULL,
50 CURSOR_DEFAULT,
51 CURSOR_IMAGE
52 };

Constructor & Destructor Documentation

◆ SdlContext()

SdlContext::SdlContext ( rdpContext *  context)
explicit

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

1769 : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1770 primary(nullptr, SDL_FreeSurface), primary_format(nullptr, SDL_FreeFormat),
1771 rdp_thread_running(false)
1772{
1773 WINPR_ASSERT(context);
1774 grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
1775}
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 969 of file sdl_context.cpp.

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

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1554 of file sdl_context.cpp.

1555{
1556 return _args.data();
1557}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1559 of file sdl_context.cpp.

1560{
1561 if (_args.size() <= 1)
1562 return 0;
1563 return _args.size() - 1;
1564}

◆ argumentHandler()

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

Definition at line 1566 of file sdl_context.cpp.

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

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 114 of file sdl_context.cpp.

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

◆ common()

rdpClientContext * SdlContext::common ( ) const

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

1783{
1784 return reinterpret_cast<rdpClientContext*>(_context);
1785}

◆ contains()

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

Definition at line 1601 of file sdl_context.cpp.

1602{
1603 for (const auto& cur : _valid_pointers)
1604 {
1605 if (cur == ptr)
1606 return true;
1607 }
1608 return false;
1609}

◆ context()

rdpContext * SdlContext::context ( ) const

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

1778{
1779 return _context;
1780}

◆ createWindows()

bool SdlContext::createWindows ( )

Definition at line 360 of file sdl_context.cpp.

361{
362 auto settings = context()->settings;
363 const auto& title = windowTitle();
364
365 ScopeGuard guard1([&]() { _windowsCreatedEvent.set(); });
366
367 UINT32 windowCount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
368
369 Sint32 originX = 0;
370 Sint32 originY = 0;
371 for (UINT32 x = 0; x < windowCount; x++)
372 {
373 auto id = monitorId(x);
374 if (id < 0)
375 return false;
376
377 auto monitor = static_cast<rdpMonitor*>(
378 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
379
380 originX = std::min<Sint32>(monitor->x, originX);
381 originY = std::min<Sint32>(monitor->y, originY);
382 }
383
384 for (UINT32 x = 0; x < windowCount; x++)
385 {
386 auto id = monitorId(x);
387 if (id < 0)
388 return false;
389
390 auto monitor = static_cast<rdpMonitor*>(
391 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
392
393 Uint32 w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
394 Uint32 h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
395 if (!(freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) ||
396 freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)))
397 {
398 if (_windowWidth > 0)
399 w = _windowWidth;
400 else
401 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
402
403 if (_windowHeight > 0)
404 h = _windowHeight;
405 else
406 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
407 }
408
409 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
410
411 if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
412 !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
413 {
414 flags |= SDL_WINDOW_FULLSCREEN;
415 }
416
417 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
418 {
419 flags |= SDL_WINDOW_BORDERLESS;
420 }
421
422 if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
423 flags |= SDL_WINDOW_BORDERLESS;
424
425 auto did = WINPR_ASSERTING_INT_CAST(SDL_DisplayID, id);
426 auto window = SdlWindow::create(did, title, flags, w, h);
427
428 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
429 {
430 window.setOffsetX(originX - monitor->x);
431 window.setOffsetY(originY - monitor->y);
432 }
433
434 _windows.insert({ window.id(), std::move(window) });
435 }
436
437 return true;
438}
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 1611 of file sdl_context.cpp.

1612{
1613 return _credentialsRead;
1614}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1793 of file sdl_context.cpp.

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

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 989 of file sdl_context.cpp.

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

◆ drawToWindow()

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

Definition at line 908 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1644 of file sdl_context.cpp.

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

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 959 of file sdl_context.cpp.

960{
961 return _exitCode;
962}

◆ getAadAuthHelper()

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

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

1788{
1789 return _aadAuthHelper;
1790}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1053 of file sdl_context.cpp.

1054{
1055 return _clip;
1056}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1063 of file sdl_context.cpp.

1064{
1065 return _dialog;
1066}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 1004 of file sdl_context.cpp.

1005{
1006 return _displays.at(id);
1007}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1043 of file sdl_context.cpp.

1044{
1045 return _disp;
1046}

◆ getDisplayIds()

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

Definition at line 1009 of file sdl_context.cpp.

1010{
1011 std::vector<SDL_DisplayID> keys;
1012 keys.reserve(_displays.size());
1013 for (const auto& entry : _displays)
1014 {
1015 keys.push_back(entry.first);
1016 }
1017 return keys;
1018}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1036 of file sdl_context.cpp.

1037{
1038 if (_windows.empty())
1039 return nullptr;
1040 return &_windows.begin()->second;
1041}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1048 of file sdl_context.cpp.

1049{
1050 return _input;
1051}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )

Definition at line 1058 of file sdl_context.cpp.

1059{
1060 return _rail;
1061}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1028 of file sdl_context.cpp.

1029{
1030 auto it = _windows.find(id);
1031 if (it == _windows.end())
1032 return nullptr;
1033 return &it->second;
1034}

◆ getWindowForId() [2/2]

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

Definition at line 1020 of file sdl_context.cpp.

1021{
1022 auto it = _windows.find(id);
1023 if (it == _windows.end())
1024 return nullptr;
1025 return &it->second;
1026}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1068 of file sdl_context.cpp.

1069{
1070 return _log;
1071}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1914 of file sdl_context.cpp.

1915{
1916 return _grabKeyboard;
1917}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1898 of file sdl_context.cpp.

1899{
1900 return _grabMouse;
1901}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1487 of file sdl_context.cpp.

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

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 76 of file sdl_context.cpp.

77{
78 return _cursor_visible;
79}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1761 of file sdl_context.cpp.

1762{
1763 return _connected;
1764}

◆ join()

int SdlContext::join ( )

Definition at line 102 of file sdl_context.cpp.

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

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1591 of file sdl_context.cpp.

1592{
1593 return _critical;
1594}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 952 of file sdl_context.cpp.

953{
954 for (auto& w : _windows)
955 w.second.minimize();
956 return true;
957}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1854 of file sdl_context.cpp.

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

◆ monitorIds()

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

Definition at line 1849 of file sdl_context.cpp.

1850{
1851 return _monitorIds;
1852}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1073 of file sdl_context.cpp.

1074{
1075 auto window = SDL_GetMouseFocus();
1076 if (!window)
1077 return true;
1078
1079 const auto id = SDL_GetWindowID(window);
1080 const auto spos = pixelToScreen(id, pos);
1081 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1082 return true;
1083}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 964 of file sdl_context.cpp.

965{
966 return _sdlPixelFormat;
967}

◆ pixelToScreen() [1/2]

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

Definition at line 1451 of file sdl_context.cpp.

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

◆ pixelToScreen() [2/2]

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

Definition at line 1472 of file sdl_context.cpp.

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

◆ pointers()

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

Definition at line 1596 of file sdl_context.cpp.

1597{
1598 return _valid_pointers;
1599}

◆ pop()

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

Definition at line 1869 of file sdl_context.cpp.

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

◆ push()

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

Definition at line 1863 of file sdl_context.cpp.

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

◆ redraw()

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

Definition at line 1742 of file sdl_context.cpp.

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

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 979 of file sdl_context.cpp.

980{
981 for (auto& w : _windows)
982 {
983 if (w.second.displayIndex() == id)
984 _windows.erase(w.first);
985 }
986 return true;
987}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1798 of file sdl_context.cpp.

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

◆ screenToPixel()

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

Definition at line 1428 of file sdl_context.cpp.

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

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1756 of file sdl_context.cpp.

1757{
1758 _connected = val;
1759}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1616 of file sdl_context.cpp.

1617{
1618 _credentialsRead = true;
1619}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1783 of file sdl_context.cpp.

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

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1777 of file sdl_context.cpp.

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

◆ setFullscreen()

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

Definition at line 1881 of file sdl_context.cpp.

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

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1924 of file sdl_context.cpp.

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

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1908 of file sdl_context.cpp.

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

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 71 of file sdl_context.cpp.

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

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 81 of file sdl_context.cpp.

82{
83 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
84 if (!wmclass || (strlen(wmclass) == 0))
85 wmclass = SDL_CLIENT_UUID;
86
87 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
88 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
89 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
90 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
91 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
92 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
93 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
94}
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 1893 of file sdl_context.cpp.

1894{
1895 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1896}

◆ setMonitorIds()

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

Definition at line 1840 of file sdl_context.cpp.

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

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1930 of file sdl_context.cpp.

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

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 122 of file sdl_context.cpp.

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

◆ start()

int SdlContext::start ( )

Definition at line 96 of file sdl_context.cpp.

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

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1962 of file sdl_context.cpp.

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

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1919 of file sdl_context.cpp.

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

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1903 of file sdl_context.cpp.

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

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1952 of file sdl_context.cpp.

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

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL  enter)

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

1732{
1733 std::scoped_lock lock(critical);
1734 for (const auto& window : windows)
1735 {
1736 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, &window.second, enter))
1737 return FALSE;
1738 }
1739 fullscreen = enter;
1740 return TRUE;
1741}

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

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

1744{
1745 std::scoped_lock lock(critical);
1746 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1747}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL  enable)

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

1750{
1751 std::scoped_lock lock(critical);
1752
1753 const auto settings = context()->settings;
1754 const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1755 const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1756 BOOL use = (dyn && enable) || smart;
1757
1758 for (const auto& window : windows)
1759 {
1760 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_RESIZEABLE, &window.second, use))
1761 return FALSE;
1762 }
1763 resizeable = use;
1764
1765 return TRUE;
1766}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID  id)

Definition at line 458 of file sdl_context.cpp.

459{
460 if (freerdp_settings_get_bool(_context->settings, FreeRDP_Fullscreen) ||
461 freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
462 return true;
463
464 auto& w = _windows.at(id);
465 auto m = w.monitor(true);
466 auto r = w.rect();
467 m.width = r.w;
468 m.height = r.h;
469 m.attributes.physicalWidth = static_cast<UINT32>(r.w);
470 m.attributes.physicalHeight = static_cast<UINT32>(r.h);
471 w.setMonitor(m);
472 return true;
473}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 440 of file sdl_context.cpp.

441{
442 std::vector<rdpMonitor> list;
443 list.reserve(_windows.size());
444 for (const auto& win : _windows)
445 list.push_back(win.second.monitor(_windows.size() == 1));
446
447 // /monitors: subset may exclude the SDL primary. The library requires
448 // the array to mark one monitor as primary, so promote the first when
449 // none of the kept windows cover the original primary.
450 if (!list.empty() &&
451 std::none_of(list.cbegin(), list.cend(), [](const rdpMonitor& m) { return m.is_primary; }))
452 list.at(0).is_primary = true;
453
454 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
455 list.size());
456}
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: