24 #include <freerdp/config.h>
30 #include <freerdp/freerdp.h>
31 #include <freerdp/constants.h>
32 #include <freerdp/gdi/gdi.h>
33 #include <freerdp/streamdump.h>
34 #include <freerdp/utils/signal.h>
36 #include <freerdp/client/file.h>
37 #include <freerdp/client/cmdline.h>
38 #include <freerdp/client/cliprdr.h>
39 #include <freerdp/client/channels.h>
40 #include <freerdp/channels/channels.h>
42 #include <winpr/crt.h>
43 #include <winpr/config.h>
44 #include <winpr/assert.h>
45 #include <winpr/synch.h>
46 #include <freerdp/log.h>
49 #include <SDL3/SDL_hints.h>
50 #include <SDL3/SDL_video.h>
51 #include <SDL3/SDL_oldnames.h>
53 #include "sdl_channels.hpp"
54 #include "sdl_freerdp.hpp"
55 #include "sdl_utils.hpp"
56 #include "sdl_disp.hpp"
57 #include "sdl_monitor.hpp"
58 #include "sdl_kbd.hpp"
59 #include "sdl_touch.hpp"
60 #include "sdl_pointer.hpp"
61 #include "sdl_prefs.hpp"
62 #include "dialogs/sdl_dialogs.hpp"
63 #include "scoped_guard.hpp"
65 #include <aad/sdl_webview.hpp>
67 #define SDL_TAG CLIENT_TAG("SDL")
73 SDL_EXIT_DISCONNECT = 1,
75 SDL_EXIT_IDLE_TIMEOUT = 3,
76 SDL_EXIT_LOGON_TIMEOUT = 4,
77 SDL_EXIT_CONN_REPLACED = 5,
78 SDL_EXIT_OUT_OF_MEMORY = 6,
79 SDL_EXIT_CONN_DENIED = 7,
80 SDL_EXIT_CONN_DENIED_FIPS = 8,
81 SDL_EXIT_USER_PRIVILEGES = 9,
82 SDL_EXIT_FRESH_CREDENTIALS_REQUIRED = 10,
83 SDL_EXIT_DISCONNECT_BY_USER = 11,
86 SDL_EXIT_LICENSE_INTERNAL = 16,
87 SDL_EXIT_LICENSE_NO_LICENSE_SERVER = 17,
88 SDL_EXIT_LICENSE_NO_LICENSE = 18,
89 SDL_EXIT_LICENSE_BAD_CLIENT_MSG = 19,
90 SDL_EXIT_LICENSE_HWID_DOESNT_MATCH = 20,
91 SDL_EXIT_LICENSE_BAD_CLIENT = 21,
92 SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22,
93 SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23,
94 SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24,
95 SDL_EXIT_LICENSE_CANT_UPGRADE = 25,
96 SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26,
102 SDL_EXIT_PARSE_ARGUMENTS = 128,
103 SDL_EXIT_MEMORY = 129,
104 SDL_EXIT_PROTOCOL = 130,
105 SDL_EXIT_CONN_FAILED = 131,
106 SDL_EXIT_AUTH_FAILURE = 132,
107 SDL_EXIT_NEGO_FAILURE = 133,
108 SDL_EXIT_LOGON_FAILURE = 134,
109 SDL_EXIT_ACCOUNT_LOCKED_OUT = 135,
110 SDL_EXIT_PRE_CONNECT_FAILED = 136,
111 SDL_EXIT_CONNECT_UNDEFINED = 137,
112 SDL_EXIT_POST_CONNECT_FAILED = 138,
113 SDL_EXIT_DNS_ERROR = 139,
114 SDL_EXIT_DNS_NAME_NOT_FOUND = 140,
115 SDL_EXIT_CONNECT_FAILED = 141,
116 SDL_EXIT_MCS_CONNECT_INITIAL_ERROR = 142,
117 SDL_EXIT_TLS_CONNECT_FAILED = 143,
118 SDL_EXIT_INSUFFICIENT_PRIVILEGES = 144,
119 SDL_EXIT_CONNECT_CANCELLED = 145,
121 SDL_EXIT_CONNECT_TRANSPORT_FAILED = 147,
122 SDL_EXIT_CONNECT_PASSWORD_EXPIRED = 148,
123 SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE = 149,
124 SDL_EXIT_CONNECT_KDC_UNREACHABLE = 150,
125 SDL_EXIT_CONNECT_ACCOUNT_DISABLED = 151,
126 SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
127 SDL_EXIT_CONNECT_CLIENT_REVOKED = 153,
128 SDL_EXIT_CONNECT_WRONG_PASSWORD = 154,
129 SDL_EXIT_CONNECT_ACCESS_DENIED = 155,
130 SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION = 156,
131 SDL_EXIT_CONNECT_ACCOUNT_EXPIRED = 157,
132 SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
133 SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
135 SDL_EXIT_UNKNOWN = 255,
138 struct sdl_exit_code_map_t
142 const char* code_tag;
145 #define ENTRY(x, y) \
149 static const struct sdl_exit_code_map_t sdl_exit_code_map[] = {
150 ENTRY(FREERDP_ERROR_SUCCESS, SDL_EXIT_SUCCESS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_DISCONNECT),
151 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGOFF), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_IDLE_TIMEOUT),
152 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGON_TIMEOUT),
153 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_REPLACED),
154 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_OUT_OF_MEMORY),
155 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED),
156 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED_FIPS),
157 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_USER_PRIVILEGES),
158 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_FRESH_CREDENTIALS_REQUIRED),
159 ENTRY(ERRINFO_LOGOFF_BY_USER, SDL_EXIT_DISCONNECT_BY_USER),
160 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_UNKNOWN),
163 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_INTERNAL),
164 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE_SERVER),
165 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE),
166 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_MSG),
167 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_HWID_DOESNT_MATCH),
168 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT),
169 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL),
170 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL),
171 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION),
172 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
173 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS),
174 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
177 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_RDP),
180 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PARSE_ARGUMENTS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_MEMORY),
181 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PROTOCOL), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_FAILED),
183 ENTRY(FREERDP_ERROR_AUTHENTICATION_FAILED, SDL_EXIT_AUTH_FAILURE),
184 ENTRY(FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, SDL_EXIT_NEGO_FAILURE),
185 ENTRY(FREERDP_ERROR_CONNECT_LOGON_FAILURE, SDL_EXIT_LOGON_FAILURE),
186 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, SDL_EXIT_ACCOUNT_LOCKED_OUT),
187 ENTRY(FREERDP_ERROR_PRE_CONNECT_FAILED, SDL_EXIT_PRE_CONNECT_FAILED),
188 ENTRY(FREERDP_ERROR_CONNECT_UNDEFINED, SDL_EXIT_CONNECT_UNDEFINED),
189 ENTRY(FREERDP_ERROR_POST_CONNECT_FAILED, SDL_EXIT_POST_CONNECT_FAILED),
190 ENTRY(FREERDP_ERROR_DNS_ERROR, SDL_EXIT_DNS_ERROR),
191 ENTRY(FREERDP_ERROR_DNS_NAME_NOT_FOUND, SDL_EXIT_DNS_NAME_NOT_FOUND),
192 ENTRY(FREERDP_ERROR_CONNECT_FAILED, SDL_EXIT_CONNECT_FAILED),
193 ENTRY(FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, SDL_EXIT_MCS_CONNECT_INITIAL_ERROR),
194 ENTRY(FREERDP_ERROR_TLS_CONNECT_FAILED, SDL_EXIT_TLS_CONNECT_FAILED),
195 ENTRY(FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, SDL_EXIT_INSUFFICIENT_PRIVILEGES),
196 ENTRY(FREERDP_ERROR_CONNECT_CANCELLED, SDL_EXIT_CONNECT_CANCELLED),
197 ENTRY(FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, SDL_EXIT_CONNECT_TRANSPORT_FAILED),
198 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, SDL_EXIT_CONNECT_PASSWORD_EXPIRED),
199 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE),
200 ENTRY(FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, SDL_EXIT_CONNECT_KDC_UNREACHABLE),
201 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, SDL_EXIT_CONNECT_ACCOUNT_DISABLED),
202 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED,
203 SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED),
204 ENTRY(FREERDP_ERROR_CONNECT_CLIENT_REVOKED, SDL_EXIT_CONNECT_CLIENT_REVOKED),
205 ENTRY(FREERDP_ERROR_CONNECT_WRONG_PASSWORD, SDL_EXIT_CONNECT_WRONG_PASSWORD),
206 ENTRY(FREERDP_ERROR_CONNECT_ACCESS_DENIED, SDL_EXIT_CONNECT_ACCESS_DENIED),
207 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION),
208 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, SDL_EXIT_CONNECT_ACCOUNT_EXPIRED),
209 ENTRY(FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED),
210 ENTRY(FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS,
211 SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS)
214 static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(
int exit_code)
216 for (
const auto& x : sdl_exit_code_map)
218 const struct sdl_exit_code_map_t* cur = &x;
219 if (cur->code == exit_code)
225 static void sdl_hide_connection_dialog(
SdlContext* sdl)
228 std::lock_guard<CriticalSection> lock(sdl->critical);
229 if (sdl->connection_dialog)
230 sdl->connection_dialog->hide();
233 static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(DWORD error)
235 for (
const auto& x : sdl_exit_code_map)
237 const struct sdl_exit_code_map_t* cur = &x;
238 if (cur->error == error)
244 static int sdl_map_error_to_exit_code(DWORD error)
246 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
250 return SDL_EXIT_CONN_FAILED;
253 static const char* sdl_map_error_to_code_tag(DWORD error)
255 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
257 return entry->code_tag;
261 static const char* sdl_map_to_code_tag(
int code)
263 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_code(code);
265 return entry->code_tag;
269 static int error_info_to_error(freerdp* instance, DWORD* pcode,
char** msg,
size_t* len)
271 const DWORD code = freerdp_error_info(instance);
272 const char* name = freerdp_get_error_info_name(code);
273 const char* str = freerdp_get_error_info_string(code);
274 const int exit_code = sdl_map_error_to_exit_code(code);
276 winpr_asprintf(msg, len,
"Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32
"]: %s",
277 sdl_map_error_to_code_tag(exit_code), name, code, str);
278 WLog_DBG(SDL_TAG,
"%s", *msg);
286 static BOOL sdl_begin_paint(rdpContext* context)
288 rdpGdi* gdi =
nullptr;
289 auto sdl = get_context(context);
293 HANDLE handles[] = { sdl->update_complete.handle(), freerdp_abort_event(context) };
294 const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
302 sdl->update_complete.clear();
306 WINPR_ASSERT(gdi->primary);
307 WINPR_ASSERT(gdi->primary->hdc);
308 WINPR_ASSERT(gdi->primary->hdc->hwnd);
309 WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
310 gdi->primary->hdc->hwnd->invalid->null = TRUE;
311 gdi->primary->hdc->hwnd->ninvalid = 0;
320 auto gdi = sdl->context()->gdi;
321 return gdi_send_suppress_output(gdi, FALSE);
324 class SdlEventUpdateTriggerGuard
330 explicit SdlEventUpdateTriggerGuard(
SdlContext* sdl) : _sdl(sdl)
333 ~SdlEventUpdateTriggerGuard()
335 _sdl->update_complete.set();
337 SdlEventUpdateTriggerGuard(
const SdlEventUpdateTriggerGuard&) =
delete;
338 SdlEventUpdateTriggerGuard(SdlEventUpdateTriggerGuard&&) =
delete;
339 SdlEventUpdateTriggerGuard& operator=(
const SdlEventUpdateTriggerGuard&) =
delete;
340 SdlEventUpdateTriggerGuard& operator=(SdlEventUpdateTriggerGuard&&) =
delete;
343 static bool sdl_draw_to_window_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
344 SDL_Point offset,
const SDL_Rect& srcRect)
346 SDL_Rect dstRect = { offset.x + srcRect.x, offset.y + srcRect.y, srcRect.w, srcRect.h };
347 return window.blit(surface, srcRect, dstRect);
350 static bool sdl_draw_to_window_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
351 SDL_Point offset,
const std::vector<SDL_Rect>& rects = {})
355 return sdl_draw_to_window_rect(sdl, window, surface, offset,
356 { 0, 0, surface->w, surface->h });
358 for (
auto& srcRect : rects)
360 if (!sdl_draw_to_window_rect(sdl, window, surface, offset, srcRect))
366 static bool sdl_draw_to_window_scaled_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
367 const SDL_Rect& srcRect)
369 SDL_Rect dstRect = srcRect;
370 sdl_scale_coordinates(sdl, window.id(), &dstRect.x, &dstRect.y, FALSE, TRUE);
371 sdl_scale_coordinates(sdl, window.id(), &dstRect.w, &dstRect.h, FALSE, TRUE);
372 return window.blit(surface, srcRect, dstRect);
375 static BOOL sdl_draw_to_window_scaled_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
376 const std::vector<SDL_Rect>& rects = {})
380 return sdl_draw_to_window_scaled_rect(sdl, window, surface,
381 { 0, 0, surface->w, surface->h });
383 for (
const auto& srcRect : rects)
385 if (!sdl_draw_to_window_scaled_rect(sdl, window, surface, srcRect))
392 const std::vector<SDL_Rect>& rects = {})
396 auto context = sdl->context();
397 auto gdi = context->gdi;
399 auto size = window.rect();
403 if (gdi->width < size.w)
405 window.setOffsetX((size.w - gdi->width) / 2);
407 if (gdi->height < size.h)
409 window.setOffsetY((size.h - gdi->height) / 2);
412 auto surface = sdl->primary.get();
413 if (!sdl_draw_to_window_rect(sdl, window, surface, { window.offsetX(), window.offsetY() },
419 if (!sdl_draw_to_window_scaled_rect(sdl, window, sdl->primary.get(), rects))
422 window.updateSurface();
426 static BOOL sdl_draw_to_window(
SdlContext* sdl, std::map<Uint32, SdlWindow>& windows,
427 const std::vector<SDL_Rect>& rects = {})
429 for (
auto& window : windows)
431 if (!sdl_draw_to_window(sdl, window.second, rects))
438 static BOOL sdl_end_paint_process(rdpContext* context)
440 rdpGdi* gdi =
nullptr;
441 auto sdl = get_context(context);
443 WINPR_ASSERT(context);
445 SdlEventUpdateTriggerGuard guard(sdl);
449 WINPR_ASSERT(gdi->primary);
450 WINPR_ASSERT(gdi->primary->hdc);
451 WINPR_ASSERT(gdi->primary->hdc->hwnd);
452 WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
453 if (gdi->suppressOutput || gdi->primary->hdc->hwnd->invalid->null)
456 const INT32 ninvalid = gdi->primary->hdc->hwnd->ninvalid;
457 const GDI_RGN* cinvalid = gdi->primary->hdc->hwnd->cinvalid;
462 std::vector<SDL_Rect> rects;
463 for (INT32 x = 0; x < ninvalid; x++)
465 auto& rgn = cinvalid[x];
466 rects.push_back({ rgn.x, rgn.y, rgn.w, rgn.h });
469 return sdl_draw_to_window(sdl, sdl->windows, rects);
476 static BOOL sdl_end_paint(rdpContext* context)
478 auto sdl = get_context(context);
481 std::lock_guard<CriticalSection> lock(sdl->critical);
482 const BOOL rc = sdl_push_user_event(SDL_EVENT_USER_UPDATE, context);
487 static void sdl_destroy_primary(
SdlContext* sdl)
491 sdl->primary.reset();
495 static BOOL sdl_create_primary(
SdlContext* sdl)
497 rdpGdi* gdi =
nullptr;
501 gdi = sdl->context()->gdi;
504 sdl_destroy_primary(sdl);
506 SDLSurfacePtr(SDL_CreateSurfaceFrom(
static_cast<int>(gdi->width),
507 static_cast<int>(gdi->height), sdl->sdl_pixel_format,
508 gdi->primary_buffer,
static_cast<int>(gdi->stride)),
513 SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE);
514 SDL_Rect surfaceRect = { 0, 0, gdi->width, gdi->height };
515 SDL_FillSurfaceRect(sdl->primary.get(), &surfaceRect,
516 SDL_MapSurfaceRGBA(sdl->primary.get(), 0, 0, 0, 0xff));
521 static BOOL sdl_desktop_resize(rdpContext* context)
523 rdpGdi* gdi =
nullptr;
524 rdpSettings* settings =
nullptr;
525 auto sdl = get_context(context);
528 WINPR_ASSERT(context);
530 settings = context->settings;
531 WINPR_ASSERT(settings);
533 std::lock_guard<CriticalSection> lock(sdl->critical);
538 return sdl_create_primary(sdl);
542 static BOOL sdl_play_sound(rdpContext* context,
const PLAY_SOUND_UPDATE* play_sound)
545 WINPR_UNUSED(context);
546 WINPR_UNUSED(play_sound);
550 static BOOL sdl_wait_for_init(
SdlContext* sdl)
553 sdl->initialize.set();
555 HANDLE handles[] = { sdl->initialized.handle(), freerdp_abort_event(sdl->context()) };
557 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
569 static BOOL sdl_pre_connect(freerdp* instance)
571 WINPR_ASSERT(instance);
572 WINPR_ASSERT(instance->context);
574 auto sdl = get_context(instance->context);
576 auto settings = instance->context->settings;
577 WINPR_ASSERT(settings);
592 PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler);
593 PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
594 sdl_OnChannelDisconnectedEventHandler);
599 UINT32 maxHeight = 0;
601 if (!sdl_wait_for_init(sdl))
604 std::lock_guard<CriticalSection> lock(sdl->critical);
606 sdl->connection_dialog = std::make_unique<SDLConnectionDialog>(instance->context);
607 if (sdl->connection_dialog)
609 sdl->connection_dialog->setTitle(
"Connecting to '%s'",
611 sdl->connection_dialog->showInfo(
612 "The connection is being established\n\nPlease wait...");
614 if (!sdl_detect_monitors(sdl, &maxWidth, &maxHeight))
617 if ((maxWidth != 0) && (maxHeight != 0) &&
620 WLog_Print(sdl->log, WLOG_INFO,
"Update size to %ux%u", maxWidth, maxHeight);
632 WLog_Print(sdl->log, WLOG_INFO,
"auth-only, but no password set. Please provide one.");
639 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only. Don't connect SDL.");
646 static const char* sdl_window_get_title(rdpSettings* settings)
648 const char* windowTitle =
nullptr;
651 const char* name =
nullptr;
652 const char* prefix =
"FreeRDP:";
664 addPort = (port != 3389);
666 char buffer[MAX_PATH + 64] = {};
669 sprintf_s(buffer,
sizeof(buffer),
"%s %s", prefix, name);
671 sprintf_s(buffer,
sizeof(buffer),
"%s %s:%" PRIu32, prefix, name, port);
678 static void sdl_term_handler(
int signum,
const char* signame,
void* context)
688 std::lock_guard<CriticalSection> lock(sdl->critical);
689 sdl->windows.clear();
690 sdl->connection_dialog.reset();
692 sdl_destroy_primary(sdl);
694 freerdp_del_signal_cleanup_handler(sdl->context(), sdl_term_handler);
699 static BOOL sdl_create_windows(
SdlContext* sdl)
703 auto settings = sdl->context()->settings;
704 auto title = sdl_window_get_title(settings);
708 for (UINT32 x = 0; x < windowCount; x++)
710 auto id = sdl_monitor_id_for_index(sdl, x);
715 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
717 Uint32 w = monitor->width;
718 Uint32 h = monitor->height;
727 auto startupX = SDL_WINDOWPOS_CENTERED_DISPLAY(
id);
728 auto startupY = SDL_WINDOWPOS_CENTERED_DISPLAY(
id);
730 if (monitor->attributes.desktopScaleFactor > 100)
732 flags |= SDL_WINDOW_HIGH_PIXEL_DENSITY;
738 flags |= SDL_WINDOW_FULLSCREEN;
743 flags |= SDL_WINDOW_BORDERLESS;
747 flags |= SDL_WINDOW_BORDERLESS;
750 static_cast<int>(startupX),
751 static_cast<int>(startupY),
755 ScopeGuard guard1([&]() { sdl->windows_created.set(); });
756 if (!window.window())
761 auto r = window.rect();
762 window.setOffsetX(0 - r.x);
763 window.setOffsetY(0 - r.y);
766 sdl->windows.insert({ window.id(), std::move(window) });
772 static BOOL sdl_wait_create_windows(
SdlContext* sdl)
774 std::lock_guard<CriticalSection> lock(sdl->critical);
775 sdl->windows_created.clear();
776 if (!sdl_push_user_event(SDL_EVENT_USER_CREATE_WINDOWS, sdl))
779 HANDLE handles[] = { sdl->initialized.handle(), freerdp_abort_event(sdl->context()) };
781 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
793 std::lock_guard<CriticalSection> lock(sdl->critical);
794 if (freerdp_shall_disconnect_context(sdl->context()))
796 if (sdl->rdp_thread_running)
798 if (!sdl->connection_dialog)
800 return !sdl->connection_dialog->running();
810 HANDLE handles[] = { sdl->initialize.handle(), freerdp_abort_event(sdl->context()) };
811 const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
820 SDL_Init(SDL_INIT_VIDEO);
822 SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED,
"0");
823 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR,
"0");
825 freerdp_add_signal_cleanup_handler(sdl->context(), sdl_term_handler);
827 sdl->initialized.set();
829 while (!shall_abort(sdl))
831 SDL_Event windowEvent = {};
832 while (!shall_abort(sdl) && SDL_WaitEventTimeout(
nullptr, 1000))
837 const int prc = SDL_PeepEvents(&windowEvent, 1, SDL_GETEVENT, SDL_EVENT_FIRST,
838 SDL_EVENT_USER_RETRY_DIALOG);
841 if (sdl_log_error(prc, sdl->log,
"SDL_PeepEvents"))
845 #if defined(WITH_DEBUG_SDL_EVENTS)
846 SDL_Log(
"got event %s [0x%08" PRIx32
"]", sdl_event_type_str(windowEvent.type),
849 std::lock_guard<CriticalSection> lock(sdl->critical);
852 if (freerdp_shall_disconnect_context(sdl->context()))
855 if (sdl->connection_dialog)
857 if (sdl->connection_dialog->handle(windowEvent))
863 switch (windowEvent.type)
866 freerdp_abort_connect_context(sdl->context());
868 case SDL_EVENT_KEY_DOWN:
869 case SDL_EVENT_KEY_UP:
871 const SDL_KeyboardEvent* ev = &windowEvent.key;
872 sdl->input.keyboard_handle_event(ev);
875 case SDL_EVENT_KEYMAP_CHANGED:
879 case SDL_EVENT_MOUSE_MOTION:
881 const SDL_MouseMotionEvent* ev = &windowEvent.motion;
882 sdl_handle_mouse_motion(sdl, ev);
885 case SDL_EVENT_MOUSE_BUTTON_DOWN:
886 case SDL_EVENT_MOUSE_BUTTON_UP:
888 const SDL_MouseButtonEvent* ev = &windowEvent.button;
889 sdl_handle_mouse_button(sdl, ev);
892 case SDL_EVENT_MOUSE_WHEEL:
894 const SDL_MouseWheelEvent* ev = &windowEvent.wheel;
895 sdl_handle_mouse_wheel(sdl, ev);
898 case SDL_EVENT_FINGER_DOWN:
900 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
901 sdl_handle_touch_down(sdl, ev);
904 case SDL_EVENT_FINGER_UP:
906 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
907 sdl_handle_touch_up(sdl, ev);
910 case SDL_EVENT_FINGER_MOTION:
912 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
913 sdl_handle_touch_motion(sdl, ev);
917 case SDL_EVENT_RENDER_TARGETS_RESET:
920 case SDL_EVENT_RENDER_DEVICE_RESET:
923 case SDL_EVENT_WILL_ENTER_FOREGROUND:
926 case SDL_EVENT_USER_CERT_DIALOG:
928 auto title =
static_cast<const char*
>(windowEvent.user.data1);
929 auto msg =
static_cast<const char*
>(windowEvent.user.data2);
930 sdl_cert_dialog_show(title, msg);
933 case SDL_EVENT_USER_SHOW_DIALOG:
935 auto title =
static_cast<const char*
>(windowEvent.user.data1);
936 auto msg =
static_cast<const char*
>(windowEvent.user.data2);
937 sdl_message_dialog_show(title, msg, windowEvent.user.code);
940 case SDL_EVENT_USER_SCARD_DIALOG:
942 auto title =
static_cast<const char*
>(windowEvent.user.data1);
943 auto msg =
static_cast<const char**
>(windowEvent.user.data2);
944 sdl_scard_dialog_show(title, windowEvent.user.code, msg);
947 case SDL_EVENT_USER_AUTH_DIALOG:
948 sdl_auth_dialog_show(
951 case SDL_EVENT_USER_UPDATE:
953 auto context =
static_cast<rdpContext*
>(windowEvent.user.data1);
954 sdl_end_paint_process(context);
957 case SDL_EVENT_USER_CREATE_WINDOWS:
959 auto ctx =
static_cast<SdlContext*
>(windowEvent.user.data1);
960 sdl_create_windows(ctx);
963 case SDL_EVENT_USER_WINDOW_RESIZEABLE:
965 auto window =
static_cast<SdlWindow*
>(windowEvent.user.data1);
966 const bool use = windowEvent.user.code != 0;
968 window->resizeable(use);
971 case SDL_EVENT_USER_WINDOW_FULLSCREEN:
973 auto window =
static_cast<SdlWindow*
>(windowEvent.user.data1);
974 const bool enter = windowEvent.user.code != 0;
976 window->fullscreen(enter);
979 case SDL_EVENT_USER_WINDOW_MINIMIZE:
980 for (
auto& window : sdl->windows)
982 window.second.minimize();
985 case SDL_EVENT_USER_POINTER_NULL:
988 case SDL_EVENT_USER_POINTER_DEFAULT:
990 SDL_Cursor* def = SDL_GetDefaultCursor();
995 case SDL_EVENT_USER_POINTER_POSITION:
998 static_cast<INT32
>(
reinterpret_cast<uintptr_t
>(windowEvent.user.data1));
1000 static_cast<INT32
>(
reinterpret_cast<uintptr_t
>(windowEvent.user.data2));
1002 SDL_Window* window = SDL_GetMouseFocus();
1005 const Uint32
id = SDL_GetWindowID(window);
1009 if (sdl_scale_coordinates(sdl,
id, &sx, &sy, FALSE, FALSE))
1010 SDL_WarpMouseInWindow(window,
static_cast<float>(sx),
1011 static_cast<float>(sy));
1015 case SDL_EVENT_USER_POINTER_SET:
1016 sdl_Pointer_Set_Process(&windowEvent.user);
1018 case SDL_EVENT_CLIPBOARD_UPDATE:
1019 sdl->clip.handle_update(windowEvent.clipboard);
1021 case SDL_EVENT_USER_QUIT:
1023 if ((windowEvent.type >= SDL_EVENT_DISPLAY_FIRST) &&
1024 (windowEvent.type <= SDL_EVENT_DISPLAY_LAST))
1026 const SDL_DisplayEvent* ev = &windowEvent.display;
1027 sdl->disp.handle_display_event(ev);
1029 else if ((windowEvent.type >= SDL_EVENT_WINDOW_FIRST) &&
1030 (windowEvent.type <= SDL_EVENT_WINDOW_LAST))
1032 const SDL_WindowEvent* ev = &windowEvent.window;
1033 auto window = sdl->windows.find(ev->windowID);
1034 if (window != sdl->windows.end())
1036 sdl->disp.handle_window_event(ev);
1040 case SDL_EVENT_WINDOW_RESIZED:
1041 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
1042 window->second.fill();
1043 window->second.updateSurface();
1045 case SDL_EVENT_WINDOW_MOVED:
1047 auto r = window->second.rect();
1048 auto id = window->second.id();
1049 WLog_DBG(SDL_TAG,
"%lu: %dx%d-%dx%d",
id, r.x, r.y, r.w, r.h);
1064 sdl_cleanup_sdl(sdl);
1076 static BOOL sdl_post_connect(freerdp* instance)
1078 WINPR_ASSERT(instance);
1080 auto context = instance->context;
1081 WINPR_ASSERT(context);
1083 auto sdl = get_context(context);
1086 sdl_hide_connection_dialog(sdl);
1093 WLog_Print(sdl->log, WLOG_INFO,
"auth-only, but no password set. Please provide one.");
1097 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only. Don't connect to X.");
1101 if (!sdl_wait_create_windows(sdl))
1104 sdl->sdl_pixel_format = SDL_PIXELFORMAT_BGRA32;
1105 if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
1108 if (!sdl_create_primary(sdl))
1111 if (!sdl_register_pointer(instance->context->graphics))
1114 WINPR_ASSERT(context->update);
1116 context->update->BeginPaint = sdl_begin_paint;
1117 context->update->EndPaint = sdl_end_paint;
1118 context->update->PlaySound = sdl_play_sound;
1119 context->update->DesktopResize = sdl_desktop_resize;
1120 context->update->SetKeyboardIndicators = sdlInput::keyboard_set_indicators;
1121 context->update->SetKeyboardImeStatus = sdlInput::keyboard_set_ime_status;
1123 sdl->update_resizeable(FALSE);
1132 static void sdl_post_disconnect(freerdp* instance)
1137 if (!instance->context)
1140 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
1141 sdl_OnChannelConnectedEventHandler);
1142 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
1143 sdl_OnChannelDisconnectedEventHandler);
1147 static void sdl_post_final_disconnect(freerdp* instance)
1152 if (!instance->context)
1156 static void sdl_client_cleanup(
SdlContext* sdl,
int exit_code,
const std::string& error_msg)
1160 rdpContext* context = sdl->context();
1161 WINPR_ASSERT(context);
1162 rdpSettings* settings = context->settings;
1163 WINPR_ASSERT(settings);
1165 sdl->rdp_thread_running =
false;
1166 bool showError =
false;
1168 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only, exit status %s [%" PRId32
"]",
1169 sdl_map_to_code_tag(exit_code), exit_code);
1174 case SDL_EXIT_SUCCESS:
1175 case SDL_EXIT_DISCONNECT:
1176 case SDL_EXIT_LOGOFF:
1177 case SDL_EXIT_DISCONNECT_BY_USER:
1178 case SDL_EXIT_CONNECT_CANCELLED:
1182 std::lock_guard<CriticalSection> lock(sdl->critical);
1183 if (sdl->connection_dialog && !error_msg.empty())
1185 sdl->connection_dialog->showError(error_msg.c_str());
1194 sdl_hide_connection_dialog(sdl);
1196 sdl->exit_code = exit_code;
1197 sdl_push_user_event(SDL_EVENT_USER_QUIT);
1201 static int sdl_client_thread_connect(
SdlContext* sdl, std::string& error_msg)
1205 auto instance = sdl->context()->instance;
1206 WINPR_ASSERT(instance);
1208 sdl->rdp_thread_running =
true;
1209 BOOL rc = freerdp_connect(instance);
1211 rdpContext* context = sdl->context();
1212 rdpSettings* settings = context->settings;
1213 WINPR_ASSERT(settings);
1215 int exit_code = SDL_EXIT_SUCCESS;
1218 UINT32 error = freerdp_get_last_error(context);
1219 exit_code = sdl_map_error_to_exit_code(error);
1224 DWORD code = freerdp_get_last_error(context);
1225 freerdp_abort_connect_context(context);
1226 WLog_Print(sdl->log, WLOG_ERROR,
"Authentication only, %s [0x%08" PRIx32
"] %s",
1227 freerdp_get_last_error_name(code), code, freerdp_get_last_error_string(code));
1233 DWORD code = freerdp_error_info(instance);
1234 if (exit_code == SDL_EXIT_SUCCESS)
1236 char* msg =
nullptr;
1238 exit_code = error_info_to_error(instance, &code, &msg, &len);
1244 auto last = freerdp_get_last_error(context);
1245 if (error_msg.empty())
1247 char* msg =
nullptr;
1249 winpr_asprintf(&msg, &len,
"%s [0x%08" PRIx32
"]\n%s",
1250 freerdp_get_last_error_name(last), last,
1251 freerdp_get_last_error_string(last));
1257 if (exit_code == SDL_EXIT_SUCCESS)
1259 if (last == FREERDP_ERROR_AUTHENTICATION_FAILED)
1260 exit_code = SDL_EXIT_AUTH_FAILURE;
1261 else if (code == ERRINFO_SUCCESS)
1262 exit_code = SDL_EXIT_CONN_FAILED;
1265 sdl_hide_connection_dialog(sdl);
1271 static int sdl_client_thread_run(
SdlContext* sdl, std::string& error_msg)
1275 auto context = sdl->context();
1276 WINPR_ASSERT(context);
1278 auto instance = context->instance;
1279 WINPR_ASSERT(instance);
1281 int exit_code = SDL_EXIT_SUCCESS;
1282 while (!freerdp_shall_disconnect_context(context))
1284 HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {};
1290 if (freerdp_focus_required(instance))
1292 auto ctx = get_context(context);
1294 if (!ctx->input.keyboard_focus_in())
1296 if (!ctx->input.keyboard_focus_in())
1300 const DWORD nCount = freerdp_get_event_handles(context, handles, ARRAYSIZE(handles));
1304 WLog_Print(sdl->log, WLOG_ERROR,
"freerdp_get_event_handles failed");
1308 const DWORD status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
1310 if (status == WAIT_FAILED)
1313 if (!freerdp_check_event_handles(context))
1315 if (client_auto_reconnect(instance))
1318 sdl_hide_connection_dialog(sdl);
1327 if (freerdp_error_info(instance) == 0)
1328 exit_code = SDL_EXIT_CONN_FAILED;
1331 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1332 WLog_Print(sdl->log, WLOG_ERROR,
"WaitForMultipleObjects failed with %" PRIu32
"",
1334 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1335 WLog_Print(sdl->log, WLOG_ERROR,
"Failed to check FreeRDP event handles");
1340 if (exit_code == SDL_EXIT_SUCCESS)
1344 char* emsg =
nullptr;
1346 exit_code = error_info_to_error(instance, &code, &emsg, &elen);
1352 if ((code == ERRINFO_LOGOFF_BY_USER) &&
1353 (freerdp_get_disconnect_ultimatum(context) == Disconnect_Ultimatum_user_requested))
1355 const char* msg =
"Error info says user did not initiate but disconnect ultimatum says "
1356 "they did; treat this as a user logoff";
1358 char* emsg =
nullptr;
1360 winpr_asprintf(&emsg, &elen,
"%s", msg);
1366 WLog_Print(sdl->log, WLOG_INFO,
"%s", msg);
1367 exit_code = SDL_EXIT_LOGOFF;
1371 freerdp_disconnect(instance);
1379 static DWORD WINAPI sdl_client_thread_proc(
SdlContext* sdl)
1383 std::string error_msg;
1384 int exit_code = sdl_client_thread_connect(sdl, error_msg);
1385 if (exit_code == SDL_EXIT_SUCCESS)
1386 exit_code = sdl_client_thread_run(sdl, error_msg);
1387 sdl_client_cleanup(sdl, exit_code, error_msg);
1389 return static_cast<DWORD
>(exit_code);
1395 static BOOL sdl_client_global_init()
1399 const DWORD wVersionRequested = MAKEWORD(1, 1);
1400 const int rc = WSAStartup(wVersionRequested, &wsaData);
1403 WLog_ERR(SDL_TAG,
"WSAStartup failed with %s [%d]", gai_strerrorA(rc), rc);
1408 if (freerdp_handle_signals() != 0)
1415 static void sdl_client_global_uninit()
1422 static BOOL sdl_client_new(freerdp* instance, rdpContext* context)
1426 if (!instance || !context)
1433 instance->PreConnect = sdl_pre_connect;
1434 instance->PostConnect = sdl_post_connect;
1435 instance->PostDisconnect = sdl_post_disconnect;
1436 instance->PostFinalDisconnect = sdl_post_final_disconnect;
1437 instance->AuthenticateEx = sdl_authenticate_ex;
1438 instance->VerifyCertificateEx = sdl_verify_certificate_ex;
1439 instance->VerifyChangedCertificateEx = sdl_verify_changed_certificate_ex;
1440 instance->LogonErrorInfo = sdl_logon_error_info;
1441 instance->PresentGatewayMessage = sdl_present_gateway_message;
1442 instance->ChooseSmartcard = sdl_choose_smartcard;
1443 instance->RetryDialog = sdl_retry_dialog;
1446 instance->GetAccessToken = sdl_webview_get_access_token;
1448 instance->GetAccessToken = client_cli_get_access_token;
1455 static void sdl_client_free(freerdp* instance, rdpContext* context)
1465 static int sdl_client_start(rdpContext* context)
1467 auto sdl = get_context(context);
1470 sdl->thread = std::thread(sdl_client_thread_proc, sdl);
1474 static int sdl_client_stop(rdpContext* context)
1476 auto sdl = get_context(context);
1481 HANDLE
event = freerdp_abort_event(context);
1482 if (!SetEvent(event))
1489 static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
1491 WINPR_ASSERT(pEntryPoints);
1493 ZeroMemory(pEntryPoints,
sizeof(RDP_CLIENT_ENTRY_POINTS));
1494 pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
1495 pEntryPoints->Size =
sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
1496 pEntryPoints->GlobalInit = sdl_client_global_init;
1497 pEntryPoints->GlobalUninit = sdl_client_global_uninit;
1499 pEntryPoints->ClientNew = sdl_client_new;
1500 pEntryPoints->ClientFree = sdl_client_free;
1501 pEntryPoints->ClientStart = sdl_client_start;
1502 pEntryPoints->ClientStop = sdl_client_stop;
1509 freerdp_client_context_free(&sdl->common.context);
1512 static const char* category2str(
int category)
1516 case SDL_LOG_CATEGORY_APPLICATION:
1517 return "SDL_LOG_CATEGORY_APPLICATION";
1518 case SDL_LOG_CATEGORY_ERROR:
1519 return "SDL_LOG_CATEGORY_ERROR";
1520 case SDL_LOG_CATEGORY_ASSERT:
1521 return "SDL_LOG_CATEGORY_ASSERT";
1522 case SDL_LOG_CATEGORY_SYSTEM:
1523 return "SDL_LOG_CATEGORY_SYSTEM";
1524 case SDL_LOG_CATEGORY_AUDIO:
1525 return "SDL_LOG_CATEGORY_AUDIO";
1526 case SDL_LOG_CATEGORY_VIDEO:
1527 return "SDL_LOG_CATEGORY_VIDEO";
1528 case SDL_LOG_CATEGORY_RENDER:
1529 return "SDL_LOG_CATEGORY_RENDER";
1530 case SDL_LOG_CATEGORY_INPUT:
1531 return "SDL_LOG_CATEGORY_INPUT";
1532 case SDL_LOG_CATEGORY_TEST:
1533 return "SDL_LOG_CATEGORY_TEST";
1534 case SDL_LOG_CATEGORY_GPU:
1535 return "SDL_LOG_CATEGORY_GPU";
1536 case SDL_LOG_CATEGORY_RESERVED2:
1537 return "SDL_LOG_CATEGORY_RESERVED2";
1538 case SDL_LOG_CATEGORY_RESERVED3:
1539 return "SDL_LOG_CATEGORY_RESERVED3";
1540 case SDL_LOG_CATEGORY_RESERVED4:
1541 return "SDL_LOG_CATEGORY_RESERVED4";
1542 case SDL_LOG_CATEGORY_RESERVED5:
1543 return "SDL_LOG_CATEGORY_RESERVED5";
1544 case SDL_LOG_CATEGORY_RESERVED6:
1545 return "SDL_LOG_CATEGORY_RESERVED6";
1546 case SDL_LOG_CATEGORY_RESERVED7:
1547 return "SDL_LOG_CATEGORY_RESERVED7";
1548 case SDL_LOG_CATEGORY_RESERVED8:
1549 return "SDL_LOG_CATEGORY_RESERVED8";
1550 case SDL_LOG_CATEGORY_RESERVED9:
1551 return "SDL_LOG_CATEGORY_RESERVED9";
1552 case SDL_LOG_CATEGORY_RESERVED10:
1553 return "SDL_LOG_CATEGORY_RESERVED10";
1554 case SDL_LOG_CATEGORY_CUSTOM:
1556 return "SDL_LOG_CATEGORY_CUSTOM";
1560 static SDL_LogPriority wloglevel2dl(DWORD level)
1565 return SDL_LOG_PRIORITY_VERBOSE;
1567 return SDL_LOG_PRIORITY_DEBUG;
1569 return SDL_LOG_PRIORITY_INFO;
1571 return SDL_LOG_PRIORITY_WARN;
1573 return SDL_LOG_PRIORITY_ERROR;
1575 return SDL_LOG_PRIORITY_CRITICAL;
1578 return SDL_LOG_PRIORITY_VERBOSE;
1582 static DWORD sdlpriority2wlog(SDL_LogPriority priority)
1584 DWORD level = WLOG_OFF;
1587 case SDL_LOG_PRIORITY_VERBOSE:
1590 case SDL_LOG_PRIORITY_DEBUG:
1593 case SDL_LOG_PRIORITY_INFO:
1596 case SDL_LOG_PRIORITY_WARN:
1599 case SDL_LOG_PRIORITY_ERROR:
1602 case SDL_LOG_PRIORITY_CRITICAL:
1612 static void SDLCALL winpr_LogOutputFunction(
void* userdata,
int category, SDL_LogPriority priority,
1613 const char* message)
1615 auto sdl =
static_cast<SdlContext*
>(userdata);
1618 const DWORD level = sdlpriority2wlog(priority);
1619 auto log = sdl->log;
1620 if (!WLog_IsLevelActive(log, level))
1623 WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, __LINE__, __FILE__, __func__,
"[%s] %s",
1624 category2str(category), message);
1627 int main(
int argc,
char* argv[])
1631 RDP_CLIENT_ENTRY_POINTS clientEntryPoints = {};
1633 freerdp_client_warn_experimental(argc, argv);
1635 RdpClientEntry(&clientEntryPoints);
1637 reinterpret_cast<sdl_rdp_context*
>(freerdp_client_context_new(&clientEntryPoints)),
1642 auto sdl = sdl_rdp->sdl;
1644 auto settings = sdl->context()->settings;
1645 WINPR_ASSERT(settings);
1647 status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
1650 rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
1652 sdl_list_monitors(sdl);
1657 case COMMAND_LINE_STATUS_PRINT:
1658 case COMMAND_LINE_STATUS_PRINT_VERSION:
1659 case COMMAND_LINE_STATUS_PRINT_BUILDCONFIG:
1661 case COMMAND_LINE_STATUS_PRINT_HELP:
1663 SdlPref::print_config_file_help(3);
1670 SDL_SetLogOutputFunction(winpr_LogOutputFunction, sdl);
1671 auto level = WLog_GetLogLevel(sdl->log);
1672 SDL_SetLogPriorities(wloglevel2dl(level));
1674 auto context = sdl->context();
1675 WINPR_ASSERT(context);
1677 if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
1680 if (freerdp_client_start(context) != 0)
1685 if (freerdp_client_stop(context) != 0)
1688 if (sdl->exit_code != 0)
1689 rc = sdl->exit_code;
1694 BOOL SdlContext::update_fullscreen(BOOL enter)
1696 std::lock_guard<CriticalSection> lock(critical);
1697 for (
const auto& window : windows)
1699 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter))
1706 BOOL SdlContext::update_minimize()
1708 std::lock_guard<CriticalSection> lock(critical);
1709 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE))
1714 BOOL SdlContext::update_resizeable(BOOL enable)
1716 std::lock_guard<CriticalSection> lock(critical);
1718 const auto settings = context()->settings;
1721 BOOL use = (dyn && enable) || smart;
1723 for (
const auto& window : windows)
1725 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1733 SdlContext::SdlContext(rdpContext* context)
1734 : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1735 clip(this), primary(nullptr, SDL_DestroySurface), rdp_thread_running(false)
1737 WINPR_ASSERT(context);
1741 rdpContext* SdlContext::context()
const
1746 rdpClientContext* SdlContext::common()
const
1748 return reinterpret_cast<rdpClientContext*
>(_context);
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_string(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param)
Sets a string settings value. The param is copied.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API const char * freerdp_settings_get_server_name(const rdpSettings *settings)
A helper function to return the correct server name.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.