FreeRDP
Loading...
Searching...
No Matches
sdl_context.cpp
1
19
20#include <algorithm>
21#include <array>
22#include <cmath>
23#include <cfloat>
24
25#include "sdl_context.hpp"
26#include "sdl_config.hpp"
27#include "sdl_channels.hpp"
28#include "sdl_input_mapping.hpp"
29#include "sdl_monitor.hpp"
30#include "sdl_display_offsets.hpp"
31#include "sdl_pointer.hpp"
32#include "sdl_touch.hpp"
33#include "sdl_prefs.hpp"
34#include "sdl_utils.hpp"
35
36#include <sdl_common_utils.hpp>
37#include <scoped_guard.hpp>
38
39#include "dialogs/sdl_dialogs.hpp"
40#include "sdl_render_service.hpp"
41
42#include <freerdp/client/aad_helper.h>
43#include <freerdp/client/geometry.h>
44#include <freerdp/gdi/gdi.h>
45#include <freerdp/client/monitor.h>
46
47static constexpr auto sdl_allow_screensaver = "sdl-allow-screensaver";
48static constexpr auto sdl_connection_dialog = "sdl-connection-dialog";
49static constexpr auto sdl_info = "sdl-info";
50
51SdlContext::SdlContext(rdpContext* context)
52 : _context(context), _log(WLog_Get(CLIENT_TAG("SDL"))), _cursor(nullptr, sdl_Pointer_FreeCopy),
53 _rdpThreadRunning(false), _primary(nullptr, SDL_DestroySurface), _disp(this), _input(this),
54 _clip(this), _rail(this), _dialog(_log)
55{
56 WINPR_ASSERT(context);
57 setMetadata();
58
59 auto instance = _context->instance;
60 WINPR_ASSERT(instance);
61
62 instance->PreConnect = preConnect;
63 instance->PostConnect = postConnect;
64 instance->PostDisconnect = postDisconnect;
65 instance->PostFinalDisconnect = postFinalDisconnect;
66 instance->AuthenticateEx = sdl_authenticate_ex;
67 instance->VerifyCertificateEx = sdl_verify_certificate_ex;
68 instance->VerifyChangedCertificateEx = sdl_verify_changed_certificate_ex;
69 instance->LogonErrorInfo = sdl_logon_error_info;
70 instance->PresentGatewayMessage = sdl_present_gateway_message;
71 instance->ChooseSmartcard = sdl_choose_smartcard;
72 instance->RetryDialog = sdl_retry_dialog;
73 instance->GetAccessToken = client_failsafe_get_access_token;
74
75 /* TODO: Client display set up */
76
77 _args.push_back({ sdl_allow_screensaver, COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse,
78 nullptr, -1, nullptr,
79 "Allow local screensaver to activate (default: on for RemoteApp)" });
80 /* BoolValueTrue does not compile in C++, any non null default means on */
81 _args.push_back({ sdl_connection_dialog, COMMAND_LINE_VALUE_BOOL, nullptr, "on", nullptr, -1,
82 nullptr, "the connection dialog with progress and errors" });
83 _args.push_back({ sdl_info, COMMAND_LINE_VALUE_BOOL, nullptr, BoolValueFalse, nullptr, -1,
84 nullptr,
85 "the stats and info overlay from the start (its hotkey SDL_Info, default "
86 "<modifier>+I, shows and hides it)" });
87
88 /* Push a null element used as abort when iterating the array */
89 _args.push_back({ nullptr, 0, nullptr, nullptr, nullptr, -1, nullptr, nullptr });
90
91 const WINDOW_INFO_SOURCE source = { this, windowInfoGet, windowInfoSessionType };
92 _context->windowInfoService = freerdp_client_window_info_service_new(&source);
93 if (!_context->windowInfoService)
94 WLog_Print(_log, WLOG_WARN, "no window info service: channels won't know our windows");
95 _context->bitmapRenderService = sdl_render_service_new(this);
96 if (!_context->bitmapRenderService)
97 WLog_Print(_log, WLOG_WARN, "no bitmap render service: no redirected video");
98}
99
100SdlContext::~SdlContext()
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}
124
125std::optional<bool> SdlContext::allowScreenSaver() const
126{
127 return _allowScreenSaver;
128}
129
130void SdlContext::setHasCursor(bool val)
131{
132 this->_cursor_visible = val;
133}
134
135bool SdlContext::hasCursor() const
136{
137 return _cursor_visible;
138}
139
140void SdlContext::setMetadata()
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}
159
160int SdlContext::start()
161{
162 _thread = std::thread(rdpThreadRun, this);
163 return 0;
164}
165
166int SdlContext::join()
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}
177
178void SdlContext::cleanup()
179{
180 std::unique_lock lock(_critical);
181 _windows.clear();
182 _dialog.destroy();
183 _primary.reset();
184}
185
186bool SdlContext::shallAbort(bool ignoreDialogs)
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}
199
200/* Called before a connection is established.
201 * Set all configuration options to support and load channels here. */
202BOOL SdlContext::preConnect(freerdp* instance)
203{
204 WINPR_ASSERT(instance);
205 WINPR_ASSERT(instance->context);
206
207 auto sdl = get_context(instance->context);
208
209 auto settings = instance->context->settings;
210 WINPR_ASSERT(settings);
211
212 if (!freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, TRUE))
213 return FALSE;
214
215 /* Optional OS identifier sent to server */
216 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNIX))
217 return FALSE;
218 if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_SDL))
219 return FALSE;
220 /* OrderSupport is initialized at this point.
221 * Only override it if you plan to implement custom order
222 * callbacks or deactivate certain features. */
223 /* Register the channel listeners.
224 * They are required to set up / tear down channels if they are loaded. */
225 if (PubSub_SubscribeChannelConnected(instance->context->pubSub,
226 sdl_OnChannelConnectedEventHandler) < 0)
227 return FALSE;
228 if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
229 sdl_OnChannelDisconnectedEventHandler) < 0)
230 return FALSE;
231 if (PubSub_SubscribeUserNotification(instance->context->pubSub,
232 sdl_OnUserNotificationEventHandler) < 0)
233 return FALSE;
234
235 if (!freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
236 {
237 UINT32 maxWidth = 0;
238 UINT32 maxHeight = 0;
239
240 if (!sdl_detect_monitors(sdl, &maxWidth, &maxHeight))
241 return FALSE;
242
243 /* The server takes the scale of a single monitor from the core data only, so put the
244 * display scale there too. Otherwise the session starts at 100% and is redone once the
245 * display channel sends the layout.
246 * Only when the session covers whole displays: a window of a fixed /size is sized in
247 * pixels, so at the display's scale everything in it would be twice as big. */
248 const auto overrides = freerdp_settings_get_uint64(settings, FreeRDP_MonitorOverrideFlags);
249 const bool coversDisplays = freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) ||
250 freerdp_settings_get_bool(settings, FreeRDP_UseMultimon);
251 if (coversDisplays && ((overrides & FREERDP_MONITOR_OVERRIDE_DESKTOP_SCALE) == 0) &&
252 !freerdp_settings_get_bool(settings, FreeRDP_SmartSizing))
253 {
254 UINT32 scale = 0;
255 for (UINT32 x = 0; x < freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount); x++)
256 {
257 auto monitor = static_cast<const rdpMonitor*>(
258 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x));
259 if (monitor && monitor->is_primary)
260 scale = monitor->attributes.desktopScaleFactor;
261 }
262 if ((scale == 0) && !sdl->monitorIds().empty())
263 {
264 auto monitor = sdl->getDisplay(sdl->monitorIds().front());
265 sdl->applyMonitorScaleOverride(monitor);
266 scale = monitor.attributes.desktopScaleFactor;
267 }
268 if ((scale >= 100) && (scale <= 500))
269 {
270 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopScaleFactor, scale))
271 return FALSE;
272 }
273
274 /* With /multimon the server also takes each monitor's own scale from the monitor
275 * attributes ([MS-RDPBCGR] 2.2.1.3.10), unless an override forces one value on all. */
276 if ((overrides == 0) &&
277 !freerdp_settings_set_bool(settings, FreeRDP_HasMonitorAttributes, TRUE))
278 return FALSE;
279 }
280
281 if ((maxWidth != 0) && (maxHeight != 0) &&
282 !freerdp_settings_get_bool(settings, FreeRDP_SmartSizing))
283 {
284 WLog_Print(sdl->getWLog(), WLOG_INFO, "Update size to %ux%u", maxWidth, maxHeight);
285 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, maxWidth))
286 return FALSE;
287 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, maxHeight))
288 return FALSE;
289 }
290
295
296 const uint32_t sw = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth);
297 const uint32_t sh = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight);
298 const BOOL sm = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
299 if (sm && (sw > 0) && (sh > 0))
300 {
301 const BOOL mm = freerdp_settings_get_bool(settings, FreeRDP_UseMultimon);
302 if (mm)
303 WLog_Print(sdl->getWLog(), WLOG_WARN,
304 "/smart-sizing and /multimon are currently not supported, ignoring "
305 "/smart-sizing!");
306 else
307 {
308 sdl->_windowWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
309 sdl->_windowHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
310
311 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, sw))
312 return FALSE;
313 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, sh))
314 return FALSE;
315 }
316 }
317 }
318 else
319 {
320 /* Check +auth-only has a username and password. */
321 if (!freerdp_settings_get_string(settings, FreeRDP_Password))
322 {
323 WLog_Print(sdl->getWLog(), WLOG_INFO,
324 "auth-only, but no password set. Please provide one.");
325 return FALSE;
326 }
327
328 if (!freerdp_settings_set_bool(settings, FreeRDP_DeactivateClientDecoding, TRUE))
329 return FALSE;
330
331 WLog_Print(sdl->getWLog(), WLOG_INFO, "Authentication only. Don't connect SDL.");
332 }
333
334 if (!sdl->getInputChannelContext().initialize())
335 return FALSE;
336
337 sdl->_credentialsRead = false;
338
339 /* Settings are consistent at this point, the dialog can be created. */
340 auto prefs = SdlPref::instance();
341 auto dialog = prefs->get_bool("SDL_ConnectionDialog", true);
342 if (sdl->_connectionDialog && prefs->is_commandline_override_allowed())
343 dialog = *sdl->_connectionDialog;
344 if (dialog && !freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
345 {
346 sdl->getDialog().create(instance->context);
347 /* Name the server as the session window will (/t), when one was given. Through a
348 * local proxy the server name is only the proxy's address. */
349 const char* title = freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
350 if (!title || (strlen(title) == 0))
351 title = freerdp_settings_get_server_name(settings);
352 sdl->getDialog().setTitle("Connecting to '%s'", title);
353 sdl->getDialog().showInfo("The connection is being established\n\nPlease wait...");
354 }
355
356 /* TODO: Any code your client requires */
357 return TRUE;
358}
359
360/* Called after a RDP connection was successfully established.
361 * Settings might have changed during negotiation of client / server feature
362 * support.
363 *
364 * Set up local framebuffers and paing callbacks.
365 * If required, register pointer callbacks to change the local mouse cursor
366 * when hovering over the RDP window
367 */
368BOOL SdlContext::postConnect(freerdp* instance)
369{
370 WINPR_ASSERT(instance);
371
372 auto context = instance->context;
373 WINPR_ASSERT(context);
374
375 auto sdl = get_context(context);
376
377 // Retry was successful, discard dialog
378 sdl->getDialog().show(false);
379
380 if (freerdp_settings_get_bool(context->settings, FreeRDP_AuthenticationOnly))
381 {
382 /* Check +auth-only has a username and password. */
383 if (!freerdp_settings_get_string(context->settings, FreeRDP_Password))
384 {
385 WLog_Print(sdl->getWLog(), WLOG_INFO,
386 "auth-only, but no password set. Please provide one.");
387 return FALSE;
388 }
389
390 WLog_Print(sdl->getWLog(), WLOG_INFO, "Authentication only. Don't connect to X.");
391 return TRUE;
392 }
393
394 if (!sdl->waitForWindowsCreated())
395 return FALSE;
396
397 sdl->_sdlPixelFormat = SDL_PIXELFORMAT_BGRA32;
398 if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
399 return FALSE;
400
401 if (!sdl->createPrimary())
402 return FALSE;
403
404 if (!sdl_register_pointer(instance->context->graphics))
405 return FALSE;
406
407 WINPR_ASSERT(context->update);
408
409 context->update->BeginPaint = beginPaint;
410 context->update->EndPaint = endPaint;
411 context->update->PlaySound = playSound;
412 context->update->DesktopResize = desktopResize;
413 context->update->SetKeyboardIndicators = sdlInput::keyboard_set_indicators;
414 context->update->SetKeyboardImeStatus = sdlInput::keyboard_set_ime_status;
415
416 if (!sdl->setResizeable(false))
417 return FALSE;
418 if (!sdl->setFullscreen(freerdp_settings_get_bool(context->settings, FreeRDP_Fullscreen) ||
419 freerdp_settings_get_bool(context->settings, FreeRDP_UseMultimon),
420 true))
421 return FALSE;
422 sdl->setConnected(true);
423 /* also after a reconnect: the overlay's rates and totals are this connection's */
424 return sdl->_overlay.connected();
425}
426
427/* This function is called whether a session ends by failure or success.
428 * Clean up everything allocated by pre_connect and post_connect.
429 */
430void SdlContext::postDisconnect(freerdp* instance)
431{
432 if (!instance)
433 return;
434
435 if (!instance->context)
436 return;
437
438 auto sdl = get_context(instance->context);
439 sdl->setConnected(false);
440
441 gdi_free(instance);
442}
443
444void SdlContext::postFinalDisconnect(freerdp* instance)
445{
446 if (!instance)
447 return;
448
449 if (!instance->context)
450 return;
451
452 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
453 sdl_OnChannelConnectedEventHandler);
454 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
455 sdl_OnChannelDisconnectedEventHandler);
456 PubSub_UnsubscribeUserNotification(instance->context->pubSub,
457 sdl_OnUserNotificationEventHandler);
458}
459
460/* Create a SDL surface from the GDI buffer */
461bool SdlContext::createPrimary()
462{
463 auto gdi = context()->gdi;
464 WINPR_ASSERT(gdi);
465
466 _primary = SDLSurfacePtr(
467 SDL_CreateSurfaceFrom(static_cast<int>(gdi->width), static_cast<int>(gdi->height),
468 pixelFormat(), gdi->primary_buffer, static_cast<int>(gdi->stride)),
469 SDL_DestroySurface);
470 if (!_primary)
471 return false;
472
473 SDL_SetSurfaceBlendMode(_primary.get(), SDL_BLENDMODE_NONE);
474 SDL_Rect surfaceRect = { 0, 0, gdi->width, gdi->height };
475 SDL_FillSurfaceRect(_primary.get(), &surfaceRect,
476 SDL_MapSurfaceRGBA(_primary.get(), 0, 0, 0, 0xff));
477
478 return true;
479}
480
481bool SdlContext::createWindows()
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}
579
580#if defined(__EMSCRIPTEN__)
581/* in sdl_monitors_emscripten.js */
582extern "C" int freerdp_web_monitors_js(int32_t* edges, int max);
583
584/* A browser has one canvas, so one window. The page may show it across several screens and
585 * split it into monitors (sdl_monitors_emscripten.js): the server then places its windows,
586 * panels and maximized windows on each, as on separate physical screens. canvas is the
587 * window's monitor; returns the monitors it is split into, or none. */
588static std::vector<rdpMonitor> sdl_web_monitors(const rdpMonitor& canvas)
589{
590 constexpr int max = 16;
591 std::array<int32_t, 5 * max> edges{};
592 const auto n = freerdp_web_monitors_js(edges.data(), max);
593 if ((n < 2) || (n > max))
594 return {};
595
596 const auto at = [](int32_t edge, int32_t size)
597 { return static_cast<INT32>(static_cast<int64_t>(edge) * size / 10000); };
598 std::vector<rdpMonitor> list;
599 for (int i = 0; i < n; i++)
600 {
601 const int32_t* e = &edges.at(5 * static_cast<size_t>(i));
602 const auto left = at(e[0], canvas.width);
603 const auto top = at(e[1], canvas.height);
604 const auto right = at(e[2], canvas.width);
605 const auto bottom = at(e[3], canvas.height);
606 if ((right <= left) || (bottom <= top))
607 return {};
608
609 rdpMonitor m = canvas;
610 m.x = left;
611 m.y = top;
612 m.width = right - left;
613 m.height = bottom - top;
614 m.is_primary = (e[4] != 0);
615 m.attributes.physicalWidth =
616 static_cast<UINT32>(static_cast<uint64_t>(canvas.attributes.physicalWidth) *
617 static_cast<UINT32>(m.width) / static_cast<UINT32>(canvas.width));
618 m.attributes.physicalHeight =
619 static_cast<UINT32>(static_cast<uint64_t>(canvas.attributes.physicalHeight) *
620 static_cast<UINT32>(m.height) / static_cast<UINT32>(canvas.height));
621 list.push_back(m);
622 }
623 return list;
624}
625#endif
626
627bool SdlContext::updateWindowList()
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}
661
662bool SdlContext::updateWindow(SDL_WindowID id)
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}
681
682std::string SdlContext::windowTitle() const
683{
684 const char* prefix = "FreeRDP:";
685
686 const auto windowTitle = freerdp_settings_get_string(context()->settings, FreeRDP_WindowTitle);
687 if (windowTitle)
688 return windowTitle;
689
690 const auto name = freerdp_settings_get_server_name(context()->settings);
691 const auto port = freerdp_settings_get_uint32(context()->settings, FreeRDP_ServerPort);
692 const auto addPort = (port != 3389);
693
694 std::stringstream ss;
695 ss << prefix << " " << name;
696
697 if (addPort)
698 ss << ":" << port;
699
700 return ss.str();
701}
702
703bool SdlContext::waitForWindowsCreated()
704{
705 {
706 std::unique_lock<CriticalSection> lock(_critical);
707 _windowsCreatedEvent.clear();
708 if (!sdl_push_user_event(SDL_EVENT_USER_CREATE_WINDOWS, this))
709 return false;
710 }
711
712 HANDLE handles[] = { _windowsCreatedEvent.handle(), freerdp_abort_event(context()) };
713
714 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
715 switch (rc)
716 {
717 case WAIT_OBJECT_0:
718 return true;
719 default:
720 return false;
721 }
722}
723
724/* This function is called when the library completed composing a new
725 * frame. Read out the changed areas and blit them to your output device.
726 * The image buffer will have the format specified by gdi_init
727 */
728BOOL SdlContext::endPaint(rdpContext* context)
729{
730 auto sdl = get_context(context);
731 WINPR_ASSERT(sdl);
732
733 auto gdi = context->gdi;
734 WINPR_ASSERT(gdi);
735 WINPR_ASSERT(gdi->primary);
736
737 HGDI_DC hdc = gdi->primary->hdc;
738 WINPR_ASSERT(hdc);
739 if (!hdc->hwnd)
740 return TRUE;
741
742 HGDI_WND hwnd = hdc->hwnd;
743 WINPR_ASSERT(hwnd->invalid || (hwnd->ninvalid == 0));
744
745 if (hwnd->invalid->null)
746 return TRUE;
747
748 WINPR_ASSERT(hwnd->invalid);
749 if (gdi->suppressOutput || hwnd->invalid->null)
750 return TRUE;
751
752 const INT32 ninvalid = hwnd->ninvalid;
753 const GDI_RGN* cinvalid = hwnd->cinvalid;
754
755 if (ninvalid < 1)
756 return TRUE;
757
758 std::vector<SDL_Rect> rects;
759 for (INT32 x = 0; x < ninvalid; x++)
760 {
761 auto& rgn = cinvalid[x];
762 rects.push_back({ rgn.x, rgn.y, rgn.w, rgn.h });
763 }
764
765 sdl->push(std::move(rects));
766 return sdl_push_user_event(SDL_EVENT_USER_UPDATE);
767}
768
769void SdlContext::sdl_client_cleanup(int exit_code, const std::string& error_msg)
770{
771 rdpSettings* settings = context()->settings;
772 WINPR_ASSERT(settings);
773
774 _rdpThreadRunning = false;
775 bool showError = false;
776 if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
777 WLog_Print(getWLog(), WLOG_INFO, "Authentication only, exit status %s [%" PRId32 "]",
778 sdl::error::exitCodeToTag(exit_code), exit_code);
779 else
780 {
781 switch (exit_code)
782 {
783 case sdl::error::SUCCESS:
784 case sdl::error::DISCONNECT:
785 case sdl::error::LOGOFF:
786 case sdl::error::DISCONNECT_BY_USER:
787 case sdl::error::CONNECT_CANCELLED:
788 break;
789 default:
790 {
791 showError = true;
792 getDialog().showError(error_msg);
793 }
794 break;
795 }
796 }
797
798 if (!showError)
799 getDialog().show(false);
800
801 _exitCode = exit_code;
802 std::ignore = sdl_push_user_event(SDL_EVENT_USER_QUIT);
803 SDL_CleanupTLS();
804}
805
806int SdlContext::sdl_client_thread_connect(std::string& error_msg)
807{
808 auto instance = context()->instance;
809 WINPR_ASSERT(instance);
810
811 _rdpThreadRunning = true;
812 BOOL rc = freerdp_connect(instance);
813
814 rdpSettings* settings = context()->settings;
815 WINPR_ASSERT(settings);
816
817 int exit_code = sdl::error::SUCCESS;
818 if (!rc)
819 {
820 UINT32 error = freerdp_get_last_error(context());
821 exit_code = sdl::error::errorToExitCode(error);
822 }
823
824 if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
825 {
826 DWORD code = freerdp_get_last_error(context());
827 freerdp_abort_connect_context(context());
828 WLog_Print(getWLog(), WLOG_ERROR, "Authentication only, %s [0x%08" PRIx32 "] %s",
829 freerdp_get_last_error_name(code), code, freerdp_get_last_error_string(code));
830 return exit_code;
831 }
832
833 if (!rc)
834 {
835 DWORD code = freerdp_error_info(instance);
836 if (exit_code == sdl::error::SUCCESS)
837 {
838 char* msg = nullptr;
839 size_t len = 0;
840 exit_code = error_info_to_error(&code, &msg, &len);
841 if (msg)
842 error_msg = msg;
843 free(msg);
844 }
845
846 auto last = freerdp_get_last_error(context());
847 if (error_msg.empty())
848 {
849 char* msg = nullptr;
850 size_t len = 0;
851 winpr_asprintf(&msg, &len, "%s [0x%08" PRIx32 "]\n%s",
852 freerdp_get_last_error_name(last), last,
853 freerdp_get_last_error_string(last));
854 if (msg)
855 error_msg = msg;
856 free(msg);
857 }
858
859 if (exit_code == sdl::error::SUCCESS)
860 {
861 if (last == FREERDP_ERROR_AUTHENTICATION_FAILED)
862 exit_code = sdl::error::AUTH_FAILURE;
863 else if (code == ERRINFO_SUCCESS)
864 exit_code = sdl::error::CONN_FAILED;
865 }
866
867 getDialog().show(false);
868 }
869
870 return exit_code;
871}
872
873int SdlContext::sdl_client_thread_run(std::string& error_msg)
874{
875 auto instance = context()->instance;
876 WINPR_ASSERT(instance);
877
878 int exit_code = sdl::error::SUCCESS;
879 while (!freerdp_shall_disconnect_context(context()))
880 {
881 HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {};
882 /*
883 * win8 and server 2k12 seem to have some timing issue/race condition
884 * when a initial sync request is send to sync the keyboard indicators
885 * sending the sync event twice fixed this problem
886 */
887 if (freerdp_focus_required(instance))
888 {
889 auto ctx = get_context(context());
890 WINPR_ASSERT(ctx);
891
892 auto& input = ctx->getInputChannelContext();
893 if (!input.keyboard_focus_in())
894 break;
895 if (!input.keyboard_focus_in())
896 break;
897 }
898
899 const DWORD nCount = freerdp_get_event_handles(context(), handles, ARRAYSIZE(handles));
900
901 if (nCount == 0)
902 {
903 WLog_Print(getWLog(), WLOG_ERROR, "freerdp_get_event_handles failed");
904 break;
905 }
906
907 const DWORD status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
908
909 if (status == WAIT_FAILED)
910 {
911 WLog_Print(getWLog(), WLOG_ERROR, "WaitForMultipleObjects WAIT_FAILED");
912 break;
913 }
914
915 if (!freerdp_check_event_handles(context()))
916 {
917 if (client_auto_reconnect(instance))
918 {
919 // Retry was successful, discard dialog
920 getDialog().show(false);
921 continue;
922 }
923 else
924 {
925 /*
926 * Indicate an unsuccessful connection attempt if reconnect
927 * did not succeed and no other error was specified.
928 */
929 if (freerdp_error_info(instance) == 0)
930 exit_code = sdl::error::errorToExitCode(freerdp_get_last_error(context()));
931 }
932
933 if (freerdp_get_last_error(context()) == FREERDP_ERROR_SUCCESS)
934 WLog_Print(getWLog(), WLOG_ERROR, "WaitForMultipleObjects failed with %" PRIu32 "",
935 status);
936 if (freerdp_get_last_error(context()) == FREERDP_ERROR_SUCCESS)
937 WLog_Print(getWLog(), WLOG_ERROR, "Failed to check FreeRDP event handles");
938 break;
939 }
940 }
941
942 if (exit_code == sdl::error::SUCCESS)
943 {
944 DWORD code = 0;
945 {
946 char* emsg = nullptr;
947 size_t elen = 0;
948 exit_code = error_info_to_error(&code, &emsg, &elen);
949 if (emsg)
950 error_msg = emsg;
951 free(emsg);
952 }
953
954 if ((code == ERRINFO_LOGOFF_BY_USER) &&
955 (freerdp_get_disconnect_ultimatum(context()) == Disconnect_Ultimatum_user_requested))
956 {
957 const char* msg = "Error info says user did not initiate but disconnect ultimatum says "
958 "they did; treat this as a user logoff";
959
960 char* emsg = nullptr;
961 size_t elen = 0;
962 winpr_asprintf(&emsg, &elen, "%s", msg);
963 if (emsg)
964 error_msg = emsg;
965 free(emsg);
966
967 /* This situation might be limited to Windows XP. */
968 WLog_Print(getWLog(), WLOG_INFO, "%s", msg);
969 exit_code = sdl::error::LOGOFF;
970 }
971 }
972
973 if ((exit_code != sdl::error::SUCCESS) && error_msg.empty())
974 {
975 const auto last = freerdp_get_last_error(context());
976 char* msg = nullptr;
977 size_t len = 0;
978 winpr_asprintf(&msg, &len, "%s [0x%08" PRIx32 "]\n%s", freerdp_get_last_error_name(last),
979 last, freerdp_get_last_error_string(last));
980 if (msg)
981 error_msg = msg;
982 free(msg);
983 }
984
985 freerdp_disconnect(instance);
986
987 return exit_code;
988}
989
990/* RDP main loop.
991 * Connects RDP, loops while running and handles event and dispatch, cleans up
992 * after the connection ends. */
993DWORD SdlContext::rdpThreadRun(SdlContext* sdl)
994{
995 WINPR_ASSERT(sdl);
996
997 std::string error_msg;
998 int exit_code = sdl->sdl_client_thread_connect(error_msg);
999 if (exit_code == sdl::error::SUCCESS)
1000 exit_code = sdl->sdl_client_thread_run(error_msg);
1001 sdl->sdl_client_cleanup(exit_code, error_msg);
1002
1003 return static_cast<DWORD>(exit_code);
1004}
1005
1006int SdlContext::error_info_to_error(DWORD* pcode, char** msg, size_t* len) const
1007{
1008 const DWORD code = freerdp_error_info(context()->instance);
1009 const char* name = freerdp_get_error_info_name(code);
1010 const char* str = freerdp_get_error_info_string(code);
1011 const int exit_code = sdl::error::errorToExitCode(code);
1012
1013 winpr_asprintf(msg, len, "Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32 "]: %s",
1014 sdl::error::errorToExitCodeTag(code), name, code, str);
1015 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%s", *msg);
1016 if (pcode)
1017 *pcode = code;
1018 return exit_code;
1019}
1020
1021void SdlContext::updateMonitorDataFromOffsets()
1022{
1023 for (auto& entry : _windows)
1024 {
1025 const auto& monitor = _displays.at(entry.first);
1026 entry.second.setMonitor(monitor);
1027 }
1028}
1029
1030bool SdlContext::drawToWindow(SdlWindow& window, const std::vector<SDL_Rect>& rects)
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}
1073
1074SdlWindow* SdlContext::overlayWindow()
1075{
1076 /* RemoteApp windows are the server's, so v1 has no overlay there */
1077 if (_rail.enabled() || _windows.empty())
1078 return nullptr;
1079 return &_windows.begin()->second;
1080}
1081
1083{
1084 return showOverlay(!_overlay.visible());
1085}
1086
1087bool SdlContext::showOverlay(bool on)
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}
1100
1101bool SdlContext::updateOverlay()
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}
1115
1116bool SdlContext::minimizeAllWindows()
1117{
1118 for (auto& w : _windows)
1119 w.second.minimize();
1120 return true;
1121}
1122
1123int SdlContext::exitCode() const
1124{
1125 return _exitCode;
1126}
1127
1128SDL_PixelFormat SdlContext::pixelFormat() const
1129{
1130 return _sdlPixelFormat;
1131}
1132
1133bool SdlContext::addDisplayWindow(SDL_DisplayID id)
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}
1142
1143bool SdlContext::removeDisplayWindow(SDL_DisplayID id)
1144{
1145 for (auto& w : _windows)
1146 {
1147 if (w.second.displayIndex() == id)
1148 _windows.erase(w.first);
1149 }
1150 return true;
1151}
1152
1153bool SdlContext::detectDisplays()
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}
1177
1178rdpMonitor SdlContext::getDisplay(SDL_DisplayID id) const
1179{
1180 return _displays.at(id);
1181}
1182
1183std::vector<SDL_DisplayID> SdlContext::getDisplayIds() const
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}
1193
1194const SdlWindow* SdlContext::getWindowForId(SDL_WindowID id) const
1195{
1196 auto it = _windows.find(id);
1197 if (it == _windows.end())
1198 return nullptr;
1199 return &it->second;
1200}
1201
1202SdlWindow* SdlContext::getWindowForId(SDL_WindowID id)
1203{
1204 auto it = _windows.find(id);
1205 if (it == _windows.end())
1206 return nullptr;
1207 return &it->second;
1208}
1209
1210bool SdlContext::allWindowsHidden() const
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}
1219
1220SdlWindow* SdlContext::getFirstWindow()
1221{
1222 if (_windows.empty())
1223 return nullptr;
1224 return &_windows.begin()->second;
1225}
1226
1227bool SdlContext::setNotification(const std::string& message)
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}
1237
1238void SdlContext::updateNotification()
1239{
1240 std::string message;
1241 {
1242 std::scoped_lock lock(_notificationLock);
1243 message = _notification;
1244 }
1245
1246 if (message.empty())
1247 {
1248 /* Restore the title the window had before the first notification. */
1249 if (_notificationWindow != 0)
1250 {
1251 auto window = SDL_GetWindowFromID(_notificationWindow);
1252 if (window)
1253 std::ignore = SDL_SetWindowTitle(window, _notificationSavedTitle.c_str());
1254 }
1255 _notificationWindow = 0;
1256 _notificationSavedTitle.clear();
1257 return;
1258 }
1259
1260 /* Save the title only for the first notification: a following one replaces the
1261 * message, the saved title stays the one to restore. */
1262 if (_notificationWindow == 0)
1263 {
1264 auto window = getFirstWindow();
1265 if (!window)
1266 return;
1267
1268 auto sdlWindow = window->window();
1269 _notificationWindow = SDL_GetWindowID(sdlWindow);
1270 _notificationSavedTitle = SDL_GetWindowTitle(sdlWindow);
1271 }
1272
1273 auto window = SDL_GetWindowFromID(_notificationWindow);
1274 if (!window)
1275 {
1276 _notificationWindow = 0;
1277 _notificationSavedTitle.clear();
1278 return;
1279 }
1280
1281 const auto title = _notificationSavedTitle + " - " + message;
1282 std::ignore = SDL_SetWindowTitle(window, title.c_str());
1283}
1284
1285sdlDispContext& SdlContext::getDisplayChannelContext()
1286{
1287 return _disp;
1288}
1289
1290sdlInput& SdlContext::getInputChannelContext()
1291{
1292 return _input;
1293}
1294
1295sdlClip& SdlContext::getClipboardChannelContext()
1296{
1297 return _clip;
1298}
1299
1300SdlRail& SdlContext::getRailChannelContext()
1301{
1302 return _rail;
1303}
1304
1305SdlConnectionDialogWrapper& SdlContext::getDialog()
1306{
1307 return _dialog;
1308}
1309
1310wLog* SdlContext::getWLog()
1311{
1312 return _log;
1313}
1314
1315bool SdlContext::moveMouseTo(const SDL_FPoint& pos)
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}
1326
1327static bool onWindowEdge(SDL_WindowID id, float x, float y)
1328{
1329 int w = 0;
1330 int h = 0;
1331 auto* window = SDL_GetWindowFromID(id);
1332 if (!window || !SDL_GetWindowSize(window, &w, &h))
1333 return false;
1334 return (x <= 0.0f) || (y <= 0.0f) || (x >= static_cast<float>(w - 1)) ||
1335 (y >= static_cast<float>(h - 1));
1336}
1337
1338bool SdlContext::handleEvent(const SDL_MouseMotionEvent& ev)
1339{
1340 SDL_Event copy{};
1341 copy.motion = ev;
1342 /* SDL follows a release outside the window with a motion clamped to its edge: drop it. */
1343 if (_rail.enabled() && (ev.state == 0) && (ev.windowID == _lastRelease.window) &&
1344 (ev.timestamp - _lastRelease.time < SDL_MS_TO_NS(2)) &&
1345 onWindowEdge(ev.windowID, ev.x, ev.y))
1346 return true;
1347 /* WM owns the drag (#12447); backstop: button released but button-up swallowed by grab. */
1348 if (_rail.enabled() && _rail.suppressServerMotion(ev.windowID))
1349 {
1350 if (!(SDL_GetGlobalMouseState(nullptr, nullptr) & SDL_BUTTON_LMASK))
1351 _rail.completeLocalMoveIfPending();
1352 return true;
1353 }
1354 SDL_FPoint pos{};
1355 SDL_FPoint delta{ ev.xrel, ev.yrel };
1356 if (!screenToRdp(ev.windowID, { ev.x, ev.y }, pos, &delta))
1357 return true; /* Event for an untracked window (e.g. closed dialog) */
1358 copy.motion.x = pos.x;
1359 copy.motion.y = pos.y;
1360 copy.motion.xrel = delta.x;
1361 copy.motion.yrel = delta.y;
1362
1363 if (_rail.enabled() && _rail.ownsWindow(ev.windowID))
1364 {
1365 _lastMotion = { ev.windowID, { ev.x, ev.y }, pos, _rail.pointerEpoch() };
1366 _rail.noteServerPointer(pos.x, pos.y);
1367 }
1368 return SdlTouch::handleEvent(this, copy.motion);
1369}
1370
1371bool SdlContext::handleEvent(const SDL_MouseWheelEvent& ev)
1372{
1373 SDL_Event copy{};
1374 copy.wheel = ev;
1375 SDL_FPoint pos{};
1376 if (!screenToRdp(ev.windowID, { ev.mouse_x, ev.mouse_y }, pos))
1377 return true;
1378 copy.wheel.mouse_x = pos.x;
1379 copy.wheel.mouse_y = pos.y;
1380 return SdlTouch::handleEvent(this, copy.wheel);
1381}
1382
1383bool SdlContext::handleEvent(const SDL_WindowEvent& ev)
1384{
1385 if (!getDisplayChannelContext().handleEvent(ev))
1386 return false;
1387
1388 auto window = getWindowForId(ev.windowID);
1389 if (!window)
1390 {
1391 /* RAIL windows aren't in _windows; handle their events here. */
1392 if (_rail.enabled() && _rail.ownsWindow(ev.windowID))
1393 {
1394 switch (ev.type)
1395 {
1396 case SDL_EVENT_WINDOW_MOUSE_ENTER:
1397 /* Re-enter fires on move-grab end. */
1398 if (!(SDL_GetGlobalMouseState(nullptr, nullptr) & SDL_BUTTON_LMASK))
1399 _rail.completeLocalMoveIfPending(); /* X11 */
1400 _rail.completeWaylandResize(); /* Wayland: compositor grab ended */
1401 /* Restore the cursor or the pointer stays hidden over RemoteApp windows. */
1402 return restoreCursor();
1403 case SDL_EVENT_WINDOW_MOUSE_LEAVE:
1404 /* Compositor took the pointer for the pending Wayland resize grab. */
1405 _rail.noteResizeGrab(ev.windowID);
1406 return true;
1407 case SDL_EVENT_WINDOW_EXPOSED:
1408 /* Force repaint for exposed windows; skip during local drag to avoid redundant
1409 * frames. */
1410 if (!_rail.dragActive(ev.windowID))
1411 _rail.invalidateWindow(ev.windowID);
1412 return true;
1413 case SDL_EVENT_WINDOW_MAXIMIZED:
1414 /* Maximize must complete move first. */
1415 _rail.completeLocalMoveIfPending();
1416 _rail.handleMaximized(ev.windowID);
1417 return true;
1418 case SDL_EVENT_WINDOW_MINIMIZED:
1419 _rail.handleMinimized(ev.windowID);
1420 return true;
1421 case SDL_EVENT_WINDOW_RESTORED:
1422 _rail.handleRestored(ev.windowID);
1423 return true;
1424 case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
1425 /* Send SC_CLOSE, don't abort the session. */
1426 _rail.handleClose(ev.windowID);
1427 return true;
1428 case SDL_EVENT_WINDOW_FOCUS_GAINED:
1429 _rail.handleFocus(ev.windowID, true);
1430 return true;
1431 case SDL_EVENT_WINDOW_FOCUS_LOST:
1432 _rail.handleFocus(ev.windowID, false);
1433 return true;
1434 case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
1435 _rail.handleDisplayChanged(ev.windowID, static_cast<SDL_DisplayID>(ev.data1));
1436 return true;
1437 case SDL_EVENT_WINDOW_MOVED:
1438 _rail.notePopupMoved(ev.windowID);
1439 if (!_rail.dragActive(ev.windowID))
1440 _rail.syncGeometry(ev.windowID);
1441 return true;
1442 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
1443 /* No server frame during the drag: repaint synchronously each configure step;
1444 * also report the new size to catch a compositor snap/tile. */
1445 _rail.noteDragResize(ev.windowID, ev.data1, ev.data2);
1446 _rail.syncGeometry(ev.windowID);
1447 _rail.noteResizeGrab(ev.windowID);
1448 std::ignore = drawToWindows({});
1449 return true;
1450 default:
1451 break;
1452 }
1453 }
1454 return true;
1455 }
1456
1457 {
1458 const auto& r = window->rect();
1459 const auto& b = window->bounds();
1460 const auto& scale = window->scale();
1461 const auto& orientation = window->orientation();
1462 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
1463 "%s: [%u] %dx%d-%dx%d {%dx%d-%dx%d}{scale=%f,orientation=%s}",
1464 sdl::utils::toString(ev.type).c_str(), ev.windowID, r.x, r.y, r.w, r.h, b.x,
1465 b.y, b.w, b.h, static_cast<double>(scale),
1466 sdl::utils::toString(orientation).c_str());
1467 }
1468
1469 switch (ev.type)
1470 {
1471 case SDL_EVENT_WINDOW_MOUSE_ENTER:
1472 return restoreCursor();
1473 case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
1474 if (!resizeToScale(window))
1475 return false;
1477 if (isConnected())
1478 {
1479 if (!window->fill())
1480 return false;
1481 if (!drawToWindow(*window))
1482 return false;
1483 if (!restoreCursor())
1484 return false;
1485 }
1486 break;
1487 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
1488 if (!resizeToScale(window))
1489 return false;
1490 if (!window->fill())
1491 return false;
1492 if (!drawToWindow(*window))
1493 return false;
1494 if (!restoreCursor())
1495 return false;
1497 break;
1498 case SDL_EVENT_WINDOW_MOVED:
1499 {
1500 auto r = window->rect();
1501 auto id = window->id();
1502 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%u: %dx%d-%dx%d", id, r.x, r.y, r.w, r.h);
1503 }
1504 break;
1505 case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
1506 {
1507 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Window closed, terminating RDP session...");
1508 std::ignore = abortConnect();
1509 }
1510 break;
1511 default:
1512 break;
1513 }
1514 return true;
1515}
1516
1517bool SdlContext::handleEvent(const SDL_DisplayEvent& ev)
1518{
1519 if (!getDisplayChannelContext().handleEvent(ev))
1520 return false;
1521#if SDL_VERSION_ATLEAST(3, 3, 2)
1522 if (ev.type == SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED)
1523 _rail.noteUsableBoundsChanged(ev.displayID);
1524#endif
1525
1526 switch (ev.type)
1527 {
1528 case SDL_EVENT_DISPLAY_REMOVED: // Can't show details for this one...
1529 break;
1530 default:
1531 {
1532 SDL_Rect r = {};
1533 if (!SDL_GetDisplayBounds(ev.displayID, &r))
1534 return false;
1535 const auto name = SDL_GetDisplayName(ev.displayID);
1536 if (!name)
1537 return false;
1538 const auto orientation = SDL_GetCurrentDisplayOrientation(ev.displayID);
1539 const auto scale = SDL_GetDisplayContentScale(ev.displayID);
1540 const auto mode = SDL_GetCurrentDisplayMode(ev.displayID);
1541 if (!mode)
1542 return false;
1543
1544 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
1545 "%s: [%u, %s] %dx%d-%dx%d {orientation=%s, scale=%f}%s",
1546 sdl::utils::toString(ev.type).c_str(), ev.displayID, name, r.x, r.y, r.w,
1547 r.h, sdl::utils::toString(orientation).c_str(), static_cast<double>(scale),
1548 sdl::utils::toString(mode).c_str());
1549 }
1550 break;
1551 }
1552 return true;
1553}
1554
1555bool SdlContext::handleEvent(const SDL_MouseButtonEvent& ev)
1556{
1557 SDL_Event copy = {};
1558 copy.button = ev;
1559 if (_rail.enabled())
1560 {
1561 /* Suppress X11 raw button during WM op. */
1562 const bool suppress = _rail.dragActive(ev.windowID);
1563 if (ev.type == SDL_EVENT_MOUSE_BUTTON_UP)
1564 _rail.completeLocalMoveIfPending();
1565 /* Backstop for a Wayland resize whose MOUSE_ENTER completion never arrived; a fresh press
1566 * proves the old grab is over, so a no-op click grab is cancelled here too. */
1567 if (ev.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
1568 _rail.completeWaylandResize(true);
1569 /* activate the clicked window before forwarding, so the click routes to it. */
1570 if (ev.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
1571 _rail.ensureActive(ev.windowID);
1572 if (suppress)
1573 return true;
1574 if (ev.type == SDL_EVENT_MOUSE_BUTTON_UP)
1575 {
1576 _lastRelease = { ev.windowID, ev.timestamp };
1577 }
1578 }
1579
1580 SDL_FPoint pos{};
1581 if (!screenToRdp(ev.windowID, { ev.x, ev.y }, pos))
1582 return true;
1583 copy.button.x = pos.x;
1584 copy.button.y = pos.y;
1585
1586 if (_rail.enabled() && _rail.ownsWindow(ev.windowID))
1587 {
1588 /* The window may have moved since the last motion: keep the server's position. */
1589 if ((ev.windowID == _lastMotion.window) && (_lastMotion.epoch == _rail.pointerEpoch()) &&
1590 (fabsf(ev.x - _lastMotion.local.x) < FLT_EPSILON) &&
1591 (fabsf(ev.y - _lastMotion.local.y) < FLT_EPSILON))
1592 {
1593 copy.button.x = _lastMotion.server.x;
1594 copy.button.y = _lastMotion.server.y;
1595 }
1596 /* Record the forwarded left press: it is the anchor of any server modal move/size
1597 * loop this press starts (the loop moves the window by release - anchor). */
1598 if ((ev.type == SDL_EVENT_MOUSE_BUTTON_DOWN) && (ev.button == SDL_BUTTON_LEFT))
1599 _rail.noteLeftPress(copy.button.x, copy.button.y);
1600 }
1601 return SdlTouch::handleEvent(this, copy.button);
1602}
1603
1604bool SdlContext::handleEvent(const SDL_TouchFingerEvent& ev)
1605{
1606 if (!getWindowForId(ev.windowID))
1607 return true;
1608 /* Finger positions are normalized to the window size in points. */
1609 int w = 0;
1610 int h = 0;
1611 if (!SDL_GetWindowSize(SDL_GetWindowFromID(ev.windowID), &w, &h))
1612 return true;
1613 const auto fw = static_cast<float>(w);
1614 const auto fh = static_cast<float>(h);
1615 SDL_FPoint pos{};
1616 SDL_FPoint delta{ ev.dx * fw, ev.dy * fh };
1617 if (!screenToRdp(ev.windowID, { ev.x * fw, ev.y * fh }, pos, &delta))
1618 return true;
1619 SDL_Event copy{};
1620 copy.tfinger = ev;
1621 copy.tfinger.x = pos.x;
1622 copy.tfinger.y = pos.y;
1623 copy.tfinger.dx = delta.x;
1624 copy.tfinger.dy = delta.y;
1625 return SdlTouch::handleEvent(this, copy.tfinger);
1626}
1627
1628void SdlContext::addOrUpdateDisplay(SDL_DisplayID id)
1629{
1630 auto monitor = SdlWindow::query(id, false);
1631 if ((monitor.width <= 0) || (monitor.height <= 0))
1632 {
1633 WLog_Print(getWLog(), WLOG_WARN, "display %" PRIu32 " has no usable size, skipped", id);
1634 return;
1635 }
1636 _displays.emplace(id, monitor);
1637
1638 /* The logical bounds and the primary are read here, on the thread SDL display functions
1639 * must be called from; updateDisplayOffsets() also runs when the selection is set during
1640 * connect, on another thread. */
1641 _displayBounds.clear();
1642 for (const auto& entry : _displays)
1643 {
1644 SDL_Rect bounds{};
1645 std::ignore = SDL_GetDisplayBounds(entry.first, &bounds);
1646 _displayBounds.emplace(entry.first, bounds);
1647 }
1648 _primaryDisplay = SDL_GetPrimaryDisplay();
1649 updateDisplayOffsets();
1650 updateMonitorDataFromOffsets();
1651}
1652
1653void SdlContext::updateDisplayOffsets()
1654{
1655 /* Update actual display rectangles from the logical display bounds and the known pixel
1656 * width and height of each display. */
1657 _offsets.clear();
1658 for (const auto& entry : _displays)
1659 {
1660 SDL_Rect bounds{};
1661 const auto found = _displayBounds.find(entry.first);
1662 if (found != _displayBounds.end())
1663 bounds = found->second;
1664
1665 SDL_Rect pixel{};
1666 pixel.w = entry.second.width;
1667 pixel.h = entry.second.height;
1668 _offsets.emplace(entry.first, std::pair{ bounds, pixel });
1669 }
1670
1671 if (_offsets.empty())
1672 return;
1673 sdl_display_offsets::update(_offsets, _primaryDisplay, _monitorIds);
1674 for (auto& entry : _displays)
1675 {
1676 const auto& pixel = _offsets.at(entry.first).second;
1677 entry.second.x = pixel.x;
1678 entry.second.y = pixel.y;
1679 }
1680}
1681
1682void SdlContext::deleteDisplay(SDL_DisplayID id)
1683{
1684 _displays.erase(id);
1685}
1686
1687SDL_FPoint SdlContext::applyLocalScaling(const SDL_FPoint& val) const
1688{
1689 if (!useLocalScale())
1690 return val;
1691
1692 auto rval = val;
1693 rval.x *= _localScale.x;
1694 rval.y *= _localScale.y;
1695 return rval;
1696}
1697
1698bool SdlContext::screenToRdp(SDL_WindowID id, const SDL_FPoint& pos, SDL_FPoint& rpos,
1699 SDL_FPoint* delta)
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}
1714
1715SDL_Point SdlContext::inputOrigin() const
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}
1730
1731SdlInputWindow SdlContext::inputWindowGeometry(SDL_Window* window, SDL_Renderer* renderer)
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}
1751
1752std::vector<SdlInputWindow> SdlContext::inputWindows(SDL_WindowID id, const SDL_Point& origin,
1753 std::optional<size_t>& source)
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}
1782
1783SDL_FPoint SdlContext::pixelToScreen(SDL_WindowID id, const SDL_FPoint& pos)
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}
1803
1804SDL_FRect SdlContext::pixelToScreen(SDL_WindowID id, const SDL_FRect& pos, bool round)
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}
1818
1819bool SdlContext::handleEvent(const SDL_Event& ev)
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}
1885
1886COMMAND_LINE_ARGUMENT_A* SdlContext::args()
1887{
1888 return _args.data();
1889}
1890
1891size_t SdlContext::argsCount() const
1892{
1893 if (_args.size() <= 1)
1894 return 0;
1895 return _args.size() - 1;
1896}
1897
1898int SdlContext::argumentHandler(const COMMAND_LINE_ARGUMENT_A* arg, void* custom)
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}
1930
1931void SdlContext::applyMonitorScaleOverride(rdpMonitor& monitor) const
1932{
1933 freerdp_client_apply_monitor_scale(context()->settings, &monitor);
1934}
1935
1936CriticalSection& SdlContext::lock()
1937{
1938 return _critical;
1939}
1940
1941std::vector<rdpPointer*>& SdlContext::pointers()
1942{
1943 return _valid_pointers;
1944}
1945
1946bool SdlContext::contains(const rdpPointer* ptr) const
1947{
1948 for (const auto& cur : _valid_pointers)
1949 {
1950 if (cur == ptr)
1951 return true;
1952 }
1953 return false;
1954}
1955
1956bool SdlContext::credentialsRead() const
1957{
1958 return _credentialsRead;
1959}
1960
1961void SdlContext::setCredentialsRead()
1962{
1963 _credentialsRead = true;
1964}
1965
1966SdlWheelAxis& SdlContext::wheelAxis(bool horizontal)
1967{
1968 return horizontal ? _wheelX : _wheelY;
1969}
1970
1971bool SdlContext::resizeToScale(SdlWindow* window)
1972{
1973 if (freerdp_settings_get_bool(context()->settings, FreeRDP_SmartSizing))
1974 return true;
1975 if (!useLocalScale())
1976 return true;
1977 if (!window)
1978 return false;
1979 return window->resizeToScale();
1980}
1981
1982bool SdlContext::useLocalScale() const
1983{
1984 const auto ssize = freerdp_settings_get_bool(context()->settings, FreeRDP_SmartSizing);
1985 if (ssize)
1986 return true;
1987 const auto dynResize =
1988 freerdp_settings_get_bool(context()->settings, FreeRDP_DynamicResolutionUpdate);
1989 const auto fs = freerdp_settings_get_bool(context()->settings, FreeRDP_Fullscreen);
1990 const auto multimon = freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon);
1991 return !dynResize && !fs && !multimon;
1992}
1993
1994bool SdlContext::drawToWindows(const std::vector<SDL_Rect>& rects)
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}
2044
2045BOOL SdlContext::desktopResize(rdpContext* context)
2046{
2047 rdpGdi* gdi = nullptr;
2048 rdpSettings* settings = nullptr;
2049 auto sdl = get_context(context);
2050
2051 WINPR_ASSERT(sdl);
2052 WINPR_ASSERT(context);
2053
2054 settings = context->settings;
2055 WINPR_ASSERT(settings);
2056
2057 std::unique_lock lock(sdl->_critical);
2058 gdi = context->gdi;
2059 if (!gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
2060 freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
2061 return FALSE;
2062 return sdl->createPrimary();
2063}
2064
2065/* This function is called to output a System BEEP */
2066BOOL SdlContext::playSound(rdpContext* context, const PLAY_SOUND_UPDATE* play_sound)
2067{
2068 /* TODO: Implement */
2069 WINPR_UNUSED(context);
2070 WINPR_UNUSED(play_sound);
2071 return TRUE;
2072}
2073
2074/* This function is called whenever a new frame starts.
2075 * It can be used to reset invalidated areas. */
2076BOOL SdlContext::beginPaint(rdpContext* context)
2077{
2078 auto gdi = context->gdi;
2079 WINPR_ASSERT(gdi);
2080 WINPR_ASSERT(gdi->primary);
2081
2082 HGDI_DC hdc = gdi->primary->hdc;
2083 WINPR_ASSERT(hdc);
2084 if (!hdc->hwnd)
2085 return TRUE;
2086
2087 HGDI_WND hwnd = hdc->hwnd;
2088 WINPR_ASSERT(hwnd->invalid);
2089 hwnd->invalid->null = TRUE;
2090 hwnd->ninvalid = 0;
2091
2092 return TRUE;
2093}
2094
2095bool SdlContext::redraw(bool suppress) const
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}
2108
2109void SdlContext::setConnected(bool val)
2110{
2111 _connected = val;
2112}
2113
2114bool SdlContext::isConnected() const
2115{
2116 return _connected;
2117}
2118
2119/* Stop requested by the user. Overwrite any earlier error with CONNECT_CANCELLED,
2120 * otherwise an auto reconnect ignores the stop. */
2121bool SdlContext::abortConnect() const
2122{
2123 freerdp_set_last_error(context(), FREERDP_ERROR_CONNECT_CANCELLED);
2124 return freerdp_abort_connect_context(context());
2125}
2126
2127rdpContext* SdlContext::context() const
2128{
2129 WINPR_ASSERT(_context);
2130 return _context;
2131}
2132
2133rdpClientContext* SdlContext::common() const
2134{
2135 return reinterpret_cast<rdpClientContext*>(context());
2136}
2137
2138bool SdlContext::setCursor(CursorType type)
2139{
2140 _cursorType = type;
2141 return restoreCursor();
2142}
2143
2144bool SdlContext::setCursor(const rdpPointer* cursor)
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}
2153
2154rdpPointer* SdlContext::cursor() const
2155{
2156 return _cursor.get();
2157}
2158
2159bool SdlContext::restoreCursor()
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}
2200
2201void SdlContext::setMonitorIds(const std::vector<SDL_DisplayID>& ids)
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}
2213
2214const std::vector<SDL_DisplayID>& SdlContext::monitorIds() const
2215{
2216 return _monitorIds;
2217}
2218
2219int64_t SdlContext::monitorId(uint32_t index) const
2220{
2221 if (index >= _monitorIds.size())
2222 {
2223 return -1;
2224 }
2225 return _monitorIds.at(index);
2226}
2227
2228void SdlContext::push(std::vector<SDL_Rect>&& rects)
2229{
2230 std::unique_lock lock(_queue_mux);
2231 _queue.emplace(std::move(rects));
2232}
2233
2234std::vector<SDL_Rect> SdlContext::pop()
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}
2245
2246bool SdlContext::setFullscreen(bool enter, bool forceOriginalDisplay)
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}
2257
2258bool SdlContext::setMinimized()
2259{
2260 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
2261}
2262
2263bool SdlContext::grabMouse() const
2264{
2265 return _grabMouse;
2266}
2267
2268bool SdlContext::toggleGrabMouse()
2269{
2270 return setGrabMouse(!grabMouse());
2271}
2272
2273bool SdlContext::setGrabMouse(bool enter)
2274{
2275 _grabMouse = enter;
2276 return true;
2277}
2278
2279bool SdlContext::grabKeyboard() const
2280{
2281 return _grabKeyboard;
2282}
2283
2284bool SdlContext::toggleGrabKeyboard()
2285{
2286 return setGrabKeyboard(!grabKeyboard());
2287}
2288
2289bool SdlContext::setGrabKeyboard(bool enter)
2290{
2291 _grabKeyboard = enter;
2292 return true;
2293}
2294
2295bool SdlContext::setResizeable(bool enable)
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}
2311
2312bool SdlContext::resizeable() const
2313{
2314 return _resizeable;
2315}
2316
2317bool SdlContext::toggleResizeable()
2318{
2319 return setResizeable(!resizeable());
2320}
2321
2322bool SdlContext::fullscreen() const
2323{
2324 return _fullscreen;
2325}
2326
2327bool SdlContext::toggleFullscreen()
2328{
2329 return setFullscreen(!fullscreen());
2330}
2331
2332/* ---- rdpContext::windowInfoService ---- */
2333
2334static bool window_info_equal(const WTS_WINDOW_INFO& a, const WTS_WINDOW_INFO& b)
2335{
2336 const bool scale = fabsf(a.scale - b.scale) <= FLT_EPSILON;
2337 return (a.hwnd == b.hwnd) && (a.remoteWidth == b.remoteWidth) &&
2338 (a.remoteHeight == b.remoteHeight) && (a.viewWidth == b.viewWidth) &&
2339 (a.viewHeight == b.viewHeight) && (a.scrollX == b.scrollX) && (a.scrollY == b.scrollY) &&
2340 scale;
2341}
2342
2344static HWND native_window(SDL_Window* window)
2345{
2346 if (!window)
2347 return nullptr;
2348 auto props = SDL_GetWindowProperties(window);
2349#if defined(_WIN32)
2350 return static_cast<HWND>(
2351 SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr));
2352#else
2353 return reinterpret_cast<HWND>(
2354 static_cast<uintptr_t>(SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0)));
2355#endif
2356}
2357
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}
2394
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}
2406
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}
2437
2438HRESULT SdlContext::windowInfoGet(void* custom, UINT64 remoteHwnd, WTS_WINDOW_INFO* info)
2439{
2440 auto sdl = static_cast<SdlContext*>(custom);
2441 WINPR_ASSERT(sdl);
2442 WINPR_ASSERT(info);
2443
2444 std::scoped_lock lock(sdl->_windowInfoLock);
2445 if (!sdl->_rail.enabled())
2446 {
2447 /* remoteHwnd only means something in RemoteApp */
2448 if (!sdl->_desktopWindowInfo.hwnd && (sdl->_desktopWindowInfo.viewWidth == 0))
2449 return E_UNEXPECTED; /* no window yet */
2450 *info = sdl->_desktopWindowInfo;
2451 return S_OK;
2452 }
2453 auto it = sdl->_railWindowInfo.find(remoteHwnd);
2454 if (it == sdl->_railWindowInfo.end())
2455 return E_INVALIDARG;
2456 *info = it->second;
2457 return S_OK;
2458}
2459
2460UINT32 SdlContext::windowInfoSessionType(void* custom)
2461{
2462 auto sdl = static_cast<SdlContext*>(custom);
2463 WINPR_ASSERT(sdl);
2464 return sdl->_rail.enabled() ? WTS_RDP_SESSION_TYPE_REMOTEAPP : WTS_RDP_SESSION_TYPE_DESKTOP;
2465}
2466
2467/* ---- mapped renderers (rdpContext::bitmapRenderService): the channels' calls come from their
2468 * threads, the textures are the main thread's ---- */
2469
2470Uint64 SdlContext::rendererAdd(UINT64 mappingId, IWTSBitmapRendererCallback* callback)
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}
2481
2482bool SdlContext::rendererFrame(Uint64 id, const BYTE* data, UINT32 width, UINT32 height,
2483 LONG stride)
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}
2523
2524void SdlContext::rendererRemove(Uint64 id)
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}
2539
2540bool SdlContext::hasRenderers()
2541{
2542 std::scoped_lock lock(_rendererLock);
2543 return !_renderers.empty();
2544}
2545
2546void SdlContext::renderersChanged()
2547{
2548 /* one pending event at a time: frames coming faster than we draw are coalesced */
2549 if (!_renderersPending.exchange(true))
2550 std::ignore = sdl_push_user_event(SDL_EVENT_USER_RENDERER);
2551}
2552
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}
void flushWindowInfo()
bool setNotification(const std::string &message)
void railWindowInfoChanged(uint64_t remoteId)
void updateWindowInfo()
bool presentRenderers()
bool toggleOverlay()
bool show(bool on)
object that handles clipboard context for the SDL3 client
Definition sdl_clip.hpp:66
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_settings_get_server_name(const rdpSettings *settings)
A helper function to return the correct server name.
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.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL val)
Sets a BOOL settings value.
WINPR_ATTR_NODISCARD FREERDP_API UINT64 freerdp_settings_get_uint64(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt64 id)
Returns a UINT64 settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
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:
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
Layout layout(float leftWidth, float leftHeight, float rightWidth, float rightHeight, float width, float margin)
what the client gives the service to answer from
same layout as Win32's RECT, which winpr doesn't have on POSIX
40 bytes on x64