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

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

Member Function Documentation

◆ abortConnect()

bool SdlContext::abortConnect ( ) const
nodiscard

Definition at line 1999 of file sdl_context.cpp.

2000{
2001 freerdp_set_last_error(context(), FREERDP_ERROR_CONNECT_CANCELLED);
2002 return freerdp_abort_connect_context(context());
2003}

◆ addDisplayWindow()

bool SdlContext::addDisplayWindow ( SDL_DisplayID id)
nodiscard

Definition at line 1116 of file sdl_context.cpp.

1117{
1118 const auto flags =
1119 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1120 auto title = sdl::utils::windowTitle(context()->settings);
1121 auto w = SdlWindow::create(id, title, flags);
1122 _windows.emplace(w.id(), std::move(w));
1123 return true;
1124}

◆ allowScreenSaver()

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

Definition at line 122 of file sdl_context.cpp.

123{
124 return _allowScreenSaver;
125}

◆ allWindowsHidden()

bool SdlContext::allWindowsHidden ( ) const
nodiscard

Definition at line 1193 of file sdl_context.cpp.

1194{
1195 return std::all_of(_windows.begin(), _windows.end(),
1196 [](const auto& entry)
1197 {
1198 const auto flags = SDL_GetWindowFlags(entry.second.window());
1199 return (flags & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) != 0;
1200 });
1201}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )
nodiscard

Definition at line 1769 of file sdl_context.cpp.

1770{
1771 return _args.data();
1772}

◆ argsCount()

size_t SdlContext::argsCount ( ) const
nodiscard

Definition at line 1774 of file sdl_context.cpp.

1775{
1776 if (_args.size() <= 1)
1777 return 0;
1778 return _args.size() - 1;
1779}

◆ argumentHandler()

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

Definition at line 1781 of file sdl_context.cpp.

1782{
1783 auto sdl = static_cast<SdlContext*>(custom);
1784 if (!sdl)
1785 return -1;
1786
1787 if (arg->Name)
1788 {
1789 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1790 {
1791 sdl->_allowScreenSaver = (arg->Value != nullptr);
1792 if (arg->Value != nullptr)
1793 {
1794 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1795 {
1796 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1797 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1798 SDL_GetError());
1799 return -2;
1800 }
1801 }
1802 }
1803 else if (strcmp(arg->Name, sdl_connection_dialog) == 0)
1804 sdl->_connectionDialog = (arg->Value != nullptr);
1805 else if (strcmp(arg->Name, sdl_info) == 0)
1806 {
1807 if (!sdl->_overlay.show(arg->Value != nullptr))
1808 return -2;
1809 }
1810 }
1811 return 0;
1812}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 170 of file sdl_context.cpp.

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

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

1825{
1826 for (const auto& cur : _valid_pointers)
1827 {
1828 if (cur == ptr)
1829 return true;
1830 }
1831 return false;
1832}

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

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

1835{
1836 return _credentialsRead;
1837}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const
nodiscard

Definition at line 2032 of file sdl_context.cpp.

2033{
2034 return _cursor.get();
2035}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )
nodiscard

Definition at line 1136 of file sdl_context.cpp.

1137{
1138 int count = 0;
1139 auto display = SDL_GetDisplays(&count);
1140 if (!display)
1141 {
1142 WLog_Print(getWLog(), WLOG_ERROR, "SDL_GetDisplays failed: %s", SDL_GetError());
1143 return false;
1144 }
1145 for (int x = 0; x < count; x++)
1146 {
1147 const auto id = display[x];
1148 addOrUpdateDisplay(id);
1149 }
1150 SDL_free(display);
1151
1152 /* The monitor setup needs at least one display. */
1153 if (_displays.empty())
1154 {
1155 WLog_Print(getWLog(), WLOG_ERROR, "none of the %d displays has a usable size", count);
1156 return false;
1157 }
1158 return true;
1159}

◆ drawToWindow()

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

Definition at line 1013 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1872 of file sdl_context.cpp.

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

◆ exitCode()

int SdlContext::exitCode ( ) const
nodiscard

Definition at line 1106 of file sdl_context.cpp.

1107{
1108 return _exitCode;
1109}

◆ flushWindowInfo()

void SdlContext::flushWindowInfo ( )

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

Definition at line 2285 of file sdl_context.cpp.

2286{
2287 std::set<uint64_t> pending;
2288 {
2289 std::scoped_lock lock(_windowInfoLock);
2290 pending.swap(_railWindowInfoPending);
2291 }
2292
2293 for (const auto id : pending)
2294 {
2295 WTS_WINDOW_INFO info{};
2296 SDL_Window* window = nullptr;
2297 /* RemoteApp windows are drawn 1:1: the same remote and view size, scale left at 0 */
2298 if (_rail.windowGeometry(id, window, info.viewWidth, info.viewHeight))
2299 {
2300 info.hwnd = native_window(window);
2301 info.remoteWidth = info.viewWidth;
2302 info.remoteHeight = info.viewHeight;
2303 }
2304 {
2305 std::scoped_lock lock(_windowInfoLock);
2306 if (info.viewWidth > 0)
2307 _railWindowInfo[id] = info;
2308 else
2309 _railWindowInfo.erase(id);
2310 }
2311 if (info.viewWidth > 0)
2312 freerdp_client_window_info_service_changed(_context->windowInfoService, id);
2313 }
2314}

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

1221{
1222 return _clip;
1223}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )
nodiscard

Definition at line 1230 of file sdl_context.cpp.

1231{
1232 return _dialog;
1233}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID id) const
nodiscard

Definition at line 1161 of file sdl_context.cpp.

1162{
1163 return _displays.at(id);
1164}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )
nodiscard

Definition at line 1210 of file sdl_context.cpp.

1211{
1212 return _disp;
1213}

◆ getDisplayIds()

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

Definition at line 1166 of file sdl_context.cpp.

1167{
1168 std::vector<SDL_DisplayID> keys;
1169 keys.reserve(_displays.size());
1170 for (const auto& entry : _displays)
1171 {
1172 keys.push_back(entry.first);
1173 }
1174 return keys;
1175}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )
nodiscard

Definition at line 1203 of file sdl_context.cpp.

1204{
1205 if (_windows.empty())
1206 return nullptr;
1207 return &_windows.begin()->second;
1208}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )
nodiscard

Definition at line 1215 of file sdl_context.cpp.

1216{
1217 return _input;
1218}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )
nodiscard

Definition at line 1225 of file sdl_context.cpp.

1226{
1227 return _rail;
1228}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID id)
nodiscard

Definition at line 1185 of file sdl_context.cpp.

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

◆ getWindowForId() [2/2]

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

Definition at line 1177 of file sdl_context.cpp.

1178{
1179 auto it = _windows.find(id);
1180 if (it == _windows.end())
1181 return nullptr;
1182 return &it->second;
1183}

◆ getWLog()

wLog * SdlContext::getWLog ( )
nodiscard

Definition at line 1235 of file sdl_context.cpp.

1236{
1237 return _log;
1238}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const
nodiscard

Definition at line 2157 of file sdl_context.cpp.

2158{
2159 return _grabKeyboard;
2160}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const
nodiscard

Definition at line 2141 of file sdl_context.cpp.

2142{
2143 return _grabMouse;
2144}

◆ handleEvent()

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

Definition at line 1702 of file sdl_context.cpp.

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

◆ hasCursor()

bool SdlContext::hasCursor ( ) const
nodiscard

Definition at line 132 of file sdl_context.cpp.

133{
134 return _cursor_visible;
135}

◆ hasRenderers()

bool SdlContext::hasRenderers ( )
nodiscard

Definition at line 2418 of file sdl_context.cpp.

2419{
2420 std::scoped_lock lock(_rendererLock);
2421 return !_renderers.empty();
2422}

◆ isConnected()

bool SdlContext::isConnected ( ) const
nodiscard

Definition at line 1992 of file sdl_context.cpp.

1993{
1994 return _connected;
1995}

◆ join()

int SdlContext::join ( )
nodiscard

Definition at line 158 of file sdl_context.cpp.

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

◆ lock()

CriticalSection & SdlContext::lock ( )
nodiscard

Definition at line 1814 of file sdl_context.cpp.

1815{
1816 return _critical;
1817}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )
nodiscard

Definition at line 1099 of file sdl_context.cpp.

1100{
1101 for (auto& w : _windows)
1102 w.second.minimize();
1103 return true;
1104}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t index) const
nodiscard

Definition at line 2097 of file sdl_context.cpp.

2098{
2099 if (index >= _monitorIds.size())
2100 {
2101 return -1;
2102 }
2103 return _monitorIds.at(index);
2104}

◆ monitorIds()

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

Definition at line 2092 of file sdl_context.cpp.

2093{
2094 return _monitorIds;
2095}

◆ moveMouseTo()

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

Definition at line 1240 of file sdl_context.cpp.

1241{
1242 auto window = SDL_GetMouseFocus();
1243 if (!window)
1244 return true;
1245
1246 const auto id = SDL_GetWindowID(window);
1247 const auto spos = pixelToScreen(id, pos);
1248 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1249 return true;
1250}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const
nodiscard

Definition at line 1111 of file sdl_context.cpp.

1112{
1113 return _sdlPixelFormat;
1114}

◆ pixelToScreen() [1/2]

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

Definition at line 1666 of file sdl_context.cpp.

1667{
1668 auto w = getWindowForId(id);
1669 if (!w)
1670 {
1671 if (_rail.enabled() && _rail.ownsWindow(id))
1672 return pos;
1673 return {};
1674 }
1675
1676 /* Ignore errors here, sometimes SDL has no renderer */
1677 auto renderer = w->renderer();
1678 if (!renderer)
1679 return pos;
1680
1681 SDL_FPoint rpos{};
1682 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1683 return {};
1684 return applyLocalScaling(rpos);
1685}

◆ pixelToScreen() [2/2]

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

Definition at line 1687 of file sdl_context.cpp.

1688{
1689 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1690 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1691 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1692 if (round)
1693 {
1694 r.w = std::ceil(r.w);
1695 r.h = std::ceil(r.h);
1696 r.x = std::floor(r.x);
1697 r.y = std::floor(r.y);
1698 }
1699 return r;
1700}

◆ pointers()

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

Definition at line 1819 of file sdl_context.cpp.

1820{
1821 return _valid_pointers;
1822}

◆ pop()

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

Definition at line 2112 of file sdl_context.cpp.

2113{
2114 std::unique_lock lock(_queue_mux);
2115 if (_queue.empty())
2116 {
2117 return {};
2118 }
2119 auto val = std::move(_queue.front());
2120 _queue.pop();
2121 return val;
2122}

◆ presentRenderers()

bool SdlContext::presentRenderers ( )
nodiscard

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

Definition at line 2431 of file sdl_context.cpp.

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

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

2107{
2108 std::unique_lock lock(_queue_mux);
2109 _queue.emplace(std::move(rects));
2110}

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

2274{
2275 bool first = false;
2276 {
2277 std::scoped_lock lock(_windowInfoLock);
2278 first = _railWindowInfoPending.empty();
2279 _railWindowInfoPending.insert(remoteId);
2280 }
2281 if (first)
2282 std::ignore = sdl_push_user_event(SDL_EVENT_USER_WINDOW_INFO);
2283}

◆ redraw()

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

Definition at line 1973 of file sdl_context.cpp.

1974{
1975 if (!_connected)
1976 return true;
1977
1978 /* RemoteApp desktop windows are placeholders, hiding one must not stop server output. */
1979 if (suppress && freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode))
1980 return true;
1981
1982 auto gdi = context()->gdi;
1983 WINPR_ASSERT(gdi);
1984 return gdi_send_suppress_output(gdi, suppress);
1985}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID id)
nodiscard

Definition at line 1126 of file sdl_context.cpp.

1127{
1128 for (auto& w : _windows)
1129 {
1130 if (w.second.displayIndex() == id)
1131 _windows.erase(w.first);
1132 }
1133 return true;
1134}

◆ rendererAdd()

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

Definition at line 2348 of file sdl_context.cpp.

2349{
2350 std::scoped_lock lock(_rendererLock);
2351 const auto id = _nextRenderer++;
2352 auto& r = _renderers[id];
2353 r.mappingId = mappingId;
2354 r.callback = callback;
2355 if (callback)
2356 callback->AddRef();
2357 return id;
2358}

◆ rendererFrame()

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

Definition at line 2360 of file sdl_context.cpp.

2362{
2363 if (stride <= 0)
2364 return false;
2365
2366 {
2367 std::scoped_lock lock(_rendererLock);
2368 auto it = _renderers.find(id);
2369 if (it == _renderers.end())
2370 return false;
2371 auto& r = it->second;
2372 /* Render's buffer is the caller's for the call only */
2373 const size_t row = static_cast<size_t>(width) * 4;
2374 r.pixels.resize(row * height);
2375 for (UINT32 y = 0; y < height; y++)
2376 {
2377 const auto offset = row * y;
2378 const auto end = offset + row;
2379 const auto dataoffset = 1ull * y * static_cast<size_t>(stride);
2380
2381 try
2382 {
2383 auto& ptr = r.pixels.at(offset);
2384 std::ignore = r.pixels.at(end);
2385 memcpy(&ptr, &data[dataoffset], row);
2386 }
2387 catch (std::out_of_range& ex)
2388 {
2389 SDL_Log("failed to render: %s", ex.what());
2390 return false;
2391 }
2392 }
2393 r.pitch = static_cast<int>(row);
2394 r.width = static_cast<int>(width);
2395 r.height = static_cast<int>(height);
2396 r.dirty = true;
2397 }
2398 renderersChanged();
2399 return true;
2400}

◆ rendererRemove()

void SdlContext::rendererRemove ( Uint64 id)

Definition at line 2402 of file sdl_context.cpp.

2403{
2404 IWTSBitmapRendererCallback* callback = nullptr;
2405 {
2406 std::scoped_lock lock(_rendererLock);
2407 auto it = _renderers.find(id);
2408 if (it == _renderers.end())
2409 return;
2410 callback = it->second.callback;
2411 _renderers.erase(it);
2412 }
2413 if (callback)
2414 callback->Release();
2415 renderersChanged();
2416}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )
nodiscard

Definition at line 2037 of file sdl_context.cpp.

2038{
2039 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
2040 switch (_cursorType)
2041 {
2042 case CURSOR_NULL:
2043 if (!SDL_HideCursor())
2044 {
2045 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
2046 return false;
2047 }
2048
2049 setHasCursor(false);
2050 return true;
2051
2052 case CURSOR_DEFAULT:
2053 {
2054 auto def = SDL_GetDefaultCursor();
2055 if (!SDL_SetCursor(def))
2056 {
2057 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
2058 static_cast<void*>(def));
2059 return false;
2060 }
2061 if (!SDL_ShowCursor())
2062 {
2063 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
2064 return false;
2065 }
2066 setHasCursor(true);
2067 return true;
2068 }
2069 case CURSOR_IMAGE:
2070 setHasCursor(true);
2071 return sdl_Pointer_Set_Process(this);
2072 default:
2073 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
2074 sdl::utils::toString(_cursorType).c_str());
2075 return false;
2076 }
2077}

◆ screenToPixel()

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

Definition at line 1643 of file sdl_context.cpp.

1644{
1645 auto w = getWindowForId(id);
1646 if (!w)
1647 {
1648 /* RAIL windows are server-authoritative 1:1 (no local scaling) and not in _windows. */
1649 if (_rail.enabled() && _rail.ownsWindow(id))
1650 return pos;
1651 return {};
1652 }
1653
1654 /* Ignore errors here, sometimes SDL has no renderer */
1655 auto renderer = w->renderer();
1656 if (!renderer)
1657 return pos;
1658
1659 SDL_FPoint rpos{};
1660 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1661 return {};
1662 removeLocalScaling(rpos.x, rpos.y);
1663 return rpos;
1664}

◆ setConnected()

void SdlContext::setConnected ( bool val)

Definition at line 1987 of file sdl_context.cpp.

1988{
1989 _connected = val;
1990}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1839 of file sdl_context.cpp.

1840{
1841 _credentialsRead = true;
1842}

◆ setCursor() [1/2]

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

Definition at line 2022 of file sdl_context.cpp.

2023{
2024 std::unique_lock lock(_critical);
2025 if (!contains(cursor))
2026 return true;
2027
2028 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
2029 return setCursor(CURSOR_IMAGE);
2030}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType type)
nodiscard

Definition at line 2016 of file sdl_context.cpp.

2017{
2018 _cursorType = type;
2019 return restoreCursor();
2020}

◆ setFullscreen()

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

Definition at line 2124 of file sdl_context.cpp.

2125{
2126 for (const auto& window : _windows)
2127 {
2128 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
2129 forceOriginalDisplay))
2130 return false;
2131 }
2132 _fullscreen = enter;
2133 return true;
2134}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool enter)
nodiscard

Definition at line 2167 of file sdl_context.cpp.

2168{
2169 _grabKeyboard = enter;
2170 return true;
2171}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool enter)
nodiscard

Definition at line 2151 of file sdl_context.cpp.

2152{
2153 _grabMouse = enter;
2154 return true;
2155}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool val)

Definition at line 127 of file sdl_context.cpp.

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

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 137 of file sdl_context.cpp.

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

2137{
2138 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
2139}

◆ setMonitorIds()

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

Definition at line 2079 of file sdl_context.cpp.

2080{
2081 _monitorIds.clear();
2082 for (auto id : ids)
2083 {
2084 _monitorIds.push_back(id);
2085 }
2086 /* Only the selected displays are sent, so only they need to fit together. This runs during
2087 * connect, outside the thread that owns the windows; they are not touched here and are
2088 * created from the updated displays. */
2089 updateDisplayOffsets();
2090}

◆ setResizeable()

bool SdlContext::setResizeable ( bool enable)
nodiscard

Definition at line 2173 of file sdl_context.cpp.

2174{
2175 const auto settings = context()->settings;
2176 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
2177 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
2178 bool use = (dyn && enable) || smart;
2179
2180 for (const auto& window : _windows)
2181 {
2182 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
2183 return false;
2184 }
2185 _resizeable = use;
2186
2187 return true;
2188}

◆ shallAbort()

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

Definition at line 178 of file sdl_context.cpp.

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

◆ showOverlay()

bool SdlContext::showOverlay ( bool on)
nodiscard

Definition at line 1070 of file sdl_context.cpp.

1071{
1072 if (!_overlay.show(on))
1073 return false;
1074 if (on || !isConnected())
1075 return true;
1076
1077 /* hidden: present the picture once without it */
1078 auto window = overlayWindow();
1079 if (window)
1080 window->updateSurface();
1081 return true;
1082}

◆ start()

int SdlContext::start ( )
nodiscard

Definition at line 152 of file sdl_context.cpp.

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

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )
nodiscard

Definition at line 2205 of file sdl_context.cpp.

2206{
2207 return setFullscreen(!fullscreen());
2208}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )
nodiscard

Definition at line 2162 of file sdl_context.cpp.

2163{
2164 return setGrabKeyboard(!grabKeyboard());
2165}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )
nodiscard

Definition at line 2146 of file sdl_context.cpp.

2147{
2148 return setGrabMouse(!grabMouse());
2149}

◆ toggleOverlay()

bool SdlContext::toggleOverlay ( )
nodiscard

The stats and info overlay, SDL's thread

Definition at line 1065 of file sdl_context.cpp.

1066{
1067 return showOverlay(!_overlay.visible());
1068}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )
nodiscard

Definition at line 2195 of file sdl_context.cpp.

2196{
2197 return setResizeable(!resizeable());
2198}

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

1085{
1086 auto window = overlayWindow();
1087 if (!window || !isConnected())
1088 return true;
1089
1090 int w = 0;
1091 int h = 0;
1092 if (!SDL_GetWindowSizeInPixels(window->window(), &w, &h))
1093 return true;
1094 if (_overlay.update(w, h, window->rendererName()))
1095 window->updateSurface(&_overlay);
1096 return true;
1097}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID id)
nodiscard

Definition at line 636 of file sdl_context.cpp.

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

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

2237{
2238 WTS_WINDOW_INFO info{};
2239 auto window = getFirstWindow();
2240 if (window && window->window())
2241 {
2242 auto settings = _context->settings;
2243 info.hwnd = native_window(window->window());
2244 info.remoteWidth =
2245 static_cast<INT32>(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
2246 info.remoteHeight =
2247 static_cast<INT32>(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
2248 int w = 0;
2249 int h = 0;
2250 if (SDL_GetWindowSizeInPixels(window->window(), &w, &h))
2251 {
2252 info.viewWidth = w;
2253 info.viewHeight = h;
2254 }
2255 /* session pixels to native pixels */
2256 const float density = SDL_GetWindowPixelDensity(window->window());
2257 const auto p0 = pixelToScreen(window->id(), SDL_FPoint{ 0, 0 });
2258 const auto p1 = pixelToScreen(window->id(), SDL_FPoint{ 1000, 1000 });
2259 const float scale = (p1.x - p0.x) * density / 1000.0f;
2260 info.scale = (scale > 0.0f) ? scale : 1.0f;
2261 }
2262
2263 {
2264 std::scoped_lock lock(_windowInfoLock);
2265 if (window_info_equal(info, _desktopWindowInfo))
2266 return;
2267 _desktopWindowInfo = info;
2268 }
2269 if (!_rail.enabled())
2270 freerdp_client_window_info_service_changed(_context->windowInfoService, 0);
2271}

References freerdp_settings_get_uint32().

Here is the call graph for this function:

◆ updateWindowList()

bool SdlContext::updateWindowList ( )
nodiscard

Definition at line 605 of file sdl_context.cpp.

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

1845{
1846 return horizontal ? _wheelX : _wheelY;
1847}

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: