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)
 
bool allWindowsHidden () const
 
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 48 of file sdl_context.hpp.

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

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 1075 of file sdl_context.cpp.

1076{
1077 const auto flags =
1078 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1079 auto title = sdl::utils::windowTitle(context()->settings);
1080 auto w = SdlWindow::create(id, title, flags);
1081 _windows.emplace(w.id(), std::move(w));
1082 return true;
1083}

◆ allWindowsHidden()

bool SdlContext::allWindowsHidden ( ) const

Definition at line 1142 of file sdl_context.cpp.

1143{
1144 return std::all_of(_windows.begin(), _windows.end(),
1145 [](const auto& entry)
1146 {
1147 const auto flags = SDL_GetWindowFlags(entry.second.window());
1148 return (flags & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) != 0;
1149 });
1150}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1710 of file sdl_context.cpp.

1711{
1712 return _args.data();
1713}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1715 of file sdl_context.cpp.

1716{
1717 if (_args.size() <= 1)
1718 return 0;
1719 return _args.size() - 1;
1720}

◆ argumentHandler()

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

Definition at line 1722 of file sdl_context.cpp.

1723{
1724 auto sdl = static_cast<SdlContext*>(custom);
1725 if (!sdl)
1726 return -1;
1727
1728 if (arg->Name)
1729 {
1730 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1731 {
1732 if (arg->Value != nullptr)
1733 {
1734 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1735 {
1736 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1737 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1738 SDL_GetError());
1739 return -2;
1740 }
1741 }
1742 }
1743 else if (strcmp(arg->Name, sdl_connection_dialog) == 0)
1744 sdl->_connectionDialog = (arg->Value != nullptr);
1745 }
1746 return 0;
1747}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 121 of file sdl_context.cpp.

122{
123 std::unique_lock lock(_critical);
124 _windows.clear();
125 _dialog.destroy();
126 _primary.reset();
127}

◆ 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 1759 of file sdl_context.cpp.

1760{
1761 for (const auto& cur : _valid_pointers)
1762 {
1763 if (cur == ptr)
1764 return true;
1765 }
1766 return false;
1767}

◆ 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 380 of file sdl_context.cpp.

381{
382 auto settings = context()->settings;
383 const auto& title = windowTitle();
384
385 ScopeGuard guard1([&]() { _windowsCreatedEvent.set(); });
386
387 UINT32 windowCount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
388
389 /* The monitor definitions are sorted (primary first), so they need not be in the same
390 * order as the monitor IDs. Match them by display, fall back to the index. */
391 auto monitorFor = [&](UINT32 index, int64_t id)
392 {
393 for (UINT32 y = 0; y < windowCount; y++)
394 {
395 auto cur = static_cast<rdpMonitor*>(
396 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, y));
397 if (cur && (static_cast<int64_t>(cur->orig_screen) == id))
398 return cur;
399 }
400 return static_cast<rdpMonitor*>(
401 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, index));
402 };
403
404 Sint32 originX = 0;
405 Sint32 originY = 0;
406 for (UINT32 x = 0; x < windowCount; x++)
407 {
408 auto id = monitorId(x);
409 if (id < 0)
410 return false;
411
412 auto monitor = monitorFor(x, id);
413
414 originX = std::min<Sint32>(monitor->x, originX);
415 originY = std::min<Sint32>(monitor->y, originY);
416 }
417
418 for (UINT32 x = 0; x < windowCount; x++)
419 {
420 auto id = monitorId(x);
421 if (id < 0)
422 return false;
423
424 auto monitor = monitorFor(x, id);
425
426 Uint32 w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
427 Uint32 h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
428 if (!(freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) ||
429 freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)))
430 {
431 if (_windowWidth > 0)
432 w = _windowWidth;
433 else
434 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
435
436 if (_windowHeight > 0)
437 h = _windowHeight;
438 else
439 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
440 }
441
442 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
443
444 if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
445 !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
446 {
447 flags |= SDL_WINDOW_FULLSCREEN;
448 }
449
450 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
451 {
452 flags |= SDL_WINDOW_BORDERLESS;
453 }
454
455 if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
456 flags |= SDL_WINDOW_BORDERLESS;
457
458 /* RemoteApp: the desktop only shows when needed (drawToWindows). */
459 if (freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode))
460 flags |= SDL_WINDOW_HIDDEN;
461
462 auto did = WINPR_ASSERTING_INT_CAST(SDL_DisplayID, id);
463 auto window = SdlWindow::create(did, title, flags, w, h);
464
465 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
466 {
467 window.setOffsetX(originX - monitor->x);
468 window.setOffsetY(originY - monitor->y);
469 }
470
471 _windows.insert({ window.id(), std::move(window) });
472 }
473
474 return true;
475}
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 1769 of file sdl_context.cpp.

1770{
1771 return _credentialsRead;
1772}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1954 of file sdl_context.cpp.

1955{
1956 return _cursor.get();
1957}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 1095 of file sdl_context.cpp.

1096{
1097 int count = 0;
1098 auto display = SDL_GetDisplays(&count);
1099 if (!display)
1100 return false;
1101 for (int x = 0; x < count; x++)
1102 {
1103 const auto id = display[x];
1104 addOrUpdateDisplay(id);
1105 }
1106 SDL_free(display);
1107 return true;
1108}

◆ drawToWindow()

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

Definition at line 1014 of file sdl_context.cpp.

1015{
1016 if (!isConnected())
1017 return true;
1018
1019 auto gdi = context()->gdi;
1020 WINPR_ASSERT(gdi);
1021
1022 auto size = window.rect();
1023
1024 std::unique_lock lock(_critical);
1025 auto surface = _primary.get();
1026
1027 if (useLocalScale())
1028 {
1029 window.setOffsetX(0);
1030 window.setOffsetY(0);
1031 if (gdi->width < size.w)
1032 {
1033 window.setOffsetX((size.w - gdi->width) / 2);
1034 }
1035 if (gdi->height < size.h)
1036 {
1037 window.setOffsetY((size.h - gdi->height) / 2);
1038 }
1039
1040 _localScale = { static_cast<float>(size.w) / static_cast<float>(gdi->width),
1041 static_cast<float>(size.h) / static_cast<float>(gdi->height) };
1042 if (!window.drawScaledRects(surface, _localScale, rects))
1043 return false;
1044 }
1045 else
1046 {
1047 SDL_Point offset{ 0, 0 };
1048 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
1049 offset = { window.offsetX(), window.offsetY() };
1050 if (!window.drawRects(surface, offset, rects))
1051 return false;
1052 }
1053
1054 window.updateSurface();
1055 return true;
1056}

◆ drawToWindows()

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

Definition at line 1802 of file sdl_context.cpp.

1803{
1804 /* RAIL damage is per-window (_gfxDamage), not in the rects queue: repaint every tick. */
1805 if (_rail.enabled())
1806 {
1807 for (auto& window : _windows)
1808 {
1809 if ((SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN) == 0)
1810 SDL_HideWindow(window.second.window());
1811 }
1812
1813 std::unique_lock lock(_critical);
1814 _rail.paint(_primary.get(), pixelFormat(), rects);
1815 return true;
1816 }
1817
1818 /* Non-RAIL mode (e.g. Non-Monitored Desktop during UAC / Consent UI): show the desktop window.
1819 * Before the RemoteApp starts, only when the logon needs the user. */
1820 if (freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode) &&
1821 !_rail.desktopMayShow())
1822 return true;
1823 bool firstShow = false;
1824 for (auto& window : _windows)
1825 {
1826 if (SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN)
1827 {
1828 SDL_ShowWindow(window.second.window());
1829 SDL_RaiseWindow(window.second.window());
1830 firstShow = true;
1831 }
1832 }
1833
1834 if (rects.empty() && !firstShow)
1835 return true;
1836
1837 std::vector<SDL_Rect> drawRects = rects;
1838 {
1839 std::unique_lock lock(_critical);
1840 if ((drawRects.empty() || firstShow) && _primary)
1841 drawRects = { { 0, 0, _primary->w, _primary->h } };
1842 }
1843
1844 for (auto& window : _windows)
1845 {
1846 if (!drawToWindow(window.second, drawRects))
1847 return false;
1848 }
1849
1850 return true;
1851}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 1065 of file sdl_context.cpp.

1066{
1067 return _exitCode;
1068}

◆ 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 1169 of file sdl_context.cpp.

1170{
1171 return _clip;
1172}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1179 of file sdl_context.cpp.

1180{
1181 return _dialog;
1182}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 1110 of file sdl_context.cpp.

1111{
1112 return _displays.at(id);
1113}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1159 of file sdl_context.cpp.

1160{
1161 return _disp;
1162}

◆ getDisplayIds()

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

Definition at line 1115 of file sdl_context.cpp.

1116{
1117 std::vector<SDL_DisplayID> keys;
1118 keys.reserve(_displays.size());
1119 for (const auto& entry : _displays)
1120 {
1121 keys.push_back(entry.first);
1122 }
1123 return keys;
1124}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1152 of file sdl_context.cpp.

1153{
1154 if (_windows.empty())
1155 return nullptr;
1156 return &_windows.begin()->second;
1157}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1164 of file sdl_context.cpp.

1165{
1166 return _input;
1167}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )

Definition at line 1174 of file sdl_context.cpp.

1175{
1176 return _rail;
1177}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1134 of file sdl_context.cpp.

1135{
1136 auto it = _windows.find(id);
1137 if (it == _windows.end())
1138 return nullptr;
1139 return &it->second;
1140}

◆ getWindowForId() [2/2]

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

Definition at line 1126 of file sdl_context.cpp.

1127{
1128 auto it = _windows.find(id);
1129 if (it == _windows.end())
1130 return nullptr;
1131 return &it->second;
1132}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1184 of file sdl_context.cpp.

1185{
1186 return _log;
1187}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 2075 of file sdl_context.cpp.

2076{
2077 return _grabKeyboard;
2078}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 2059 of file sdl_context.cpp.

2060{
2061 return _grabMouse;
2062}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1643 of file sdl_context.cpp.

1644{
1645 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1646 {
1647 const auto& dev = ev.display;
1648 return handleEvent(dev);
1649 }
1650 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1651 {
1652 const auto& wev = ev.window;
1653 return handleEvent(wev);
1654 }
1655 switch (ev.type)
1656 {
1657 case SDL_EVENT_RENDER_TARGETS_RESET:
1658 case SDL_EVENT_RENDER_DEVICE_RESET:
1659 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1660 return redraw();
1661 default:
1662 break;
1663 }
1664
1665 if (!isConnected())
1666 return true;
1667
1668 switch (ev.type)
1669 {
1670 case SDL_EVENT_FINGER_DOWN:
1671 case SDL_EVENT_FINGER_UP:
1672 case SDL_EVENT_FINGER_MOTION:
1673 {
1674 const auto& cev = ev.tfinger;
1675 return handleEvent(cev);
1676 }
1677 case SDL_EVENT_MOUSE_MOTION:
1678
1679 {
1680 const auto& cev = ev.motion;
1681 return handleEvent(cev);
1682 }
1683 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1684 case SDL_EVENT_MOUSE_BUTTON_UP:
1685 {
1686 const auto& cev = ev.button;
1687 return handleEvent(cev);
1688 }
1689 case SDL_EVENT_MOUSE_WHEEL:
1690 {
1691 const auto& cev = ev.wheel;
1692 return handleEvent(cev);
1693 }
1694 case SDL_EVENT_CLIPBOARD_UPDATE:
1695 {
1696 const auto& cev = ev.clipboard;
1697 return getClipboardChannelContext().handleEvent(cev);
1698 }
1699 case SDL_EVENT_KEY_DOWN:
1700 case SDL_EVENT_KEY_UP:
1701 {
1702 const auto& cev = ev.key;
1703 return getInputChannelContext().handleEvent(cev);
1704 }
1705 default:
1706 return true;
1707 }
1708}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 83 of file sdl_context.cpp.

84{
85 return _cursor_visible;
86}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1922 of file sdl_context.cpp.

1923{
1924 return _connected;
1925}

◆ join()

int SdlContext::join ( )

Definition at line 109 of file sdl_context.cpp.

110{
111 /* We do not want to use freerdp_abort_connect_context here.
112 * It would change the exit code and we do not want that. */
113 HANDLE event = freerdp_abort_event(context());
114 if (!SetEvent(event))
115 return -1;
116
117 _thread.join();
118 return 0;
119}

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1749 of file sdl_context.cpp.

1750{
1751 return _critical;
1752}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 1058 of file sdl_context.cpp.

1059{
1060 for (auto& w : _windows)
1061 w.second.minimize();
1062 return true;
1063}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 2015 of file sdl_context.cpp.

2016{
2017 if (index >= _monitorIds.size())
2018 {
2019 return -1;
2020 }
2021 return _monitorIds.at(index);
2022}

◆ monitorIds()

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

Definition at line 2010 of file sdl_context.cpp.

2011{
2012 return _monitorIds;
2013}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1189 of file sdl_context.cpp.

1190{
1191 auto window = SDL_GetMouseFocus();
1192 if (!window)
1193 return true;
1194
1195 const auto id = SDL_GetWindowID(window);
1196 const auto spos = pixelToScreen(id, pos);
1197 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1198 return true;
1199}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 1070 of file sdl_context.cpp.

1071{
1072 return _sdlPixelFormat;
1073}

◆ pixelToScreen() [1/2]

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

Definition at line 1607 of file sdl_context.cpp.

1608{
1609 auto w = getWindowForId(id);
1610 if (!w)
1611 {
1612 if (_rail.enabled() && _rail.ownsWindow(id))
1613 return pos;
1614 return {};
1615 }
1616
1617 /* Ignore errors here, sometimes SDL has no renderer */
1618 auto renderer = w->renderer();
1619 if (!renderer)
1620 return pos;
1621
1622 SDL_FPoint rpos{};
1623 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1624 return {};
1625 return applyLocalScaling(rpos);
1626}

◆ pixelToScreen() [2/2]

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

Definition at line 1628 of file sdl_context.cpp.

1629{
1630 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1631 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1632 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1633 if (round)
1634 {
1635 r.w = std::ceil(r.w);
1636 r.h = std::ceil(r.h);
1637 r.x = std::floor(r.x);
1638 r.y = std::floor(r.y);
1639 }
1640 return r;
1641}

◆ pointers()

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

Definition at line 1754 of file sdl_context.cpp.

1755{
1756 return _valid_pointers;
1757}

◆ pop()

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

Definition at line 2030 of file sdl_context.cpp.

2031{
2032 std::unique_lock lock(_queue_mux);
2033 if (_queue.empty())
2034 {
2035 return {};
2036 }
2037 auto val = std::move(_queue.front());
2038 _queue.pop();
2039 return val;
2040}

◆ push()

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

Definition at line 2024 of file sdl_context.cpp.

2025{
2026 std::unique_lock lock(_queue_mux);
2027 _queue.emplace(std::move(rects));
2028}

◆ redraw()

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

Definition at line 1903 of file sdl_context.cpp.

1904{
1905 if (!_connected)
1906 return true;
1907
1908 /* RemoteApp desktop windows are placeholders, hiding one must not stop server output. */
1909 if (suppress && freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode))
1910 return true;
1911
1912 auto gdi = context()->gdi;
1913 WINPR_ASSERT(gdi);
1914 return gdi_send_suppress_output(gdi, suppress);
1915}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 1085 of file sdl_context.cpp.

1086{
1087 for (auto& w : _windows)
1088 {
1089 if (w.second.displayIndex() == id)
1090 _windows.erase(w.first);
1091 }
1092 return true;
1093}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1959 of file sdl_context.cpp.

1960{
1961 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
1962 switch (_cursorType)
1963 {
1964 case CURSOR_NULL:
1965 if (!SDL_HideCursor())
1966 {
1967 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1968 return false;
1969 }
1970
1971 setHasCursor(false);
1972 return true;
1973
1974 case CURSOR_DEFAULT:
1975 {
1976 auto def = SDL_GetDefaultCursor();
1977 if (!SDL_SetCursor(def))
1978 {
1979 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1980 static_cast<void*>(def));
1981 return false;
1982 }
1983 if (!SDL_ShowCursor())
1984 {
1985 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1986 return false;
1987 }
1988 setHasCursor(true);
1989 return true;
1990 }
1991 case CURSOR_IMAGE:
1992 setHasCursor(true);
1993 return sdl_Pointer_Set_Process(this);
1994 default:
1995 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1996 sdl::utils::toString(_cursorType).c_str());
1997 return false;
1998 }
1999}

◆ screenToPixel()

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

Definition at line 1584 of file sdl_context.cpp.

1585{
1586 auto w = getWindowForId(id);
1587 if (!w)
1588 {
1589 /* RAIL windows are server-authoritative 1:1 (no local scaling) and not in _windows. */
1590 if (_rail.enabled() && _rail.ownsWindow(id))
1591 return pos;
1592 return {};
1593 }
1594
1595 /* Ignore errors here, sometimes SDL has no renderer */
1596 auto renderer = w->renderer();
1597 if (!renderer)
1598 return pos;
1599
1600 SDL_FPoint rpos{};
1601 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1602 return {};
1603 removeLocalScaling(rpos.x, rpos.y);
1604 return rpos;
1605}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1917 of file sdl_context.cpp.

1918{
1919 _connected = val;
1920}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1774 of file sdl_context.cpp.

1775{
1776 _credentialsRead = true;
1777}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1944 of file sdl_context.cpp.

1945{
1946 std::unique_lock lock(_critical);
1947 if (!contains(cursor))
1948 return true;
1949
1950 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1951 return setCursor(CURSOR_IMAGE);
1952}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1938 of file sdl_context.cpp.

1939{
1940 _cursorType = type;
1941 return restoreCursor();
1942}

◆ setFullscreen()

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

Definition at line 2042 of file sdl_context.cpp.

2043{
2044 for (const auto& window : _windows)
2045 {
2046 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
2047 forceOriginalDisplay))
2048 return false;
2049 }
2050 _fullscreen = enter;
2051 return true;
2052}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 2085 of file sdl_context.cpp.

2086{
2087 _grabKeyboard = enter;
2088 return true;
2089}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 2069 of file sdl_context.cpp.

2070{
2071 _grabMouse = enter;
2072 return true;
2073}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 78 of file sdl_context.cpp.

79{
80 this->_cursor_visible = val;
81}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 88 of file sdl_context.cpp.

89{
90 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
91 if (!wmclass || (strlen(wmclass) == 0))
92 wmclass = SDL_CLIENT_UUID;
93
94 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
95 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
96 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
97 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
98 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
99 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
100 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
101}
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 2054 of file sdl_context.cpp.

2055{
2056 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
2057}

◆ setMonitorIds()

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

Definition at line 2001 of file sdl_context.cpp.

2002{
2003 _monitorIds.clear();
2004 for (auto id : ids)
2005 {
2006 _monitorIds.push_back(id);
2007 }
2008}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 2091 of file sdl_context.cpp.

2092{
2093 const auto settings = context()->settings;
2094 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
2095 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
2096 bool use = (dyn && enable) || smart;
2097
2098 for (const auto& window : _windows)
2099 {
2100 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
2101 return false;
2102 }
2103 _resizeable = use;
2104
2105 return true;
2106}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 129 of file sdl_context.cpp.

130{
131 std::unique_lock lock(_critical);
132 if (freerdp_shall_disconnect_context(context()))
133 {
134 if (ignoreDialogs)
135 return true;
136 if (_rdpThreadRunning)
137 return false;
138 return !getDialog().isRunning();
139 }
140 return false;
141}

◆ start()

int SdlContext::start ( )

Definition at line 103 of file sdl_context.cpp.

104{
105 _thread = std::thread(rdpThreadRun, this);
106 return 0;
107}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 2123 of file sdl_context.cpp.

2124{
2125 return setFullscreen(!fullscreen());
2126}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 2080 of file sdl_context.cpp.

2081{
2082 return setGrabKeyboard(!grabKeyboard());
2083}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 2064 of file sdl_context.cpp.

2065{
2066 return setGrabMouse(!grabMouse());
2067}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 2113 of file sdl_context.cpp.

2114{
2115 return setResizeable(!resizeable());
2116}

◆ 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 551 of file sdl_context.cpp.

552{
553 /* In fullscreen the monitor kept the size measured with the probe window at startup and was
554 * never updated, so a session the server started at another size stayed that way. Only the
555 * window knows its real size, so ask it in fullscreen as well. */
556 if (freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
557 return true;
558
559 auto& w = _windows.at(id);
560 auto m = w.monitor(true);
561 auto r = w.rect();
562 m.width = r.w;
563 m.height = r.h;
564 w.setMonitor(m);
565 return true;
566}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 524 of file sdl_context.cpp.

525{
526 std::vector<rdpMonitor> list;
527 list.reserve(_windows.size());
528 for (const auto& win : _windows)
529 list.push_back(win.second.monitor(_windows.size() == 1));
530
531#if defined(__EMSCRIPTEN__)
532 if ((list.size() == 1) && (list.at(0).width > 0) && (list.at(0).height > 0))
533 {
534 auto split = sdl_web_monitors(list.at(0));
535 if (!split.empty())
536 list = std::move(split);
537 }
538#endif
539
540 // /monitors: subset may exclude the SDL primary. The library requires
541 // the array to mark one monitor as primary, so promote the first when
542 // none of the kept windows cover the original primary.
543 if (!list.empty() &&
544 std::none_of(list.cbegin(), list.cend(), [](const rdpMonitor& m) { return m.is_primary; }))
545 list.at(0).is_primary = true;
546
547 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
548 list.size());
549}
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: