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 ()
void setSelectedPointer (rdpPointer *pointer)
bool isSelectedPointer (const rdpPointer *pointer)
rdpPointer * getSelectedPointer () const
 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 setNotification (const std::string &message)
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)
bool screenToRdp (SDL_WindowID id, const SDL_FPoint &pos, SDL_FPoint &rpos, SDL_FPoint *delta=nullptr)
SDL_Point inputOrigin () const
std::vector< SdlInputWindow > inputWindows (SDL_WindowID id, const SDL_Point &origin, std::optional< size_t > &source)
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 SdlInputWindow inputWindowGeometry (SDL_Window *window, SDL_Renderer *renderer)
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 53 of file sdl_context.hpp.

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

Constructor & Destructor Documentation

◆ SdlContext()

SdlContext::SdlContext ( rdpContext * context)
explicit

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

1787 : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1788 primary(nullptr, SDL_FreeSurface), primary_format(nullptr, SDL_FreeFormat),
1789 rdp_thread_running(false)
1790{
1791 WINPR_ASSERT(context);
1792 grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
1793}
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 100 of file sdl_context.cpp.

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

Member Function Documentation

◆ abortConnect()

bool SdlContext::abortConnect ( ) const
nodiscard

Definition at line 2121 of file sdl_context.cpp.

2122{
2123 freerdp_set_last_error(context(), FREERDP_ERROR_CONNECT_CANCELLED);
2124 return freerdp_abort_connect_context(context());
2125}

◆ addDisplayWindow()

bool SdlContext::addDisplayWindow ( SDL_DisplayID id)
nodiscard

Definition at line 1133 of file sdl_context.cpp.

1134{
1135 const auto flags =
1136 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1137 auto title = sdl::utils::windowTitle(context()->settings);
1138 auto w = SdlWindow::create(id, title, flags);
1139 _windows.emplace(w.id(), std::move(w));
1140 return true;
1141}

◆ allowScreenSaver()

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

Definition at line 125 of file sdl_context.cpp.

126{
127 return _allowScreenSaver;
128}

◆ allWindowsHidden()

bool SdlContext::allWindowsHidden ( ) const
nodiscard

Definition at line 1210 of file sdl_context.cpp.

1211{
1212 return std::all_of(_windows.begin(), _windows.end(),
1213 [](const auto& entry)
1214 {
1215 const auto flags = SDL_GetWindowFlags(entry.second.window());
1216 return (flags & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) != 0;
1217 });
1218}

◆ applyMonitorScaleOverride()

void SdlContext::applyMonitorScaleOverride ( rdpMonitor & monitor) const

Definition at line 1931 of file sdl_context.cpp.

1932{
1933 freerdp_client_apply_monitor_scale(context()->settings, &monitor);
1934}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )
nodiscard

Definition at line 1886 of file sdl_context.cpp.

1887{
1888 return _args.data();
1889}

◆ argsCount()

size_t SdlContext::argsCount ( ) const
nodiscard

Definition at line 1891 of file sdl_context.cpp.

1892{
1893 if (_args.size() <= 1)
1894 return 0;
1895 return _args.size() - 1;
1896}

◆ argumentHandler()

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

Definition at line 1898 of file sdl_context.cpp.

1899{
1900 auto sdl = static_cast<SdlContext*>(custom);
1901 if (!sdl)
1902 return -1;
1903
1904 if (arg->Name)
1905 {
1906 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1907 {
1908 sdl->_allowScreenSaver = (arg->Value != nullptr);
1909 if (arg->Value != nullptr)
1910 {
1911 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1912 {
1913 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1914 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1915 SDL_GetError());
1916 return -2;
1917 }
1918 }
1919 }
1920 else if (strcmp(arg->Name, sdl_connection_dialog) == 0)
1921 sdl->_connectionDialog = (arg->Value != nullptr);
1922 else if (strcmp(arg->Name, sdl_info) == 0)
1923 {
1924 if (!sdl->_overlay.show(arg->Value != nullptr))
1925 return -2;
1926 }
1927 }
1928 return 0;
1929}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 178 of file sdl_context.cpp.

179{
180 std::unique_lock lock(_critical);
181 _windows.clear();
182 _dialog.destroy();
183 _primary.reset();
184}

◆ common()

rdpClientContext * SdlContext::common ( ) const
nodiscard

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

1801{
1802 return reinterpret_cast<rdpClientContext*>(_context);
1803}

◆ contains()

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

Definition at line 1946 of file sdl_context.cpp.

1947{
1948 for (const auto& cur : _valid_pointers)
1949 {
1950 if (cur == ptr)
1951 return true;
1952 }
1953 return false;
1954}

◆ context()

rdpContext * SdlContext::context ( ) const
nodiscard

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

1796{
1797 return _context;
1798}

◆ createWindows()

bool SdlContext::createWindows ( )
nodiscard

Definition at line 481 of file sdl_context.cpp.

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

1957{
1958 return _credentialsRead;
1959}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const
nodiscard

Definition at line 2154 of file sdl_context.cpp.

2155{
2156 return _cursor.get();
2157}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )
nodiscard

Definition at line 1153 of file sdl_context.cpp.

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

◆ drawToWindow()

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

Definition at line 1030 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1994 of file sdl_context.cpp.

1995{
1996 /* RAIL damage is per-window (_gfxDamage), not in the rects queue: repaint every tick. */
1997 if (_rail.enabled())
1998 {
1999 for (auto& window : _windows)
2000 {
2001 if ((SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN) == 0)
2002 SDL_HideWindow(window.second.window());
2003 }
2004
2005 std::unique_lock lock(_critical);
2006 _rail.paint(_primary.get(), pixelFormat(), rects);
2007 return true;
2008 }
2009
2010 /* Non-RAIL mode (e.g. Non-Monitored Desktop during UAC / Consent UI): show the desktop window.
2011 * Before the RemoteApp starts, only when the logon needs the user. */
2012 if (freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode) &&
2013 !_rail.desktopMayShow())
2014 return true;
2015 bool firstShow = false;
2016 for (auto& window : _windows)
2017 {
2018 if (SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN)
2019 {
2020 SDL_ShowWindow(window.second.window());
2021 SDL_RaiseWindow(window.second.window());
2022 firstShow = true;
2023 }
2024 }
2025
2026 if (rects.empty() && !firstShow)
2027 return true;
2028
2029 std::vector<SDL_Rect> drawRects = rects;
2030 {
2031 std::unique_lock lock(_critical);
2032 if ((drawRects.empty() || firstShow) && _primary)
2033 drawRects = { { 0, 0, _primary->w, _primary->h } };
2034 }
2035
2036 for (auto& window : _windows)
2037 {
2038 if (!drawToWindow(window.second, drawRects))
2039 return false;
2040 }
2041
2042 return true;
2043}

◆ exitCode()

int SdlContext::exitCode ( ) const
nodiscard

Definition at line 1123 of file sdl_context.cpp.

1124{
1125 return _exitCode;
1126}

◆ flushWindowInfo()

void SdlContext::flushWindowInfo ( )

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

Definition at line 2407 of file sdl_context.cpp.

2408{
2409 std::set<uint64_t> pending;
2410 {
2411 std::scoped_lock lock(_windowInfoLock);
2412 pending.swap(_railWindowInfoPending);
2413 }
2414
2415 for (const auto id : pending)
2416 {
2417 WTS_WINDOW_INFO info{};
2418 SDL_Window* window = nullptr;
2419 /* RemoteApp windows are drawn 1:1: the same remote and view size, scale left at 0 */
2420 if (_rail.windowGeometry(id, window, info.viewWidth, info.viewHeight))
2421 {
2422 info.hwnd = native_window(window);
2423 info.remoteWidth = info.viewWidth;
2424 info.remoteHeight = info.viewHeight;
2425 }
2426 {
2427 std::scoped_lock lock(_windowInfoLock);
2428 if (info.viewWidth > 0)
2429 _railWindowInfo[id] = info;
2430 else
2431 _railWindowInfo.erase(id);
2432 }
2433 if (info.viewWidth > 0)
2434 freerdp_client_window_info_service_changed(_context->windowInfoService, id);
2435 }
2436}

◆ getAadAuthHelper()

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

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

1806{
1807 return _aadAuthHelper;
1808}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )
nodiscard

Definition at line 1295 of file sdl_context.cpp.

1296{
1297 return _clip;
1298}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )
nodiscard

Definition at line 1305 of file sdl_context.cpp.

1306{
1307 return _dialog;
1308}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID id) const
nodiscard

Definition at line 1178 of file sdl_context.cpp.

1179{
1180 return _displays.at(id);
1181}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )
nodiscard

Definition at line 1285 of file sdl_context.cpp.

1286{
1287 return _disp;
1288}

◆ getDisplayIds()

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

Definition at line 1183 of file sdl_context.cpp.

1184{
1185 std::vector<SDL_DisplayID> keys;
1186 keys.reserve(_displays.size());
1187 for (const auto& entry : _displays)
1188 {
1189 keys.push_back(entry.first);
1190 }
1191 return keys;
1192}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )
nodiscard

Definition at line 1220 of file sdl_context.cpp.

1221{
1222 if (_windows.empty())
1223 return nullptr;
1224 return &_windows.begin()->second;
1225}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )
nodiscard

Definition at line 1290 of file sdl_context.cpp.

1291{
1292 return _input;
1293}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )
nodiscard

Definition at line 1300 of file sdl_context.cpp.

1301{
1302 return _rail;
1303}

◆ getSelectedPointer()

rdpPointer * SdlContext::getSelectedPointer ( ) const
nodiscard

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

1823{
1824 return _selected_pointer;
1825}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID id)
nodiscard

Definition at line 1202 of file sdl_context.cpp.

1203{
1204 auto it = _windows.find(id);
1205 if (it == _windows.end())
1206 return nullptr;
1207 return &it->second;
1208}

◆ getWindowForId() [2/2]

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

Definition at line 1194 of file sdl_context.cpp.

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

◆ getWLog()

wLog * SdlContext::getWLog ( )
nodiscard

Definition at line 1310 of file sdl_context.cpp.

1311{
1312 return _log;
1313}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const
nodiscard

Definition at line 2279 of file sdl_context.cpp.

2280{
2281 return _grabKeyboard;
2282}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const
nodiscard

Definition at line 2263 of file sdl_context.cpp.

2264{
2265 return _grabMouse;
2266}

◆ handleEvent()

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

Definition at line 1819 of file sdl_context.cpp.

1820{
1821 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1822 {
1823 const auto& dev = ev.display;
1824 return handleEvent(dev);
1825 }
1826 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1827 {
1828 const auto& wev = ev.window;
1829 return handleEvent(wev);
1830 }
1831 switch (ev.type)
1832 {
1833 case SDL_EVENT_RENDER_TARGETS_RESET:
1834 case SDL_EVENT_RENDER_DEVICE_RESET:
1835 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1836 return redraw();
1837 default:
1838 break;
1839 }
1840
1841 if (!isConnected())
1842 return true;
1843
1844 switch (ev.type)
1845 {
1846 case SDL_EVENT_FINGER_DOWN:
1847 case SDL_EVENT_FINGER_UP:
1848 case SDL_EVENT_FINGER_MOTION:
1849 {
1850 const auto& cev = ev.tfinger;
1851 return handleEvent(cev);
1852 }
1853 case SDL_EVENT_MOUSE_MOTION:
1854
1855 {
1856 const auto& cev = ev.motion;
1857 return handleEvent(cev);
1858 }
1859 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1860 case SDL_EVENT_MOUSE_BUTTON_UP:
1861 {
1862 const auto& cev = ev.button;
1863 return handleEvent(cev);
1864 }
1865 case SDL_EVENT_MOUSE_WHEEL:
1866 {
1867 const auto& cev = ev.wheel;
1868 return handleEvent(cev);
1869 }
1870 case SDL_EVENT_CLIPBOARD_UPDATE:
1871 {
1872 const auto& cev = ev.clipboard;
1873 return getClipboardChannelContext().handleEvent(cev);
1874 }
1875 case SDL_EVENT_KEY_DOWN:
1876 case SDL_EVENT_KEY_UP:
1877 {
1878 const auto& cev = ev.key;
1879 return getInputChannelContext().handleEvent(cev);
1880 }
1881 default:
1882 return true;
1883 }
1884}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const
nodiscard

Definition at line 135 of file sdl_context.cpp.

136{
137 return _cursor_visible;
138}

◆ hasRenderers()

bool SdlContext::hasRenderers ( )
nodiscard

Definition at line 2540 of file sdl_context.cpp.

2541{
2542 std::scoped_lock lock(_rendererLock);
2543 return !_renderers.empty();
2544}

◆ inputOrigin()

SDL_Point SdlContext::inputOrigin ( ) const
nodiscard

Definition at line 1715 of file sdl_context.cpp.

1716{
1717 auto settings = context()->settings;
1718 const auto count = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
1719 std::vector<SDL_Rect> layout;
1720 layout.reserve(count);
1721 for (UINT32 x = 0; x < count; x++)
1722 {
1723 const auto* monitor = static_cast<const rdpMonitor*>(
1724 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x));
1725 if (monitor)
1726 layout.push_back({ monitor->x, monitor->y, monitor->width, monitor->height });
1727 }
1728 return sdl_layout_input_origin(layout);
1729}
Layout layout(float leftWidth, float leftHeight, float rightWidth, float rightHeight, float width, float margin)

◆ inputWindowGeometry()

SdlInputWindow SdlContext::inputWindowGeometry ( SDL_Window * window,
SDL_Renderer * renderer )
staticnodiscard

Definition at line 1731 of file sdl_context.cpp.

1732{
1733 SdlInputWindow input{};
1734 if (!window)
1735 return input;
1736
1737 /* Wayland cannot report window positions; such windows keep their own mapping. */
1738 if (!sdl::utils::isWaylandDriver())
1739 {
1740 SDL_Rect bounds{};
1741 if (SDL_GetWindowPosition(window, &bounds.x, &bounds.y) &&
1742 SDL_GetWindowSize(window, &bounds.w, &bounds.h))
1743 input.local = bounds;
1744 }
1745
1746 /* Without a renderer, positions are used as they are. */
1747 if (renderer)
1748 input.density = SDL_GetWindowPixelDensity(window);
1749 return input;
1750}

◆ inputWindows()

std::vector< SdlInputWindow > SdlContext::inputWindows ( SDL_WindowID id,
const SDL_Point & origin,
std::optional< size_t > & source )
nodiscard

Definition at line 1752 of file sdl_context.cpp.

1754{
1755 source.reset();
1756 std::vector<SdlInputWindow> windows;
1757 windows.reserve(_windows.size());
1758
1759 const auto multimon = freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon);
1760 for (auto& entry : _windows)
1761 {
1762 auto& window = entry.second;
1763 const auto isSource = (entry.first == id);
1764 /* The RemoteApp desktop window is hidden unless needed. */
1765 if (!isSource && ((SDL_GetWindowFlags(window.window()) & SDL_WINDOW_HIDDEN) != 0))
1766 continue;
1767
1768 auto input = inputWindowGeometry(window.window(), window.renderer());
1769 if (window.renderer() && useLocalScale())
1770 input.scale = _localScale;
1771 /* Without /multimon the single window is the only 'monitor': it shows the whole
1772 * desktop, from the layout origin. */
1773 input.layout = multimon ? window.layoutPosition() : origin;
1774 if (isSource)
1775 source = windows.size();
1776 windows.push_back(input);
1777 }
1778
1779 _rail.inputWindows(id, windows, source);
1780 return windows;
1781}

◆ isConnected()

bool SdlContext::isConnected ( ) const
nodiscard

Definition at line 2114 of file sdl_context.cpp.

2115{
2116 return _connected;
2117}

◆ isSelectedPointer()

bool SdlContext::isSelectedPointer ( const rdpPointer * pointer)
nodiscard

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

1816{
1817 if (!_selected_pointer)
1818 return false;
1819 return _selected_pointer == pointer;
1820}

◆ join()

int SdlContext::join ( )
nodiscard

Definition at line 166 of file sdl_context.cpp.

167{
168 /* We do not want to use freerdp_abort_connect_context here.
169 * It would change the exit code and we do not want that. */
170 HANDLE event = freerdp_abort_event(context());
171 if (!SetEvent(event))
172 return -1;
173
174 _thread.join();
175 return 0;
176}

◆ lock()

CriticalSection & SdlContext::lock ( )
nodiscard

Definition at line 1936 of file sdl_context.cpp.

1937{
1938 return _critical;
1939}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )
nodiscard

Definition at line 1116 of file sdl_context.cpp.

1117{
1118 for (auto& w : _windows)
1119 w.second.minimize();
1120 return true;
1121}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t index) const
nodiscard

Definition at line 2219 of file sdl_context.cpp.

2220{
2221 if (index >= _monitorIds.size())
2222 {
2223 return -1;
2224 }
2225 return _monitorIds.at(index);
2226}

◆ monitorIds()

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

Definition at line 2214 of file sdl_context.cpp.

2215{
2216 return _monitorIds;
2217}

◆ moveMouseTo()

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

Definition at line 1315 of file sdl_context.cpp.

1316{
1317 auto window = SDL_GetMouseFocus();
1318 if (!window)
1319 return true;
1320
1321 const auto id = SDL_GetWindowID(window);
1322 const auto spos = pixelToScreen(id, pos);
1323 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1324 return true;
1325}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const
nodiscard

Definition at line 1128 of file sdl_context.cpp.

1129{
1130 return _sdlPixelFormat;
1131}

◆ pixelToScreen() [1/2]

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

Definition at line 1783 of file sdl_context.cpp.

1784{
1785 auto w = getWindowForId(id);
1786 if (!w)
1787 {
1788 if (_rail.enabled() && _rail.ownsWindow(id))
1789 return pos;
1790 return {};
1791 }
1792
1793 /* Ignore errors here, sometimes SDL has no renderer */
1794 auto renderer = w->renderer();
1795 if (!renderer)
1796 return pos;
1797
1798 SDL_FPoint rpos{};
1799 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1800 return {};
1801 return applyLocalScaling(rpos);
1802}

◆ pixelToScreen() [2/2]

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

Definition at line 1804 of file sdl_context.cpp.

1805{
1806 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1807 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1808 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1809 if (round)
1810 {
1811 r.w = std::ceil(r.w);
1812 r.h = std::ceil(r.h);
1813 r.x = std::floor(r.x);
1814 r.y = std::floor(r.y);
1815 }
1816 return r;
1817}

◆ pointers()

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

Definition at line 1941 of file sdl_context.cpp.

1942{
1943 return _valid_pointers;
1944}

◆ pop()

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

Definition at line 2234 of file sdl_context.cpp.

2235{
2236 std::unique_lock lock(_queue_mux);
2237 if (_queue.empty())
2238 {
2239 return {};
2240 }
2241 auto val = std::move(_queue.front());
2242 _queue.pop();
2243 return val;
2244}

◆ presentRenderers()

bool SdlContext::presentRenderers ( )
nodiscard

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

Definition at line 2553 of file sdl_context.cpp.

2554{
2555 _renderersPending = false;
2556 if (!isConnected())
2557 return true;
2558
2559 /* OnTargetSizeChanged() calls, made once _rendererLock is released */
2560 std::vector<std::pair<IWTSBitmapRendererCallback*, WTS_RECT>> targets;
2561 {
2562 std::scoped_lock lock(_rendererLock);
2563
2564 /* a renderer is placed by its mapping's geometry (MS-RDPEGT), hidden without one */
2565 struct Placement
2566 {
2567 bool visible = false;
2568 SDL_Rect rect{};
2569 std::vector<SDL_Rect> region; /* the visible parts, empty: all of it */
2570 };
2571 std::map<Uint64, Placement> placements;
2572 rdpGdi* gdi = _context->gdi;
2573 GeometryClientContext* geometry = gdi ? gdi->geometry : nullptr;
2574 if (geometry && geometry->geometries)
2575 {
2576 HashTable_Lock(geometry->geometries);
2577 for (auto& kv : _renderers)
2578 {
2579 auto g = static_cast<const MAPPED_GEOMETRY*>(
2580 HashTable_GetItemValue(geometry->geometries, &kv.second.mappingId));
2581 if (!g)
2582 continue;
2583 Placement p;
2584 p.rect = { static_cast<int>(g->topLevelLeft + g->left),
2585 static_cast<int>(g->topLevelTop + g->top),
2586 static_cast<int>(std::max<INT64>(0, g->right - g->left)),
2587 static_cast<int>(std::max<INT64>(0, g->bottom - g->top)) };
2588 p.visible = (p.rect.w > 0) && (p.rect.h > 0);
2589 /* the region's rectangles are relative to the tracked rectangle */
2590 INT64 area = 0;
2591 for (UINT32 i = 0; g->geometry.rects && (i < g->geometry.nRectCount); i++)
2592 {
2593 const RDP_RECT& r = g->geometry.rects[i];
2594 const int left = std::max(0, static_cast<int>(r.x));
2595 const int top = std::max(0, static_cast<int>(r.y));
2596 const int right = std::min(p.rect.w, r.x + r.width);
2597 const int bottom = std::min(p.rect.h, r.y + r.height);
2598 if ((right <= left) || (bottom <= top))
2599 continue;
2600 area += static_cast<INT64>(right - left) * (bottom - top);
2601 p.region.push_back(
2602 { p.rect.x + left, p.rect.y + top, right - left, bottom - top });
2603 }
2604 if (area >= static_cast<INT64>(p.rect.w) * p.rect.h)
2605 p.region.clear();
2606 placements[kv.first] = std::move(p);
2607 }
2608 HashTable_Unlock(geometry->geometries);
2609 }
2610
2611 for (auto& kv : _renderers)
2612 {
2613 auto& r = kv.second;
2614 const auto& p = placements[kv.first];
2615 if (p.visible && r.callback && !SDL_RectsEqual(&p.rect, &r.target))
2616 {
2617 r.target = p.rect;
2618 r.callback->AddRef();
2619 targets.emplace_back(r.callback, WTS_RECT{ p.rect.x, p.rect.y, p.rect.x + p.rect.w,
2620 p.rect.y + p.rect.h });
2621 }
2622 }
2623
2624 for (auto& w : _windows)
2625 {
2626 auto& window = w.second;
2627 window.pruneVideoOverlays([this](Uint64 id) { return _renderers.count(id) != 0; });
2628 for (auto& kv : _renderers)
2629 {
2630 auto& r = kv.second;
2631 const auto& p = placements[kv.first];
2632 /* where the session is drawn in the window: as drawToWindow() does */
2633 SDL_Point offset{ 0, 0 };
2634 if (!useLocalScale() &&
2635 freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
2636 offset = { window.offsetX(), window.offsetY() };
2637 auto toWindow = [&](const SDL_Rect& rc)
2638 {
2639 if (useLocalScale())
2640 return SDL_FRect{ static_cast<float>(rc.x) * _localScale.x,
2641 static_cast<float>(rc.y) * _localScale.y,
2642 static_cast<float>(rc.w) * _localScale.x,
2643 static_cast<float>(rc.h) * _localScale.y };
2644 return SDL_FRect{ static_cast<float>(rc.x + offset.x),
2645 static_cast<float>(rc.y + offset.y), static_cast<float>(rc.w),
2646 static_cast<float>(rc.h) };
2647 };
2648 const SDL_FRect dst = toWindow(p.rect);
2649 std::vector<SDL_FRect> clip;
2650 clip.reserve(p.region.size());
2651 for (const auto& rc : p.region)
2652 clip.push_back(toWindow(rc));
2653 const bool visible = p.visible && !r.pixels.empty();
2654 if (!window.setVideoOverlay(kv.first, r.dirty ? r.pixels.data() : nullptr, r.pitch,
2655 r.width, r.height, dst, clip, visible))
2656 continue;
2657 }
2658 window.updateSurface();
2659 }
2660 for (auto& kv : _renderers)
2661 kv.second.dirty = false;
2662 }
2663
2664 for (auto& t : targets)
2665 {
2666 std::ignore = t.first->OnTargetSizeChanged(t.second);
2667 t.first->Release();
2668 }
2669 return true;
2670}

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

2229{
2230 std::unique_lock lock(_queue_mux);
2231 _queue.emplace(std::move(rects));
2232}

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

2396{
2397 bool first = false;
2398 {
2399 std::scoped_lock lock(_windowInfoLock);
2400 first = _railWindowInfoPending.empty();
2401 _railWindowInfoPending.insert(remoteId);
2402 }
2403 if (first)
2404 std::ignore = sdl_push_user_event(SDL_EVENT_USER_WINDOW_INFO);
2405}

◆ redraw()

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

Definition at line 2095 of file sdl_context.cpp.

2096{
2097 if (!_connected)
2098 return true;
2099
2100 /* RemoteApp desktop windows are placeholders, hiding one must not stop server output. */
2101 if (suppress && freerdp_settings_get_bool(context()->settings, FreeRDP_RemoteApplicationMode))
2102 return true;
2103
2104 auto gdi = context()->gdi;
2105 WINPR_ASSERT(gdi);
2106 return gdi_send_suppress_output(gdi, suppress);
2107}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID id)
nodiscard

Definition at line 1143 of file sdl_context.cpp.

1144{
1145 for (auto& w : _windows)
1146 {
1147 if (w.second.displayIndex() == id)
1148 _windows.erase(w.first);
1149 }
1150 return true;
1151}

◆ rendererAdd()

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

Definition at line 2470 of file sdl_context.cpp.

2471{
2472 std::scoped_lock lock(_rendererLock);
2473 const auto id = _nextRenderer++;
2474 auto& r = _renderers[id];
2475 r.mappingId = mappingId;
2476 r.callback = callback;
2477 if (callback)
2478 callback->AddRef();
2479 return id;
2480}

◆ rendererFrame()

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

Definition at line 2482 of file sdl_context.cpp.

2484{
2485 if (stride <= 0)
2486 return false;
2487
2488 {
2489 std::scoped_lock lock(_rendererLock);
2490 auto it = _renderers.find(id);
2491 if (it == _renderers.end())
2492 return false;
2493 auto& r = it->second;
2494 /* Render's buffer is the caller's for the call only */
2495 const size_t row = static_cast<size_t>(width) * 4;
2496 r.pixels.resize(row * height);
2497 for (UINT32 y = 0; y < height; y++)
2498 {
2499 const auto offset = row * y;
2500 const auto end = offset + row;
2501 const auto dataoffset = 1ull * y * static_cast<size_t>(stride);
2502
2503 try
2504 {
2505 auto& ptr = r.pixels.at(offset);
2506 std::ignore = r.pixels.at(end);
2507 memcpy(&ptr, &data[dataoffset], row);
2508 }
2509 catch (std::out_of_range& ex)
2510 {
2511 SDL_Log("failed to render: %s", ex.what());
2512 return false;
2513 }
2514 }
2515 r.pitch = static_cast<int>(row);
2516 r.width = static_cast<int>(width);
2517 r.height = static_cast<int>(height);
2518 r.dirty = true;
2519 }
2520 renderersChanged();
2521 return true;
2522}

◆ rendererRemove()

void SdlContext::rendererRemove ( Uint64 id)

Definition at line 2524 of file sdl_context.cpp.

2525{
2526 IWTSBitmapRendererCallback* callback = nullptr;
2527 {
2528 std::scoped_lock lock(_rendererLock);
2529 auto it = _renderers.find(id);
2530 if (it == _renderers.end())
2531 return;
2532 callback = it->second.callback;
2533 _renderers.erase(it);
2534 }
2535 if (callback)
2536 callback->Release();
2537 renderersChanged();
2538}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )
nodiscard

Definition at line 2159 of file sdl_context.cpp.

2160{
2161 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
2162 switch (_cursorType)
2163 {
2164 case CURSOR_NULL:
2165 if (!SDL_HideCursor())
2166 {
2167 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
2168 return false;
2169 }
2170
2171 setHasCursor(false);
2172 return true;
2173
2174 case CURSOR_DEFAULT:
2175 {
2176 auto def = SDL_GetDefaultCursor();
2177 if (!SDL_SetCursor(def))
2178 {
2179 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
2180 static_cast<void*>(def));
2181 return false;
2182 }
2183 if (!SDL_ShowCursor())
2184 {
2185 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
2186 return false;
2187 }
2188 setHasCursor(true);
2189 return true;
2190 }
2191 case CURSOR_IMAGE:
2192 setHasCursor(true);
2193 return sdl_Pointer_Set_Process(this);
2194 default:
2195 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
2196 sdl::utils::toString(_cursorType).c_str());
2197 return false;
2198 }
2199}

◆ screenToRdp()

bool SdlContext::screenToRdp ( SDL_WindowID id,
const SDL_FPoint & pos,
SDL_FPoint & rpos,
SDL_FPoint * delta = nullptr )
nodiscard

Definition at line 1698 of file sdl_context.cpp.

1700{
1701 const auto origin = inputOrigin();
1702 std::optional<size_t> source;
1703 const auto windows = inputWindows(id, origin, source);
1704 if (!source)
1705 return false;
1706 const auto mapped = sdl_window_to_input(windows, *source, pos, origin);
1707 if (!mapped)
1708 return false;
1709 rpos = *mapped;
1710 if (delta)
1711 *delta = sdl_window_delta_to_input(windows[*source], *delta);
1712 return true;
1713}

◆ setConnected()

void SdlContext::setConnected ( bool val)

Definition at line 2109 of file sdl_context.cpp.

2110{
2111 _connected = val;
2112}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1961 of file sdl_context.cpp.

1962{
1963 _credentialsRead = true;
1964}

◆ setCursor() [1/2]

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

Definition at line 2144 of file sdl_context.cpp.

2145{
2146 std::unique_lock lock(_critical);
2147 if (!contains(cursor))
2148 return true;
2149
2150 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
2151 return setCursor(CURSOR_IMAGE);
2152}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType type)
nodiscard

Definition at line 2138 of file sdl_context.cpp.

2139{
2140 _cursorType = type;
2141 return restoreCursor();
2142}

◆ setFullscreen()

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

Definition at line 2246 of file sdl_context.cpp.

2247{
2248 for (const auto& window : _windows)
2249 {
2250 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
2251 forceOriginalDisplay))
2252 return false;
2253 }
2254 _fullscreen = enter;
2255 return true;
2256}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool enter)
nodiscard

Definition at line 2289 of file sdl_context.cpp.

2290{
2291 _grabKeyboard = enter;
2292 return true;
2293}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool enter)
nodiscard

Definition at line 2273 of file sdl_context.cpp.

2274{
2275 _grabMouse = enter;
2276 return true;
2277}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool val)

Definition at line 130 of file sdl_context.cpp.

131{
132 this->_cursor_visible = val;
133}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 140 of file sdl_context.cpp.

141{
142 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
143 if (!wmclass || (strlen(wmclass) == 0))
144 wmclass = SDL_CLIENT_UUID;
145
146 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
147#if !defined(__APPLE__)
148 /* On macOS SDL names the application menu (About, Hide, Quit) after this. Leave it unset
149 * so SDL takes CFBundleName from the bundle's Info.plist, the name the user sees in the
150 * Dock and Finder. */
151 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
152#endif
153 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
154 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
155 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
156 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
157 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
158}
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 2258 of file sdl_context.cpp.

2259{
2260 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
2261}

◆ setMonitorIds()

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

Definition at line 2201 of file sdl_context.cpp.

2202{
2203 _monitorIds.clear();
2204 for (auto id : ids)
2205 {
2206 _monitorIds.push_back(id);
2207 }
2208 /* Only the selected displays are sent, so only they need to fit together. This runs during
2209 * connect, outside the thread that owns the windows; they are not touched here and are
2210 * created from the updated displays. */
2211 updateDisplayOffsets();
2212}

◆ setNotification()

bool SdlContext::setNotification ( const std::string & message)
nodiscard

Shows message in the title of the first session window, or restores that title when message is empty. Can be called from any thread, the title changes on the main thread.

Definition at line 1227 of file sdl_context.cpp.

1228{
1229 {
1230 std::scoped_lock lock(_notificationLock);
1231 _notification = message;
1232 }
1233
1234 return SDL_RunOnMainThread(
1235 [](void* user) { static_cast<SdlContext*>(user)->updateNotification(); }, this, false);
1236}

◆ setResizeable()

bool SdlContext::setResizeable ( bool enable)
nodiscard

Definition at line 2295 of file sdl_context.cpp.

2296{
2297 const auto settings = context()->settings;
2298 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
2299 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
2300 bool use = (dyn && enable) || smart;
2301
2302 for (const auto& window : _windows)
2303 {
2304 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
2305 return false;
2306 }
2307 _resizeable = use;
2308
2309 return true;
2310}

◆ setSelectedPointer()

void SdlContext::setSelectedPointer ( rdpPointer * pointer)

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

1811{
1812 _selected_pointer = pointer;
1813}

◆ shallAbort()

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

Definition at line 186 of file sdl_context.cpp.

187{
188 std::unique_lock lock(_critical);
189 if (freerdp_shall_disconnect_context(context()))
190 {
191 if (ignoreDialogs)
192 return true;
193 if (_rdpThreadRunning)
194 return false;
195 return !getDialog().isRunning();
196 }
197 return false;
198}

◆ showOverlay()

bool SdlContext::showOverlay ( bool on)
nodiscard

Definition at line 1087 of file sdl_context.cpp.

1088{
1089 if (!_overlay.show(on))
1090 return false;
1091 if (on || !isConnected())
1092 return true;
1093
1094 /* hidden: present the picture once without it */
1095 auto window = overlayWindow();
1096 if (window)
1097 window->updateSurface();
1098 return true;
1099}

◆ start()

int SdlContext::start ( )
nodiscard

Definition at line 160 of file sdl_context.cpp.

161{
162 _thread = std::thread(rdpThreadRun, this);
163 return 0;
164}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )
nodiscard

Definition at line 2327 of file sdl_context.cpp.

2328{
2329 return setFullscreen(!fullscreen());
2330}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )
nodiscard

Definition at line 2284 of file sdl_context.cpp.

2285{
2286 return setGrabKeyboard(!grabKeyboard());
2287}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )
nodiscard

Definition at line 2268 of file sdl_context.cpp.

2269{
2270 return setGrabMouse(!grabMouse());
2271}

◆ toggleOverlay()

bool SdlContext::toggleOverlay ( )
nodiscard

The stats and info overlay, SDL's thread

Definition at line 1082 of file sdl_context.cpp.

1083{
1084 return showOverlay(!_overlay.visible());
1085}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )
nodiscard

Definition at line 2317 of file sdl_context.cpp.

2318{
2319 return setResizeable(!resizeable());
2320}

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL enter)

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

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

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

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

1762{
1763 std::scoped_lock lock(critical);
1764 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1765}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL enable)

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

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

◆ updateOverlay()

bool SdlContext::updateOverlay ( )
nodiscard

Definition at line 1101 of file sdl_context.cpp.

1102{
1103 auto window = overlayWindow();
1104 if (!window || !isConnected())
1105 return true;
1106
1107 int w = 0;
1108 int h = 0;
1109 if (!SDL_GetWindowSizeInPixels(window->window(), &w, &h))
1110 return true;
1111 if (_overlay.update(w, h, window->rendererName()))
1112 window->updateSurface(&_overlay);
1113 return true;
1114}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID id)
nodiscard

Definition at line 662 of file sdl_context.cpp.

663{
664 /* In fullscreen the monitor kept the size measured with the probe window at startup and was
665 * never updated, so a session the server started at another size stayed that way. Only the
666 * window knows its real size, so ask it in fullscreen as well. */
667 if (freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
668 return true;
669
670 auto& w = _windows.at(id);
671 auto m = w.monitor(true);
672 applyMonitorScaleOverride(m);
673 auto r = w.rect();
674 m.width = r.w;
675 m.height = r.h;
676 /* The window may be on another display than the one it was created on. */
677 m.attributes.desktopScaleFactor = static_cast<UINT32>(std::roundf(w.scale() * 100.0f));
678 w.setMonitor(m);
679 return true;
680}

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

2359{
2360 WTS_WINDOW_INFO info{};
2361 auto window = getFirstWindow();
2362 if (window && window->window())
2363 {
2364 auto settings = _context->settings;
2365 info.hwnd = native_window(window->window());
2366 info.remoteWidth =
2367 static_cast<INT32>(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
2368 info.remoteHeight =
2369 static_cast<INT32>(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
2370 int w = 0;
2371 int h = 0;
2372 if (SDL_GetWindowSizeInPixels(window->window(), &w, &h))
2373 {
2374 info.viewWidth = w;
2375 info.viewHeight = h;
2376 }
2377 /* session pixels to native pixels */
2378 const float density = SDL_GetWindowPixelDensity(window->window());
2379 const auto p0 = pixelToScreen(window->id(), SDL_FPoint{ 0, 0 });
2380 const auto p1 = pixelToScreen(window->id(), SDL_FPoint{ 1000, 1000 });
2381 const float scale = (p1.x - p0.x) * density / 1000.0f;
2382 info.scale = (scale > 0.0f) ? scale : 1.0f;
2383 }
2384
2385 {
2386 std::scoped_lock lock(_windowInfoLock);
2387 if (window_info_equal(info, _desktopWindowInfo))
2388 return;
2389 _desktopWindowInfo = info;
2390 }
2391 if (!_rail.enabled())
2392 freerdp_client_window_info_service_changed(_context->windowInfoService, 0);
2393}

References freerdp_settings_get_uint32().

Here is the call graph for this function:

◆ updateWindowList()

bool SdlContext::updateWindowList ( )
nodiscard

Definition at line 627 of file sdl_context.cpp.

628{
629 /* The windows only know their own size: keep the layout from connect. */
630 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
631 return true;
632
633 std::vector<rdpMonitor> list;
634 list.reserve(_windows.size());
635 for (const auto& win : _windows)
636 {
637 auto monitor = win.second.monitor(_windows.size() == 1);
638 applyMonitorScaleOverride(monitor);
639 list.push_back(monitor);
640 }
641
642#if defined(__EMSCRIPTEN__)
643 if ((list.size() == 1) && (list.at(0).width > 0) && (list.at(0).height > 0))
644 {
645 auto split = sdl_web_monitors(list.at(0));
646 if (!split.empty())
647 list = std::move(split);
648 }
649#endif
650
651 // /monitors: subset may exclude the SDL primary. The library requires
652 // the array to mark one monitor as primary, so promote the first when
653 // none of the kept windows cover the original primary.
654 if (!list.empty() &&
655 std::none_of(list.cbegin(), list.cend(), [](const rdpMonitor& m) { return m.is_primary; }))
656 list.at(0).is_primary = true;
657
658 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
659 list.size());
660}
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 1966 of file sdl_context.cpp.

1967{
1968 return horizontal ? _wheelX : _wheelY;
1969}

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: