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
bool abortConnect () 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 toggleOverlay ()
bool showOverlay (bool on)
bool updateOverlay ()
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)
std::optional< bool > allowScreenSaver () const
bool hasCursor () const
void setMetadata ()
int start ()
int join ()
bool shallAbort (bool ignoreDialogs=false)
bool createWindows ()
void updateWindowInfo ()
void railWindowInfoChanged (uint64_t remoteId)
void flushWindowInfo ()
bool presentRenderers ()
bool hasRenderers ()
Uint64 rendererAdd (UINT64 mappingId, IWTSBitmapRendererCallback *callback)
bool rendererFrame (Uint64 id, const BYTE *data, UINT32 width, UINT32 height, LONG stride)
void rendererRemove (Uint64 id)
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
void applyMonitorScaleOverride (rdpMonitor &monitor) 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 ()
SdlWheelAxis & wheelAxis (bool horizontal)

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 52 of file sdl_context.hpp.

53 {
54 CURSOR_NULL,
55 CURSOR_DEFAULT,
56 CURSOR_IMAGE
57 };

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.

◆ ~SdlContext()

SdlContext::~SdlContext ( )
default

Definition at line 98 of file sdl_context.cpp.

99{
100 /* the channels, freed after us, may still hold the services */
101 if (_context->windowInfoService)
102 {
103 freerdp_client_window_info_service_detach(_context->windowInfoService);
104 _context->windowInfoService->Release();
105 _context->windowInfoService = nullptr;
106 }
107 if (_context->bitmapRenderService)
108 {
109 sdl_render_service_detach(_context->bitmapRenderService);
110 _context->bitmapRenderService->Release();
111 _context->bitmapRenderService = nullptr;
112 }
113 /* renderers the channels didn't remove */
114 std::scoped_lock lock(_rendererLock);
115 for (auto& kv : _renderers)
116 {
117 if (kv.second.callback)
118 kv.second.callback->Release();
119 }
120 _renderers.clear();
121}

Member Function Documentation

◆ abortConnect()

bool SdlContext::abortConnect ( ) const
nodiscard

Definition at line 2014 of file sdl_context.cpp.

2015{
2016 freerdp_set_last_error(context(), FREERDP_ERROR_CONNECT_CANCELLED);
2017 return freerdp_abort_connect_context(context());
2018}

◆ addDisplayWindow()

bool SdlContext::addDisplayWindow ( SDL_DisplayID id)
nodiscard

Definition at line 1126 of file sdl_context.cpp.

1127{
1128 const auto flags =
1129 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1130 auto title = sdl::utils::windowTitle(context()->settings);
1131 auto w = SdlWindow::create(id, title, flags);
1132 _windows.emplace(w.id(), std::move(w));
1133 return true;
1134}

◆ allowScreenSaver()

std::optional< bool > SdlContext::allowScreenSaver ( ) const
nodiscard

Definition at line 123 of file sdl_context.cpp.

124{
125 return _allowScreenSaver;
126}

◆ allWindowsHidden()

bool SdlContext::allWindowsHidden ( ) const
nodiscard

Definition at line 1203 of file sdl_context.cpp.

1204{
1205 return std::all_of(_windows.begin(), _windows.end(),
1206 [](const auto& entry)
1207 {
1208 const auto flags = SDL_GetWindowFlags(entry.second.window());
1209 return (flags & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) != 0;
1210 });
1211}

◆ applyMonitorScaleOverride()

void SdlContext::applyMonitorScaleOverride ( rdpMonitor & monitor) const

Definition at line 1824 of file sdl_context.cpp.

1825{
1826 freerdp_client_apply_monitor_scale(context()->settings, &monitor);
1827}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )
nodiscard

Definition at line 1779 of file sdl_context.cpp.

1780{
1781 return _args.data();
1782}

◆ argsCount()

size_t SdlContext::argsCount ( ) const
nodiscard

Definition at line 1784 of file sdl_context.cpp.

1785{
1786 if (_args.size() <= 1)
1787 return 0;
1788 return _args.size() - 1;
1789}

◆ argumentHandler()

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

Definition at line 1791 of file sdl_context.cpp.

1792{
1793 auto sdl = static_cast<SdlContext*>(custom);
1794 if (!sdl)
1795 return -1;
1796
1797 if (arg->Name)
1798 {
1799 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1800 {
1801 sdl->_allowScreenSaver = (arg->Value != nullptr);
1802 if (arg->Value != nullptr)
1803 {
1804 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1805 {
1806 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1807 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1808 SDL_GetError());
1809 return -2;
1810 }
1811 }
1812 }
1813 else if (strcmp(arg->Name, sdl_connection_dialog) == 0)
1814 sdl->_connectionDialog = (arg->Value != nullptr);
1815 else if (strcmp(arg->Name, sdl_info) == 0)
1816 {
1817 if (!sdl->_overlay.show(arg->Value != nullptr))
1818 return -2;
1819 }
1820 }
1821 return 0;
1822}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 171 of file sdl_context.cpp.

172{
173 std::unique_lock lock(_critical);
174 _windows.clear();
175 _dialog.destroy();
176 _primary.reset();
177}

◆ common()

rdpClientContext * SdlContext::common ( ) const
nodiscard

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
nodiscard

Definition at line 1839 of file sdl_context.cpp.

1840{
1841 for (const auto& cur : _valid_pointers)
1842 {
1843 if (cur == ptr)
1844 return true;
1845 }
1846 return false;
1847}

◆ context()

rdpContext * SdlContext::context ( ) const
nodiscard

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

1778{
1779 return _context;
1780}

◆ createWindows()

bool SdlContext::createWindows ( )
nodiscard

Definition at line 465 of file sdl_context.cpp.

466{
467 auto settings = context()->settings;
468 const auto& title = windowTitle();
469
470 ScopeGuard guard1([&]() { _windowsCreatedEvent.set(); });
471
472 UINT32 windowCount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
473
474 /* The monitor definitions are sorted (primary first), so they need not be in the same
475 * order as the monitor IDs. Match them by display, fall back to the index. */
476 auto monitorFor = [&](UINT32 index, int64_t id)
477 {
478 for (UINT32 y = 0; y < windowCount; y++)
479 {
480 auto cur = static_cast<rdpMonitor*>(
481 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, y));
482 if (cur && (static_cast<int64_t>(cur->orig_screen) == id))
483 return cur;
484 }
485 return static_cast<rdpMonitor*>(
486 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, index));
487 };
488
489 Sint32 originX = 0;
490 Sint32 originY = 0;
491 for (UINT32 x = 0; x < windowCount; x++)
492 {
493 auto id = monitorId(x);
494 if (id < 0)
495 return false;
496
497 auto monitor = monitorFor(x, id);
498
499 originX = std::min<Sint32>(monitor->x, originX);
500 originY = std::min<Sint32>(monitor->y, originY);
501 }
502
503 for (UINT32 x = 0; x < windowCount; x++)
504 {
505 auto id = monitorId(x);
506 if (id < 0)
507 return false;
508
509 auto monitor = monitorFor(x, id);
510
511 Uint32 w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
512 Uint32 h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
513 if (!(freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) ||
514 freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)))
515 {
516 if (_windowWidth > 0)
517 w = _windowWidth;
518 else
519 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
520
521 if (_windowHeight > 0)
522 h = _windowHeight;
523 else
524 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
525 }
526
527 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
528
529 if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
530 !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
531 {
532 flags |= SDL_WINDOW_FULLSCREEN;
533 }
534
535 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
536 {
537 flags |= SDL_WINDOW_BORDERLESS;
538 }
539
540 if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
541 flags |= SDL_WINDOW_BORDERLESS;
542
543 /* RemoteApp: the desktop only shows when needed (drawToWindows). */
544 if (freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode))
545 flags |= SDL_WINDOW_HIDDEN;
546
547 auto did = WINPR_ASSERTING_INT_CAST(SDL_DisplayID, id);
548 auto window = SdlWindow::create(did, title, flags, w, h);
549
550 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
551 {
552 window.setOffsetX(originX - monitor->x);
553 window.setOffsetY(originY - monitor->y);
554 }
555
556 _windows.insert({ window.id(), std::move(window) });
557 }
558
560 return true;
561}
void updateWindowInfo()
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
nodiscard

Definition at line 1849 of file sdl_context.cpp.

1850{
1851 return _credentialsRead;
1852}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const
nodiscard

Definition at line 2047 of file sdl_context.cpp.

2048{
2049 return _cursor.get();
2050}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )
nodiscard

Definition at line 1146 of file sdl_context.cpp.

1147{
1148 int count = 0;
1149 auto display = SDL_GetDisplays(&count);
1150 if (!display)
1151 {
1152 WLog_Print(getWLog(), WLOG_ERROR, "SDL_GetDisplays failed: %s", SDL_GetError());
1153 return false;
1154 }
1155 for (int x = 0; x < count; x++)
1156 {
1157 const auto id = display[x];
1158 addOrUpdateDisplay(id);
1159 }
1160 SDL_free(display);
1161
1162 /* The monitor setup needs at least one display. */
1163 if (_displays.empty())
1164 {
1165 WLog_Print(getWLog(), WLOG_ERROR, "none of the %d displays has a usable size", count);
1166 return false;
1167 }
1168 return true;
1169}

◆ drawToWindow()

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

Definition at line 1023 of file sdl_context.cpp.

1024{
1025 if (!isConnected())
1026 return true;
1027
1028 auto gdi = context()->gdi;
1029 WINPR_ASSERT(gdi);
1030
1031 auto size = window.rect();
1032
1033 std::unique_lock lock(_critical);
1034 auto surface = _primary.get();
1035
1036 if (useLocalScale())
1037 {
1038 window.setOffsetX(0);
1039 window.setOffsetY(0);
1040 if (gdi->width < size.w)
1041 {
1042 window.setOffsetX((size.w - gdi->width) / 2);
1043 }
1044 if (gdi->height < size.h)
1045 {
1046 window.setOffsetY((size.h - gdi->height) / 2);
1047 }
1048
1049 _localScale = { static_cast<float>(size.w) / static_cast<float>(gdi->width),
1050 static_cast<float>(size.h) / static_cast<float>(gdi->height) };
1051 if (!window.drawScaledRects(surface, _localScale, rects))
1052 return false;
1053 }
1054 else
1055 {
1056 SDL_Point offset{ 0, 0 };
1057 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
1058 offset = { window.offsetX(), window.offsetY() };
1059 if (!window.drawRects(surface, offset, rects))
1060 return false;
1061 }
1062
1063 window.updateSurface((&window == overlayWindow()) ? &_overlay : nullptr);
1064 return true;
1065}

◆ drawToWindows()

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

Definition at line 1887 of file sdl_context.cpp.

1888{
1889 /* RAIL damage is per-window (_gfxDamage), not in the rects queue: repaint every tick. */
1890 if (_rail.enabled())
1891 {
1892 for (auto& window : _windows)
1893 {
1894 if ((SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN) == 0)
1895 SDL_HideWindow(window.second.window());
1896 }
1897
1898 std::unique_lock lock(_critical);
1899 _rail.paint(_primary.get(), pixelFormat(), rects);
1900 return true;
1901 }
1902
1903 /* Non-RAIL mode (e.g. Non-Monitored Desktop during UAC / Consent UI): show the desktop window.
1904 * Before the RemoteApp starts, only when the logon needs the user. */
1905 if (freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode) &&
1906 !_rail.desktopMayShow())
1907 return true;
1908 bool firstShow = false;
1909 for (auto& window : _windows)
1910 {
1911 if (SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN)
1912 {
1913 SDL_ShowWindow(window.second.window());
1914 SDL_RaiseWindow(window.second.window());
1915 firstShow = true;
1916 }
1917 }
1918
1919 if (rects.empty() && !firstShow)
1920 return true;
1921
1922 std::vector<SDL_Rect> drawRects = rects;
1923 {
1924 std::unique_lock lock(_critical);
1925 if ((drawRects.empty() || firstShow) && _primary)
1926 drawRects = { { 0, 0, _primary->w, _primary->h } };
1927 }
1928
1929 for (auto& window : _windows)
1930 {
1931 if (!drawToWindow(window.second, drawRects))
1932 return false;
1933 }
1934
1935 return true;
1936}

◆ exitCode()

int SdlContext::exitCode ( ) const
nodiscard

Definition at line 1116 of file sdl_context.cpp.

1117{
1118 return _exitCode;
1119}

◆ flushWindowInfo()

void SdlContext::flushWindowInfo ( )

main thread: refreshes the RemoteApp windows' info railWindowInfoChanged() queued

Definition at line 2300 of file sdl_context.cpp.

2301{
2302 std::set<uint64_t> pending;
2303 {
2304 std::scoped_lock lock(_windowInfoLock);
2305 pending.swap(_railWindowInfoPending);
2306 }
2307
2308 for (const auto id : pending)
2309 {
2310 WTS_WINDOW_INFO info{};
2311 SDL_Window* window = nullptr;
2312 /* RemoteApp windows are drawn 1:1: the same remote and view size, scale left at 0 */
2313 if (_rail.windowGeometry(id, window, info.viewWidth, info.viewHeight))
2314 {
2315 info.hwnd = native_window(window);
2316 info.remoteWidth = info.viewWidth;
2317 info.remoteHeight = info.viewHeight;
2318 }
2319 {
2320 std::scoped_lock lock(_windowInfoLock);
2321 if (info.viewWidth > 0)
2322 _railWindowInfo[id] = info;
2323 else
2324 _railWindowInfo.erase(id);
2325 }
2326 if (info.viewWidth > 0)
2327 freerdp_client_window_info_service_changed(_context->windowInfoService, id);
2328 }
2329}

◆ getAadAuthHelper()

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

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

1788{
1789 return _aadAuthHelper;
1790}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )
nodiscard

Definition at line 1230 of file sdl_context.cpp.

1231{
1232 return _clip;
1233}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )
nodiscard

Definition at line 1240 of file sdl_context.cpp.

1241{
1242 return _dialog;
1243}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID id) const
nodiscard

Definition at line 1171 of file sdl_context.cpp.

1172{
1173 return _displays.at(id);
1174}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )
nodiscard

Definition at line 1220 of file sdl_context.cpp.

1221{
1222 return _disp;
1223}

◆ getDisplayIds()

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

Definition at line 1176 of file sdl_context.cpp.

1177{
1178 std::vector<SDL_DisplayID> keys;
1179 keys.reserve(_displays.size());
1180 for (const auto& entry : _displays)
1181 {
1182 keys.push_back(entry.first);
1183 }
1184 return keys;
1185}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )
nodiscard

Definition at line 1213 of file sdl_context.cpp.

1214{
1215 if (_windows.empty())
1216 return nullptr;
1217 return &_windows.begin()->second;
1218}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )
nodiscard

Definition at line 1225 of file sdl_context.cpp.

1226{
1227 return _input;
1228}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )
nodiscard

Definition at line 1235 of file sdl_context.cpp.

1236{
1237 return _rail;
1238}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID id)
nodiscard

Definition at line 1195 of file sdl_context.cpp.

1196{
1197 auto it = _windows.find(id);
1198 if (it == _windows.end())
1199 return nullptr;
1200 return &it->second;
1201}

◆ getWindowForId() [2/2]

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

Definition at line 1187 of file sdl_context.cpp.

1188{
1189 auto it = _windows.find(id);
1190 if (it == _windows.end())
1191 return nullptr;
1192 return &it->second;
1193}

◆ getWLog()

wLog * SdlContext::getWLog ( )
nodiscard

Definition at line 1245 of file sdl_context.cpp.

1246{
1247 return _log;
1248}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const
nodiscard

Definition at line 2172 of file sdl_context.cpp.

2173{
2174 return _grabKeyboard;
2175}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const
nodiscard

Definition at line 2156 of file sdl_context.cpp.

2157{
2158 return _grabMouse;
2159}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event & ev)
nodiscard

Definition at line 1712 of file sdl_context.cpp.

1713{
1714 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1715 {
1716 const auto& dev = ev.display;
1717 return handleEvent(dev);
1718 }
1719 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1720 {
1721 const auto& wev = ev.window;
1722 return handleEvent(wev);
1723 }
1724 switch (ev.type)
1725 {
1726 case SDL_EVENT_RENDER_TARGETS_RESET:
1727 case SDL_EVENT_RENDER_DEVICE_RESET:
1728 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1729 return redraw();
1730 default:
1731 break;
1732 }
1733
1734 if (!isConnected())
1735 return true;
1736
1737 switch (ev.type)
1738 {
1739 case SDL_EVENT_FINGER_DOWN:
1740 case SDL_EVENT_FINGER_UP:
1741 case SDL_EVENT_FINGER_MOTION:
1742 {
1743 const auto& cev = ev.tfinger;
1744 return handleEvent(cev);
1745 }
1746 case SDL_EVENT_MOUSE_MOTION:
1747
1748 {
1749 const auto& cev = ev.motion;
1750 return handleEvent(cev);
1751 }
1752 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1753 case SDL_EVENT_MOUSE_BUTTON_UP:
1754 {
1755 const auto& cev = ev.button;
1756 return handleEvent(cev);
1757 }
1758 case SDL_EVENT_MOUSE_WHEEL:
1759 {
1760 const auto& cev = ev.wheel;
1761 return handleEvent(cev);
1762 }
1763 case SDL_EVENT_CLIPBOARD_UPDATE:
1764 {
1765 const auto& cev = ev.clipboard;
1766 return getClipboardChannelContext().handleEvent(cev);
1767 }
1768 case SDL_EVENT_KEY_DOWN:
1769 case SDL_EVENT_KEY_UP:
1770 {
1771 const auto& cev = ev.key;
1772 return getInputChannelContext().handleEvent(cev);
1773 }
1774 default:
1775 return true;
1776 }
1777}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const
nodiscard

Definition at line 133 of file sdl_context.cpp.

134{
135 return _cursor_visible;
136}

◆ hasRenderers()

bool SdlContext::hasRenderers ( )
nodiscard

Definition at line 2433 of file sdl_context.cpp.

2434{
2435 std::scoped_lock lock(_rendererLock);
2436 return !_renderers.empty();
2437}

◆ isConnected()

bool SdlContext::isConnected ( ) const
nodiscard

Definition at line 2007 of file sdl_context.cpp.

2008{
2009 return _connected;
2010}

◆ join()

int SdlContext::join ( )
nodiscard

Definition at line 159 of file sdl_context.cpp.

160{
161 /* We do not want to use freerdp_abort_connect_context here.
162 * It would change the exit code and we do not want that. */
163 HANDLE event = freerdp_abort_event(context());
164 if (!SetEvent(event))
165 return -1;
166
167 _thread.join();
168 return 0;
169}

◆ lock()

CriticalSection & SdlContext::lock ( )
nodiscard

Definition at line 1829 of file sdl_context.cpp.

1830{
1831 return _critical;
1832}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )
nodiscard

Definition at line 1109 of file sdl_context.cpp.

1110{
1111 for (auto& w : _windows)
1112 w.second.minimize();
1113 return true;
1114}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t index) const
nodiscard

Definition at line 2112 of file sdl_context.cpp.

2113{
2114 if (index >= _monitorIds.size())
2115 {
2116 return -1;
2117 }
2118 return _monitorIds.at(index);
2119}

◆ monitorIds()

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

Definition at line 2107 of file sdl_context.cpp.

2108{
2109 return _monitorIds;
2110}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint & pos)
nodiscard

Definition at line 1250 of file sdl_context.cpp.

1251{
1252 auto window = SDL_GetMouseFocus();
1253 if (!window)
1254 return true;
1255
1256 const auto id = SDL_GetWindowID(window);
1257 const auto spos = pixelToScreen(id, pos);
1258 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1259 return true;
1260}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const
nodiscard

Definition at line 1121 of file sdl_context.cpp.

1122{
1123 return _sdlPixelFormat;
1124}

◆ pixelToScreen() [1/2]

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

Definition at line 1676 of file sdl_context.cpp.

1677{
1678 auto w = getWindowForId(id);
1679 if (!w)
1680 {
1681 if (_rail.enabled() && _rail.ownsWindow(id))
1682 return pos;
1683 return {};
1684 }
1685
1686 /* Ignore errors here, sometimes SDL has no renderer */
1687 auto renderer = w->renderer();
1688 if (!renderer)
1689 return pos;
1690
1691 SDL_FPoint rpos{};
1692 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1693 return {};
1694 return applyLocalScaling(rpos);
1695}

◆ pixelToScreen() [2/2]

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

Definition at line 1697 of file sdl_context.cpp.

1698{
1699 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1700 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1701 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1702 if (round)
1703 {
1704 r.w = std::ceil(r.w);
1705 r.h = std::ceil(r.h);
1706 r.x = std::floor(r.x);
1707 r.y = std::floor(r.y);
1708 }
1709 return r;
1710}

◆ pointers()

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

Definition at line 1834 of file sdl_context.cpp.

1835{
1836 return _valid_pointers;
1837}

◆ pop()

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

Definition at line 2127 of file sdl_context.cpp.

2128{
2129 std::unique_lock lock(_queue_mux);
2130 if (_queue.empty())
2131 {
2132 return {};
2133 }
2134 auto val = std::move(_queue.front());
2135 _queue.pop();
2136 return val;
2137}

◆ presentRenderers()

bool SdlContext::presentRenderers ( )
nodiscard

main thread: draws the mapped renderers (rdpContext::bitmapRenderService) where the Geometry Tracking channel puts them

Definition at line 2446 of file sdl_context.cpp.

2447{
2448 _renderersPending = false;
2449 if (!isConnected())
2450 return true;
2451
2452 /* OnTargetSizeChanged() calls, made once _rendererLock is released */
2453 std::vector<std::pair<IWTSBitmapRendererCallback*, WTS_RECT>> targets;
2454 {
2455 std::scoped_lock lock(_rendererLock);
2456
2457 /* a renderer is placed by its mapping's geometry (MS-RDPEGT), hidden without one */
2458 struct Placement
2459 {
2460 bool visible = false;
2461 SDL_Rect rect{};
2462 std::vector<SDL_Rect> region; /* the visible parts, empty: all of it */
2463 };
2464 std::map<Uint64, Placement> placements;
2465 rdpGdi* gdi = _context->gdi;
2466 GeometryClientContext* geometry = gdi ? gdi->geometry : nullptr;
2467 if (geometry && geometry->geometries)
2468 {
2469 HashTable_Lock(geometry->geometries);
2470 for (auto& kv : _renderers)
2471 {
2472 auto g = static_cast<const MAPPED_GEOMETRY*>(
2473 HashTable_GetItemValue(geometry->geometries, &kv.second.mappingId));
2474 if (!g)
2475 continue;
2476 Placement p;
2477 p.rect = { static_cast<int>(g->topLevelLeft + g->left),
2478 static_cast<int>(g->topLevelTop + g->top),
2479 static_cast<int>(std::max<INT64>(0, g->right - g->left)),
2480 static_cast<int>(std::max<INT64>(0, g->bottom - g->top)) };
2481 p.visible = (p.rect.w > 0) && (p.rect.h > 0);
2482 /* the region's rectangles are relative to the tracked rectangle */
2483 INT64 area = 0;
2484 for (UINT32 i = 0; g->geometry.rects && (i < g->geometry.nRectCount); i++)
2485 {
2486 const RDP_RECT& r = g->geometry.rects[i];
2487 const int left = std::max(0, static_cast<int>(r.x));
2488 const int top = std::max(0, static_cast<int>(r.y));
2489 const int right = std::min(p.rect.w, r.x + r.width);
2490 const int bottom = std::min(p.rect.h, r.y + r.height);
2491 if ((right <= left) || (bottom <= top))
2492 continue;
2493 area += static_cast<INT64>(right - left) * (bottom - top);
2494 p.region.push_back(
2495 { p.rect.x + left, p.rect.y + top, right - left, bottom - top });
2496 }
2497 if (area >= static_cast<INT64>(p.rect.w) * p.rect.h)
2498 p.region.clear();
2499 placements[kv.first] = std::move(p);
2500 }
2501 HashTable_Unlock(geometry->geometries);
2502 }
2503
2504 for (auto& kv : _renderers)
2505 {
2506 auto& r = kv.second;
2507 const auto& p = placements[kv.first];
2508 if (p.visible && r.callback && !SDL_RectsEqual(&p.rect, &r.target))
2509 {
2510 r.target = p.rect;
2511 r.callback->AddRef();
2512 targets.emplace_back(r.callback, WTS_RECT{ p.rect.x, p.rect.y, p.rect.x + p.rect.w,
2513 p.rect.y + p.rect.h });
2514 }
2515 }
2516
2517 for (auto& w : _windows)
2518 {
2519 auto& window = w.second;
2520 window.pruneVideoOverlays([this](Uint64 id) { return _renderers.count(id) != 0; });
2521 for (auto& kv : _renderers)
2522 {
2523 auto& r = kv.second;
2524 const auto& p = placements[kv.first];
2525 /* where the session is drawn in the window: as drawToWindow() does */
2526 SDL_Point offset{ 0, 0 };
2527 if (!useLocalScale() &&
2528 freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
2529 offset = { window.offsetX(), window.offsetY() };
2530 auto toWindow = [&](const SDL_Rect& rc)
2531 {
2532 if (useLocalScale())
2533 return SDL_FRect{ static_cast<float>(rc.x) * _localScale.x,
2534 static_cast<float>(rc.y) * _localScale.y,
2535 static_cast<float>(rc.w) * _localScale.x,
2536 static_cast<float>(rc.h) * _localScale.y };
2537 return SDL_FRect{ static_cast<float>(rc.x + offset.x),
2538 static_cast<float>(rc.y + offset.y), static_cast<float>(rc.w),
2539 static_cast<float>(rc.h) };
2540 };
2541 const SDL_FRect dst = toWindow(p.rect);
2542 std::vector<SDL_FRect> clip;
2543 clip.reserve(p.region.size());
2544 for (const auto& rc : p.region)
2545 clip.push_back(toWindow(rc));
2546 const bool visible = p.visible && !r.pixels.empty();
2547 if (!window.setVideoOverlay(kv.first, r.dirty ? r.pixels.data() : nullptr, r.pitch,
2548 r.width, r.height, dst, clip, visible))
2549 continue;
2550 }
2551 window.updateSurface();
2552 }
2553 for (auto& kv : _renderers)
2554 kv.second.dirty = false;
2555 }
2556
2557 for (auto& t : targets)
2558 {
2559 std::ignore = t.first->OnTargetSizeChanged(t.second);
2560 t.first->Release();
2561 }
2562 return true;
2563}

References freerdp_settings_get_bool().

Here is the call graph for this function:

◆ push()

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

Definition at line 2121 of file sdl_context.cpp.

2122{
2123 std::unique_lock lock(_queue_mux);
2124 _queue.emplace(std::move(rects));
2125}

◆ railWindowInfoChanged()

void SdlContext::railWindowInfoChanged ( uint64_t remoteId)

any thread: a RemoteApp window (remoteId) was created, moved, resized or deleted; its window info is refreshed on the main thread (flushWindowInfo)

Definition at line 2288 of file sdl_context.cpp.

2289{
2290 bool first = false;
2291 {
2292 std::scoped_lock lock(_windowInfoLock);
2293 first = _railWindowInfoPending.empty();
2294 _railWindowInfoPending.insert(remoteId);
2295 }
2296 if (first)
2297 std::ignore = sdl_push_user_event(SDL_EVENT_USER_WINDOW_INFO);
2298}

◆ redraw()

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

Definition at line 1988 of file sdl_context.cpp.

1989{
1990 if (!_connected)
1991 return true;
1992
1993 /* RemoteApp desktop windows are placeholders, hiding one must not stop server output. */
1994 if (suppress && freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode))
1995 return true;
1996
1997 auto gdi = context()->gdi;
1998 WINPR_ASSERT(gdi);
1999 return gdi_send_suppress_output(gdi, suppress);
2000}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID id)
nodiscard

Definition at line 1136 of file sdl_context.cpp.

1137{
1138 for (auto& w : _windows)
1139 {
1140 if (w.second.displayIndex() == id)
1141 _windows.erase(w.first);
1142 }
1143 return true;
1144}

◆ rendererAdd()

Uint64 SdlContext::rendererAdd ( UINT64 mappingId,
IWTSBitmapRendererCallback * callback )
nodiscard

Definition at line 2363 of file sdl_context.cpp.

2364{
2365 std::scoped_lock lock(_rendererLock);
2366 const auto id = _nextRenderer++;
2367 auto& r = _renderers[id];
2368 r.mappingId = mappingId;
2369 r.callback = callback;
2370 if (callback)
2371 callback->AddRef();
2372 return id;
2373}

◆ rendererFrame()

bool SdlContext::rendererFrame ( Uint64 id,
const BYTE * data,
UINT32 width,
UINT32 height,
LONG stride )
nodiscard

Definition at line 2375 of file sdl_context.cpp.

2377{
2378 if (stride <= 0)
2379 return false;
2380
2381 {
2382 std::scoped_lock lock(_rendererLock);
2383 auto it = _renderers.find(id);
2384 if (it == _renderers.end())
2385 return false;
2386 auto& r = it->second;
2387 /* Render's buffer is the caller's for the call only */
2388 const size_t row = static_cast<size_t>(width) * 4;
2389 r.pixels.resize(row * height);
2390 for (UINT32 y = 0; y < height; y++)
2391 {
2392 const auto offset = row * y;
2393 const auto end = offset + row;
2394 const auto dataoffset = 1ull * y * static_cast<size_t>(stride);
2395
2396 try
2397 {
2398 auto& ptr = r.pixels.at(offset);
2399 std::ignore = r.pixels.at(end);
2400 memcpy(&ptr, &data[dataoffset], row);
2401 }
2402 catch (std::out_of_range& ex)
2403 {
2404 SDL_Log("failed to render: %s", ex.what());
2405 return false;
2406 }
2407 }
2408 r.pitch = static_cast<int>(row);
2409 r.width = static_cast<int>(width);
2410 r.height = static_cast<int>(height);
2411 r.dirty = true;
2412 }
2413 renderersChanged();
2414 return true;
2415}

◆ rendererRemove()

void SdlContext::rendererRemove ( Uint64 id)

Definition at line 2417 of file sdl_context.cpp.

2418{
2419 IWTSBitmapRendererCallback* callback = nullptr;
2420 {
2421 std::scoped_lock lock(_rendererLock);
2422 auto it = _renderers.find(id);
2423 if (it == _renderers.end())
2424 return;
2425 callback = it->second.callback;
2426 _renderers.erase(it);
2427 }
2428 if (callback)
2429 callback->Release();
2430 renderersChanged();
2431}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )
nodiscard

Definition at line 2052 of file sdl_context.cpp.

2053{
2054 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
2055 switch (_cursorType)
2056 {
2057 case CURSOR_NULL:
2058 if (!SDL_HideCursor())
2059 {
2060 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
2061 return false;
2062 }
2063
2064 setHasCursor(false);
2065 return true;
2066
2067 case CURSOR_DEFAULT:
2068 {
2069 auto def = SDL_GetDefaultCursor();
2070 if (!SDL_SetCursor(def))
2071 {
2072 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
2073 static_cast<void*>(def));
2074 return false;
2075 }
2076 if (!SDL_ShowCursor())
2077 {
2078 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
2079 return false;
2080 }
2081 setHasCursor(true);
2082 return true;
2083 }
2084 case CURSOR_IMAGE:
2085 setHasCursor(true);
2086 return sdl_Pointer_Set_Process(this);
2087 default:
2088 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
2089 sdl::utils::toString(_cursorType).c_str());
2090 return false;
2091 }
2092}

◆ screenToPixel()

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

Definition at line 1653 of file sdl_context.cpp.

1654{
1655 auto w = getWindowForId(id);
1656 if (!w)
1657 {
1658 /* RAIL windows are server-authoritative 1:1 (no local scaling) and not in _windows. */
1659 if (_rail.enabled() && _rail.ownsWindow(id))
1660 return pos;
1661 return {};
1662 }
1663
1664 /* Ignore errors here, sometimes SDL has no renderer */
1665 auto renderer = w->renderer();
1666 if (!renderer)
1667 return pos;
1668
1669 SDL_FPoint rpos{};
1670 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1671 return {};
1672 removeLocalScaling(rpos.x, rpos.y);
1673 return rpos;
1674}

◆ setConnected()

void SdlContext::setConnected ( bool val)

Definition at line 2002 of file sdl_context.cpp.

2003{
2004 _connected = val;
2005}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1854 of file sdl_context.cpp.

1855{
1856 _credentialsRead = true;
1857}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer * cursor)
nodiscard

Definition at line 2037 of file sdl_context.cpp.

2038{
2039 std::unique_lock lock(_critical);
2040 if (!contains(cursor))
2041 return true;
2042
2043 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
2044 return setCursor(CURSOR_IMAGE);
2045}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType type)
nodiscard

Definition at line 2031 of file sdl_context.cpp.

2032{
2033 _cursorType = type;
2034 return restoreCursor();
2035}

◆ setFullscreen()

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

Definition at line 2139 of file sdl_context.cpp.

2140{
2141 for (const auto& window : _windows)
2142 {
2143 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
2144 forceOriginalDisplay))
2145 return false;
2146 }
2147 _fullscreen = enter;
2148 return true;
2149}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool enter)
nodiscard

Definition at line 2182 of file sdl_context.cpp.

2183{
2184 _grabKeyboard = enter;
2185 return true;
2186}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool enter)
nodiscard

Definition at line 2166 of file sdl_context.cpp.

2167{
2168 _grabMouse = enter;
2169 return true;
2170}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool val)

Definition at line 128 of file sdl_context.cpp.

129{
130 this->_cursor_visible = val;
131}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 138 of file sdl_context.cpp.

139{
140 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
141 if (!wmclass || (strlen(wmclass) == 0))
142 wmclass = SDL_CLIENT_UUID;
143
144 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
145 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
146 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
147 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
148 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
149 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
150 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
151}
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 ( )
nodiscard

Definition at line 2151 of file sdl_context.cpp.

2152{
2153 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
2154}

◆ setMonitorIds()

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

Definition at line 2094 of file sdl_context.cpp.

2095{
2096 _monitorIds.clear();
2097 for (auto id : ids)
2098 {
2099 _monitorIds.push_back(id);
2100 }
2101 /* Only the selected displays are sent, so only they need to fit together. This runs during
2102 * connect, outside the thread that owns the windows; they are not touched here and are
2103 * created from the updated displays. */
2104 updateDisplayOffsets();
2105}

◆ setResizeable()

bool SdlContext::setResizeable ( bool enable)
nodiscard

Definition at line 2188 of file sdl_context.cpp.

2189{
2190 const auto settings = context()->settings;
2191 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
2192 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
2193 bool use = (dyn && enable) || smart;
2194
2195 for (const auto& window : _windows)
2196 {
2197 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
2198 return false;
2199 }
2200 _resizeable = use;
2201
2202 return true;
2203}

◆ shallAbort()

bool SdlContext::shallAbort ( bool ignoreDialogs = false)
nodiscard

Definition at line 179 of file sdl_context.cpp.

180{
181 std::unique_lock lock(_critical);
182 if (freerdp_shall_disconnect_context(context()))
183 {
184 if (ignoreDialogs)
185 return true;
186 if (_rdpThreadRunning)
187 return false;
188 return !getDialog().isRunning();
189 }
190 return false;
191}

◆ showOverlay()

bool SdlContext::showOverlay ( bool on)
nodiscard

Definition at line 1080 of file sdl_context.cpp.

1081{
1082 if (!_overlay.show(on))
1083 return false;
1084 if (on || !isConnected())
1085 return true;
1086
1087 /* hidden: present the picture once without it */
1088 auto window = overlayWindow();
1089 if (window)
1090 window->updateSurface();
1091 return true;
1092}

◆ start()

int SdlContext::start ( )
nodiscard

Definition at line 153 of file sdl_context.cpp.

154{
155 _thread = std::thread(rdpThreadRun, this);
156 return 0;
157}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )
nodiscard

Definition at line 2220 of file sdl_context.cpp.

2221{
2222 return setFullscreen(!fullscreen());
2223}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )
nodiscard

Definition at line 2177 of file sdl_context.cpp.

2178{
2179 return setGrabKeyboard(!grabKeyboard());
2180}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )
nodiscard

Definition at line 2161 of file sdl_context.cpp.

2162{
2163 return setGrabMouse(!grabMouse());
2164}

◆ toggleOverlay()

bool SdlContext::toggleOverlay ( )
nodiscard

The stats and info overlay, SDL's thread

Definition at line 1075 of file sdl_context.cpp.

1076{
1077 return showOverlay(!_overlay.visible());
1078}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )
nodiscard

Definition at line 2210 of file sdl_context.cpp.

2211{
2212 return setResizeable(!resizeable());
2213}

◆ 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}

◆ updateOverlay()

bool SdlContext::updateOverlay ( )
nodiscard

Definition at line 1094 of file sdl_context.cpp.

1095{
1096 auto window = overlayWindow();
1097 if (!window || !isConnected())
1098 return true;
1099
1100 int w = 0;
1101 int h = 0;
1102 if (!SDL_GetWindowSizeInPixels(window->window(), &w, &h))
1103 return true;
1104 if (_overlay.update(w, h, window->rendererName()))
1105 window->updateSurface(&_overlay);
1106 return true;
1107}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID id)
nodiscard

Definition at line 645 of file sdl_context.cpp.

646{
647 /* In fullscreen the monitor kept the size measured with the probe window at startup and was
648 * never updated, so a session the server started at another size stayed that way. Only the
649 * window knows its real size, so ask it in fullscreen as well. */
650 if (freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
651 return true;
652
653 auto& w = _windows.at(id);
654 auto m = w.monitor(true);
655 applyMonitorScaleOverride(m);
656 auto r = w.rect();
657 m.width = r.w;
658 m.height = r.h;
659 /* The window may be on another display than the one it was created on. */
660 m.attributes.desktopScaleFactor = static_cast<UINT32>(std::roundf(w.scale() * 100.0f));
661 w.setMonitor(m);
662 return true;
663}

◆ updateWindowInfo()

void SdlContext::updateWindowInfo ( )

main thread: recomputes what rdpContext::windowInfoService tells about the session window after it was created, resized or rescaled, and tells the subscriber

Definition at line 2251 of file sdl_context.cpp.

2252{
2253 WTS_WINDOW_INFO info{};
2254 auto window = getFirstWindow();
2255 if (window && window->window())
2256 {
2257 auto settings = _context->settings;
2258 info.hwnd = native_window(window->window());
2259 info.remoteWidth =
2260 static_cast<INT32>(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
2261 info.remoteHeight =
2262 static_cast<INT32>(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
2263 int w = 0;
2264 int h = 0;
2265 if (SDL_GetWindowSizeInPixels(window->window(), &w, &h))
2266 {
2267 info.viewWidth = w;
2268 info.viewHeight = h;
2269 }
2270 /* session pixels to native pixels */
2271 const float density = SDL_GetWindowPixelDensity(window->window());
2272 const auto p0 = pixelToScreen(window->id(), SDL_FPoint{ 0, 0 });
2273 const auto p1 = pixelToScreen(window->id(), SDL_FPoint{ 1000, 1000 });
2274 const float scale = (p1.x - p0.x) * density / 1000.0f;
2275 info.scale = (scale > 0.0f) ? scale : 1.0f;
2276 }
2277
2278 {
2279 std::scoped_lock lock(_windowInfoLock);
2280 if (window_info_equal(info, _desktopWindowInfo))
2281 return;
2282 _desktopWindowInfo = info;
2283 }
2284 if (!_rail.enabled())
2285 freerdp_client_window_info_service_changed(_context->windowInfoService, 0);
2286}

References freerdp_settings_get_uint32().

Here is the call graph for this function:

◆ updateWindowList()

bool SdlContext::updateWindowList ( )
nodiscard

Definition at line 610 of file sdl_context.cpp.

611{
612 /* The windows only know their own size: keep the layout from connect. */
613 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
614 return true;
615
616 std::vector<rdpMonitor> list;
617 list.reserve(_windows.size());
618 for (const auto& win : _windows)
619 {
620 auto monitor = win.second.monitor(_windows.size() == 1);
621 applyMonitorScaleOverride(monitor);
622 list.push_back(monitor);
623 }
624
625#if defined(__EMSCRIPTEN__)
626 if ((list.size() == 1) && (list.at(0).width > 0) && (list.at(0).height > 0))
627 {
628 auto split = sdl_web_monitors(list.at(0));
629 if (!split.empty())
630 list = std::move(split);
631 }
632#endif
633
634 // /monitors: subset may exclude the SDL primary. The library requires
635 // the array to mark one monitor as primary, so promote the first when
636 // none of the kept windows cover the original primary.
637 if (!list.empty() &&
638 std::none_of(list.cbegin(), list.cend(), [](const rdpMonitor& m) { return m.is_primary; }))
639 list.at(0).is_primary = true;
640
641 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
642 list.size());
643}
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:

◆ wheelAxis()

SdlWheelAxis & SdlContext::wheelAxis ( bool horizontal)
nodiscard

Definition at line 1859 of file sdl_context.cpp.

1860{
1861 return horizontal ? _wheelX : _wheelY;
1862}

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: