FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_freerdp.cpp
1
20#include <iostream>
21#include <memory>
22#include <mutex>
23
24#include <freerdp/config.h>
25
26#if defined(__has_include)
27#if __has_include(<version>)
28#include <version>
29#endif
30#endif
31
32#include <cerrno>
33#include <cstdio>
34#include <cstring>
35
36#if defined(__cpp_lib_source_location) && (__cpp_lib_source_location >= 201907L)
37#include <source_location>
38#endif
39
40#include <freerdp/constants.h>
41#include <freerdp/freerdp.h>
42#include <freerdp/gdi/gdi.h>
43#include <freerdp/streamdump.h>
44#include <freerdp/utils/signal.h>
45
46#include <freerdp/channels/channels.h>
47#include <freerdp/client/channels.h>
48#include <freerdp/client/cliprdr.h>
49#include <freerdp/client/cmdline.h>
50#include <freerdp/client/file.h>
51
52#include <freerdp/log.h>
53#include <winpr/assert.h>
54#include <winpr/config.h>
55#include <winpr/crt.h>
56#include <winpr/synch.h>
57
58#include <SDL3/SDL.h>
59#if !defined(__MINGW32__)
60#include <SDL3/SDL_main.h>
61#endif
62#include <SDL3/SDL_hints.h>
63#include <SDL3/SDL_oldnames.h>
64#include <SDL3/SDL_video.h>
65
66#include <sdl_config.hpp>
67
68#include "dialogs/sdl_connection_dialog_hider.hpp"
69#include "dialogs/sdl_dialogs.hpp"
70#include "scoped_guard.hpp"
71#include "sdl_channels.hpp"
72#include "sdl_freerdp.hpp"
73#include "sdl_context.hpp"
74#include "sdl_monitor.hpp"
75#include "sdl_pointer.hpp"
76#include "sdl_prefs.hpp"
77#if defined(_WIN32)
78#include "sdl_win32_console.hpp"
79#endif
80#include "sdl_utils.hpp"
81
82#if defined(_WIN32)
83#define SDL_TAG CLIENT_TAG("SDL")
84#endif
85
86class ErrorMsg : public std::exception
87{
88 public:
89 ErrorMsg(int rc, Uint32 type, const std::string& msg,
90 const std::string& sdlError = SDL_GetError()
91#if defined(__cpp_lib_source_location) && (__cpp_lib_source_location >= 201907L)
92 ,
93 std::source_location loc = std::source_location::current()
94#elif defined(__GNUC__)
95 ,
96 const std::string& file = __builtin_FILE(),
97 const std::string& fkt = __builtin_FUNCTION(), size_t line = __builtin_LINE(),
98#if defined(__clang__)
99 size_t column = __builtin_COLUMN()
100#else
101 size_t column = 0
102#endif
103#endif
104 );
105
106 [[nodiscard]] int rc() const;
107 [[nodiscard]] const char* what() const noexcept override;
108
109 private:
110 int _rc;
111 Uint32 _type;
112 std::string _msg;
113 std::string _sdlError;
114 std::string _buffer;
115
116 std::string _file;
117 std::string _fkt;
118 size_t _line = 0;
119 size_t _column = 0;
120};
121const char* ErrorMsg::what() const noexcept
122{
123 return _buffer.c_str();
124}
125
126int ErrorMsg::rc() const
127{
128 return _rc;
129}
130
131ErrorMsg::ErrorMsg(int rc, Uint32 type, const std::string& msg, const std::string& sdlError
132#if defined(__cpp_lib_source_location) && (__cpp_lib_source_location >= 201907L)
133 ,
134 std::source_location loc
135#elif defined(__GNUC__)
136 ,
137 const std::string& file, const std::string& fkt, size_t line, size_t column
138#endif
139 )
140 : _rc(rc), _type(type), _msg(msg), _sdlError(sdlError)
141#if defined(__cpp_lib_source_location) && (__cpp_lib_source_location >= 201907L)
142 ,
143 _file(loc.file_name()), _fkt(loc.function_name()), _line(loc.line()), _column(loc.column())
144#elif defined(__GNUC__)
145 ,
146 _file(file), _fkt(fkt), _line(line), _column(column)
147#endif
148{
149 std::stringstream ss;
150 ss << _msg << " {" << sdl::utils::toString(_type) << "}{SDL:" << sdlError << "}";
151 ss << "{" << _fkt << " [" << _file << ":" << _line << "-" << _column << "]}";
152 _buffer = ss.str();
153}
154
155static void sdl_term_handler([[maybe_unused]] int signum, [[maybe_unused]] const char* signame,
156 [[maybe_unused]] void* context)
157{
158 std::ignore = sdl_push_quit();
159}
160
161[[nodiscard]] static int sdl_run(SdlContext* sdl)
162{
163 int rc = -1;
164 WINPR_ASSERT(sdl);
165
166 try
167 {
168 while (!sdl->shallAbort())
169 {
170 SDL_Event windowEvent = {};
171 while (!sdl->shallAbort() && SDL_WaitEventTimeout(nullptr, 1000))
172 {
173 /* Only poll standard SDL events and SDL_EVENT_USERS meant to create
174 * dialogs. do not process the dialog return value events here.
175 */
176 const int prc = SDL_PeepEvents(&windowEvent, 1, SDL_GETEVENT, SDL_EVENT_FIRST,
177 SDL_EVENT_USER_RETRY_DIALOG);
178 if (prc < 0)
179 {
180 if (sdl_log_error(prc, sdl->getWLog(), "SDL_PeepEvents"))
181 continue;
182 }
183
184#if defined(WITH_DEBUG_SDL_EVENTS)
185 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "got event %s [0x%08" PRIx32 "]",
186 sdl::utils::toString(windowEvent.type).c_str(), windowEvent.type);
187#endif
188 if (sdl->shallAbort(true))
189 continue;
190
191 if (sdl->getDialog().handleEvent(windowEvent))
192 continue;
193
194 if (!sdl->handleEvent(windowEvent))
195 throw ErrorMsg{ -1, windowEvent.type, "sdl->handleEvent" };
196
197 switch (windowEvent.type)
198 {
199 case SDL_EVENT_QUIT:
200 std::ignore = freerdp_abort_connect_context(sdl->context());
201 break;
202 case SDL_EVENT_USER_CERT_DIALOG:
203 {
205 auto title = static_cast<const char*>(windowEvent.user.data1);
206 auto msg = static_cast<const char*>(windowEvent.user.data2);
207 if (!sdl_cert_dialog_show(title, msg))
208 throw ErrorMsg{ -1, windowEvent.type, "sdl_cert_dialog_show" };
209 }
210 break;
211 case SDL_EVENT_USER_SHOW_DIALOG:
212 {
214 auto title = static_cast<const char*>(windowEvent.user.data1);
215 auto msg = static_cast<const char*>(windowEvent.user.data2);
216 if (!sdl_message_dialog_show(title, msg, windowEvent.user.code))
217 throw ErrorMsg{ -1, windowEvent.type, "sdl_message_dialog_show" };
218 }
219 break;
220 case SDL_EVENT_USER_SCARD_DIALOG:
221 {
223 auto title = static_cast<const char*>(windowEvent.user.data1);
224 auto msg = static_cast<const char**>(windowEvent.user.data2);
225 if (!sdl_scard_dialog_show(title, windowEvent.user.code, msg))
226 throw ErrorMsg{ -1, windowEvent.type, "sdl_scard_dialog_show" };
227 }
228 break;
229 case SDL_EVENT_USER_AUTH_DIALOG:
230 {
232 if (!sdl_auth_dialog_show(
233 reinterpret_cast<const SDL_UserAuthArg*>(windowEvent.padding)))
234 throw ErrorMsg{ -1, windowEvent.type, "sdl_auth_dialog_show" };
235 }
236 break;
237 case SDL_EVENT_USER_UPDATE:
238 {
239 std::vector<SDL_Rect> rectangles;
240 do
241 {
242 rectangles = sdl->pop();
243 if (!sdl->drawToWindows(rectangles))
244 throw ErrorMsg{ -1, windowEvent.type, "sdl->drawToWindows" };
245 } while (!rectangles.empty());
246 }
247 break;
248 case SDL_EVENT_USER_CREATE_WINDOWS:
249 {
250 auto ctx = static_cast<SdlContext*>(windowEvent.user.data1);
251 if (!ctx->createWindows())
252 throw ErrorMsg{ -1, windowEvent.type, "sdl->createWindows" };
253 }
254 break;
255 case SDL_EVENT_USER_WINDOW_RESIZEABLE:
256 {
257 auto window = static_cast<SdlWindow*>(windowEvent.user.data1);
258 const bool use = windowEvent.user.code != 0;
259 if (window)
260 window->resizeable(use);
261 }
262 break;
263 case SDL_EVENT_USER_WINDOW_FULLSCREEN:
264 {
265 auto window = static_cast<SdlWindow*>(windowEvent.user.data1);
266 const bool enter = windowEvent.user.code != 0;
267 const bool forceOriginalDisplay = windowEvent.user.data2 != nullptr;
268 if (window)
269 window->fullscreen(enter, forceOriginalDisplay);
270 }
271 break;
272 case SDL_EVENT_USER_WINDOW_MINIMIZE:
273 if (!sdl->minimizeAllWindows())
274 throw ErrorMsg{ -1, windowEvent.type, "sdl->minimizeAllWindows" };
275 break;
276 case SDL_EVENT_USER_POINTER_NULL:
277 if (!sdl->setCursor(SdlContext::CURSOR_NULL))
278 throw ErrorMsg{ -1, windowEvent.type, "sdl->setCursor" };
279 break;
280 case SDL_EVENT_USER_POINTER_DEFAULT:
281 if (!sdl->setCursor(SdlContext::CURSOR_DEFAULT))
282 throw ErrorMsg{ -1, windowEvent.type, "sdl->setCursor" };
283 break;
284 case SDL_EVENT_USER_POINTER_POSITION:
285 {
286 const auto x =
287 static_cast<INT32>(reinterpret_cast<uintptr_t>(windowEvent.user.data1));
288 const auto y =
289 static_cast<INT32>(reinterpret_cast<uintptr_t>(windowEvent.user.data2));
290 if (!sdl->moveMouseTo(
291 { static_cast<float>(x) * 1.0f, static_cast<float>(y) * 1.0f }))
292 throw ErrorMsg{ -1, windowEvent.type, "sdl->moveMouseTo" };
293 }
294 break;
295 case SDL_EVENT_USER_POINTER_SET:
296 if (!sdl->setCursor(static_cast<rdpPointer*>(windowEvent.user.data1)))
297 throw ErrorMsg{ -1, windowEvent.type, "sdl->setCursor" };
298 break;
299 case SDL_EVENT_USER_QUIT:
300 default:
301 break;
302 }
303 }
304 }
305 rc = 1;
306 }
307 catch (ErrorMsg& msg)
308 {
309 WLog_Print(sdl->getWLog(), WLOG_ERROR, "[exception] %s", msg.what());
310 rc = msg.rc();
311 }
312
313 return rc;
314}
315
316/* Optional global initializer.
317 * Here we just register a signal handler to print out stack traces
318 * if available. */
319[[nodiscard]] static BOOL sdl_client_global_init()
320{
321#if defined(_WIN32)
322 WSADATA wsaData = {};
323 const DWORD wVersionRequested = MAKEWORD(1, 1);
324 const int rc = WSAStartup(wVersionRequested, &wsaData);
325 if (rc != 0)
326 {
327 WLog_ERR(SDL_TAG, "WSAStartup failed with %s [%d]", gai_strerrorA(rc), rc);
328 return FALSE;
329 }
330#endif
331
332 return (freerdp_handle_signals() == 0);
333}
334
335/* Optional global tear down */
336static void sdl_client_global_uninit()
337{
338#if defined(_WIN32)
339 WSACleanup();
340#endif
341}
342
343[[nodiscard]] static BOOL sdl_client_new(freerdp* instance, rdpContext* context)
344{
345 auto sdl = reinterpret_cast<sdl_rdp_context*>(context);
346
347 if (!instance || !context)
348 return FALSE;
349
350 sdl->sdl = new SdlContext(context);
351 return sdl->sdl != nullptr;
352}
353
354static void sdl_client_free([[maybe_unused]] freerdp* instance, rdpContext* context)
355{
356 auto sdl = reinterpret_cast<sdl_rdp_context*>(context);
357
358 if (!context)
359 return;
360
361 delete sdl->sdl;
362}
363
364[[nodiscard]] static int sdl_client_start(rdpContext* context)
365{
366 auto sdl = get_context(context);
367 WINPR_ASSERT(sdl);
368 return sdl->start();
369}
370
371[[nodiscard]] static int sdl_client_stop(rdpContext* context)
372{
373 auto sdl = get_context(context);
374 WINPR_ASSERT(sdl);
375 return sdl->join();
376}
377
378static void RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
379{
380 WINPR_ASSERT(pEntryPoints);
381
382 ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
383 pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
384 pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
385 pEntryPoints->GlobalInit = sdl_client_global_init;
386 pEntryPoints->GlobalUninit = sdl_client_global_uninit;
387 pEntryPoints->ContextSize = sizeof(sdl_rdp_context);
388 pEntryPoints->ClientNew = sdl_client_new;
389 pEntryPoints->ClientFree = sdl_client_free;
390 pEntryPoints->ClientStart = sdl_client_start;
391 pEntryPoints->ClientStop = sdl_client_stop;
392}
393
394static void context_free(sdl_rdp_context* sdl)
395{
396 if (sdl)
397 freerdp_client_context_free(&sdl->common.context);
398}
399
400[[nodiscard]] static const char* category2str(int category)
401{
402 switch (category)
403 {
404 case SDL_LOG_CATEGORY_APPLICATION:
405 return "SDL_LOG_CATEGORY_APPLICATION";
406 case SDL_LOG_CATEGORY_ERROR:
407 return "SDL_LOG_CATEGORY_ERROR";
408 case SDL_LOG_CATEGORY_ASSERT:
409 return "SDL_LOG_CATEGORY_ASSERT";
410 case SDL_LOG_CATEGORY_SYSTEM:
411 return "SDL_LOG_CATEGORY_SYSTEM";
412 case SDL_LOG_CATEGORY_AUDIO:
413 return "SDL_LOG_CATEGORY_AUDIO";
414 case SDL_LOG_CATEGORY_VIDEO:
415 return "SDL_LOG_CATEGORY_VIDEO";
416 case SDL_LOG_CATEGORY_RENDER:
417 return "SDL_LOG_CATEGORY_RENDER";
418 case SDL_LOG_CATEGORY_INPUT:
419 return "SDL_LOG_CATEGORY_INPUT";
420 case SDL_LOG_CATEGORY_TEST:
421 return "SDL_LOG_CATEGORY_TEST";
422 case SDL_LOG_CATEGORY_GPU:
423 return "SDL_LOG_CATEGORY_GPU";
424 case SDL_LOG_CATEGORY_RESERVED2:
425 return "SDL_LOG_CATEGORY_RESERVED2";
426 case SDL_LOG_CATEGORY_RESERVED3:
427 return "SDL_LOG_CATEGORY_RESERVED3";
428 case SDL_LOG_CATEGORY_RESERVED4:
429 return "SDL_LOG_CATEGORY_RESERVED4";
430 case SDL_LOG_CATEGORY_RESERVED5:
431 return "SDL_LOG_CATEGORY_RESERVED5";
432 case SDL_LOG_CATEGORY_RESERVED6:
433 return "SDL_LOG_CATEGORY_RESERVED6";
434 case SDL_LOG_CATEGORY_RESERVED7:
435 return "SDL_LOG_CATEGORY_RESERVED7";
436 case SDL_LOG_CATEGORY_RESERVED8:
437 return "SDL_LOG_CATEGORY_RESERVED8";
438 case SDL_LOG_CATEGORY_RESERVED9:
439 return "SDL_LOG_CATEGORY_RESERVED9";
440 case SDL_LOG_CATEGORY_RESERVED10:
441 return "SDL_LOG_CATEGORY_RESERVED10";
442 case SDL_LOG_CATEGORY_CUSTOM:
443 default:
444 return "SDL_LOG_CATEGORY_CUSTOM";
445 }
446}
447
448[[nodiscard]] static SDL_LogPriority wloglevel2dl(DWORD level)
449{
450 switch (level)
451 {
452 case WLOG_TRACE:
453 return SDL_LOG_PRIORITY_VERBOSE;
454 case WLOG_DEBUG:
455 return SDL_LOG_PRIORITY_DEBUG;
456 case WLOG_INFO:
457 return SDL_LOG_PRIORITY_INFO;
458 case WLOG_WARN:
459 return SDL_LOG_PRIORITY_WARN;
460 case WLOG_ERROR:
461 return SDL_LOG_PRIORITY_ERROR;
462 case WLOG_FATAL:
463 return SDL_LOG_PRIORITY_CRITICAL;
464 case WLOG_OFF:
465 default:
466 return SDL_LOG_PRIORITY_VERBOSE;
467 }
468}
469
470[[nodiscard]] static DWORD sdlpriority2wlog(SDL_LogPriority priority)
471{
472 DWORD level = WLOG_OFF;
473 switch (priority)
474 {
475 case SDL_LOG_PRIORITY_VERBOSE:
476 level = WLOG_TRACE;
477 break;
478 case SDL_LOG_PRIORITY_DEBUG:
479 level = WLOG_DEBUG;
480 break;
481 case SDL_LOG_PRIORITY_INFO:
482 level = WLOG_INFO;
483 break;
484 case SDL_LOG_PRIORITY_WARN:
485 level = WLOG_WARN;
486 break;
487 case SDL_LOG_PRIORITY_ERROR:
488 level = WLOG_ERROR;
489 break;
490 case SDL_LOG_PRIORITY_CRITICAL:
491 level = WLOG_FATAL;
492 break;
493 default:
494 break;
495 }
496
497 return level;
498}
499
500static void SDLCALL winpr_LogOutputFunction(void* userdata, int category, SDL_LogPriority priority,
501 const char* message)
502{
503 auto sdl = static_cast<SdlContext*>(userdata);
504 WINPR_ASSERT(sdl);
505
506 const DWORD level = sdlpriority2wlog(priority);
507 auto log = sdl->getWLog();
508 if (!WLog_IsLevelActive(log, level))
509 return;
510
511 WLog_PrintTextMessage(log, level, __LINE__, __FILE__, __func__, "[%s] %s",
512 category2str(category), message);
513}
514
515static void sdl_quit()
516{
517 const auto cat = SDL_LOG_CATEGORY_APPLICATION;
518 SDL_Event ev = {};
519 ev.type = SDL_EVENT_QUIT;
520 if (!SDL_PushEvent(&ev))
521 {
522 SDL_LogError(cat, "An error occurred: %s", SDL_GetError());
523 }
524}
525
526static void SDLCALL rdp_file_cb(void* userdata, const char* const* filelist,
527 WINPR_ATTR_UNUSED int filter)
528{
529 auto rdp = static_cast<std::string*>(userdata);
530
531 const auto cat = SDL_LOG_CATEGORY_APPLICATION;
532 if (!filelist)
533 {
534 SDL_LogError(cat, "An error occurred: %s", SDL_GetError());
535 sdl_quit();
536 return;
537 }
538 else if (!*filelist)
539 {
540 SDL_LogError(cat, "The user did not select any file.");
541 SDL_LogError(cat, "Most likely, the dialog was canceled.");
542 sdl_quit();
543 return;
544 }
545
546 while (*filelist)
547 {
548 SDL_LogError(cat, "Full path to selected file: '%s'", *filelist);
549 *rdp = *filelist;
550 filelist++;
551 }
552
553 sdl_quit();
554}
555
556[[nodiscard]] static std::string getRdpFile()
557{
558 const auto flags = SDL_INIT_VIDEO | SDL_INIT_EVENTS;
559 SDL_DialogFileFilter filters[] = { { "RDP files", "rdp;rdpw" } };
560 std::string rdp;
561
562 bool running = true;
563 if (!SDL_Init(flags))
564 return {};
565
566 auto props = SDL_CreateProperties();
567 SDL_SetStringProperty(props, SDL_PROP_FILE_DIALOG_TITLE_STRING,
568 "SDL Freerdp - Open a RDP file");
569 SDL_SetBooleanProperty(props, SDL_PROP_FILE_DIALOG_MANY_BOOLEAN, false);
570 SDL_SetPointerProperty(props, SDL_PROP_FILE_DIALOG_FILTERS_POINTER, filters);
571 SDL_SetNumberProperty(props, SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER, ARRAYSIZE(filters));
572 SDL_ShowFileDialogWithProperties(SDL_FILEDIALOG_OPENFILE, rdp_file_cb, &rdp, props);
573 SDL_DestroyProperties(props);
574
575 do
576 {
577 SDL_Event event = {};
578 std::ignore = SDL_PollEvent(&event);
579
580 switch (event.type)
581 {
582 case SDL_EVENT_QUIT:
583 running = false;
584 break;
585 default:
586 break;
587 }
588 } while (running);
589 SDL_Quit();
590 return rdp;
591}
592
593int main(int argc, char* argv[])
594{
595#if defined(_WIN32)
596 sdl::win32::release_transient_console();
597#endif
598
599 int rc = -1;
600 RDP_CLIENT_ENTRY_POINTS clientEntryPoints = {};
601
602 /* Allocate the RDP context first, we need to pass it to SDL */
603 RdpClientEntry(&clientEntryPoints);
604 std::unique_ptr<sdl_rdp_context, void (*)(sdl_rdp_context*)> sdl_rdp(
605 reinterpret_cast<sdl_rdp_context*>(freerdp_client_context_new(&clientEntryPoints)),
606 context_free);
607
608 if (!sdl_rdp)
609 return -1;
610 auto sdl = sdl_rdp->sdl;
611
612 auto settings = sdl->context()->settings;
613 WINPR_ASSERT(settings);
614
615 std::string rdp_file;
616 std::vector<char*> args;
617 args.reserve(WINPR_ASSERTING_INT_CAST(size_t, argc));
618 for (auto x = 0; x < argc; x++)
619 args.push_back(argv[x]);
620
621 if (argc == 1)
622 {
623 rdp_file = getRdpFile();
624 if (!rdp_file.empty())
625 {
626 args.push_back(rdp_file.data());
627 }
628 }
629
630 auto status = freerdp_client_settings_parse_command_line(
631 settings, WINPR_ASSERTING_INT_CAST(int, args.size()), args.data(), FALSE);
632 sdl_rdp->sdl->setMetadata();
633 if (status)
634 {
635 rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
636 if (freerdp_settings_get_bool(settings, FreeRDP_ListMonitors))
637 {
638 if (!sdl_list_monitors(sdl))
639 return -1;
640 }
641 else
642 {
643 switch (status)
644 {
645 case COMMAND_LINE_STATUS_PRINT:
646 case COMMAND_LINE_STATUS_PRINT_VERSION:
647 case COMMAND_LINE_STATUS_PRINT_BUILDCONFIG:
648 break;
649 case COMMAND_LINE_STATUS_PRINT_HELP:
650 SdlPref::print_config_file_help(3);
651 break;
652 default:
653 break;
654 }
655 }
656 return rc;
657 }
658
659 /* Basic SDL initialization */
660 if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
661 return -1;
662
663 SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
664 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
665 SDL_SetHint(SDL_HINT_PEN_MOUSE_EVENTS, "0");
666 SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
667 SDL_SetHint(SDL_HINT_PEN_TOUCH_EVENTS, "1");
668 SDL_SetHint(SDL_HINT_TRACKPAD_IS_TOUCH_ONLY, "1");
669#if SDL_VERSION_ATLEAST(3, 4, 0)
670 SDL_SetHint(SDL_HINT_MOUSE_DPI_SCALE_CURSORS, "1");
671#endif
672
673 /* Redirect SDL log messages to wLog */
674 SDL_SetLogOutputFunction(winpr_LogOutputFunction, sdl);
675 auto level = WLog_GetLogLevel(sdl->getWLog());
676 SDL_SetLogPriorities(wloglevel2dl(level));
677
678 auto backend = SDL_GetCurrentVideoDriver();
679 WLog_Print(sdl->getWLog(), WLOG_DEBUG, "client is using backend '%s'", backend);
680 sdl_dialogs_init();
681
682 /* SDL cleanup code if the client exits */
683 ScopeGuard guard(
684 [&]()
685 {
686 sdl->cleanup();
687 freerdp_del_signal_cleanup_handler(sdl->context(), sdl_term_handler);
688 sdl_dialogs_uninit();
689 SDL_Quit();
690 });
691 if (!sdl->detectDisplays())
692 return -1;
693
694 /* Initialize RDP */
695 auto context = sdl->context();
696 WINPR_ASSERT(context);
697
698 if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
699 return -1;
700
701 if (freerdp_client_start(context) != 0)
702 return -1;
703
704 rc = sdl_run(sdl);
705
706 if (freerdp_client_stop(context) != 0)
707 return -1;
708
709 if (sdl->exitCode() != 0)
710 rc = sdl->exitCode();
711
712 return rc;
713}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.