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>
43#include <winpr/config.h>
44#include <winpr/assert.h>
45#include <winpr/synch.h>
46#include <freerdp/log.h>
49#if !defined(__MINGW32__)
50#include <SDL3/SDL_main.h>
52#include <SDL3/SDL_hints.h>
53#include <SDL3/SDL_video.h>
54#include <SDL3/SDL_oldnames.h>
56#include "sdl_channels.hpp"
57#include "sdl_freerdp.hpp"
58#include "sdl_utils.hpp"
59#include "sdl_disp.hpp"
60#include "sdl_monitor.hpp"
62#include "sdl_touch.hpp"
63#include "sdl_pointer.hpp"
64#include "sdl_prefs.hpp"
65#include "dialogs/sdl_dialogs.hpp"
66#include "dialogs/sdl_connection_dialog_hider.hpp"
67#include "scoped_guard.hpp"
69#include <aad/sdl_webview.hpp>
71#define SDL_TAG CLIENT_TAG("SDL")
77 SDL_EXIT_DISCONNECT = 1,
79 SDL_EXIT_IDLE_TIMEOUT = 3,
80 SDL_EXIT_LOGON_TIMEOUT = 4,
81 SDL_EXIT_CONN_REPLACED = 5,
82 SDL_EXIT_OUT_OF_MEMORY = 6,
83 SDL_EXIT_CONN_DENIED = 7,
84 SDL_EXIT_CONN_DENIED_FIPS = 8,
85 SDL_EXIT_USER_PRIVILEGES = 9,
86 SDL_EXIT_FRESH_CREDENTIALS_REQUIRED = 10,
87 SDL_EXIT_DISCONNECT_BY_USER = 11,
90 SDL_EXIT_LICENSE_INTERNAL = 16,
91 SDL_EXIT_LICENSE_NO_LICENSE_SERVER = 17,
92 SDL_EXIT_LICENSE_NO_LICENSE = 18,
93 SDL_EXIT_LICENSE_BAD_CLIENT_MSG = 19,
94 SDL_EXIT_LICENSE_HWID_DOESNT_MATCH = 20,
95 SDL_EXIT_LICENSE_BAD_CLIENT = 21,
96 SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22,
97 SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23,
98 SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24,
99 SDL_EXIT_LICENSE_CANT_UPGRADE = 25,
100 SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26,
106 SDL_EXIT_PARSE_ARGUMENTS = 128,
107 SDL_EXIT_MEMORY = 129,
108 SDL_EXIT_PROTOCOL = 130,
109 SDL_EXIT_CONN_FAILED = 131,
110 SDL_EXIT_AUTH_FAILURE = 132,
111 SDL_EXIT_NEGO_FAILURE = 133,
112 SDL_EXIT_LOGON_FAILURE = 134,
113 SDL_EXIT_ACCOUNT_LOCKED_OUT = 135,
114 SDL_EXIT_PRE_CONNECT_FAILED = 136,
115 SDL_EXIT_CONNECT_UNDEFINED = 137,
116 SDL_EXIT_POST_CONNECT_FAILED = 138,
117 SDL_EXIT_DNS_ERROR = 139,
118 SDL_EXIT_DNS_NAME_NOT_FOUND = 140,
119 SDL_EXIT_CONNECT_FAILED = 141,
120 SDL_EXIT_MCS_CONNECT_INITIAL_ERROR = 142,
121 SDL_EXIT_TLS_CONNECT_FAILED = 143,
122 SDL_EXIT_INSUFFICIENT_PRIVILEGES = 144,
123 SDL_EXIT_CONNECT_CANCELLED = 145,
125 SDL_EXIT_CONNECT_TRANSPORT_FAILED = 147,
126 SDL_EXIT_CONNECT_PASSWORD_EXPIRED = 148,
127 SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE = 149,
128 SDL_EXIT_CONNECT_KDC_UNREACHABLE = 150,
129 SDL_EXIT_CONNECT_ACCOUNT_DISABLED = 151,
130 SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
131 SDL_EXIT_CONNECT_CLIENT_REVOKED = 153,
132 SDL_EXIT_CONNECT_WRONG_PASSWORD = 154,
133 SDL_EXIT_CONNECT_ACCESS_DENIED = 155,
134 SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION = 156,
135 SDL_EXIT_CONNECT_ACCOUNT_EXPIRED = 157,
136 SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
137 SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
139 SDL_EXIT_UNKNOWN = 255,
142struct sdl_exit_code_map_t
146 const char* code_tag;
149#define ENTRY(x, y) { x, y, #y }
150static const struct sdl_exit_code_map_t sdl_exit_code_map[] = {
151 ENTRY(FREERDP_ERROR_SUCCESS, SDL_EXIT_SUCCESS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_DISCONNECT),
152 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGOFF), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_IDLE_TIMEOUT),
153 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGON_TIMEOUT),
154 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_REPLACED),
155 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_OUT_OF_MEMORY),
156 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED),
157 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED_FIPS),
158 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_USER_PRIVILEGES),
159 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_FRESH_CREDENTIALS_REQUIRED),
160 ENTRY(ERRINFO_LOGOFF_BY_USER, SDL_EXIT_DISCONNECT_BY_USER),
161 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_UNKNOWN),
164 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_INTERNAL),
165 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE_SERVER),
166 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE),
167 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_MSG),
168 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_HWID_DOESNT_MATCH),
169 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT),
170 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL),
171 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL),
172 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION),
173 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
174 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS),
175 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
178 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_RDP),
181 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PARSE_ARGUMENTS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_MEMORY),
182 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PROTOCOL), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_FAILED),
184 ENTRY(FREERDP_ERROR_AUTHENTICATION_FAILED, SDL_EXIT_AUTH_FAILURE),
185 ENTRY(FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, SDL_EXIT_NEGO_FAILURE),
186 ENTRY(FREERDP_ERROR_CONNECT_LOGON_FAILURE, SDL_EXIT_LOGON_FAILURE),
187 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, SDL_EXIT_ACCOUNT_LOCKED_OUT),
188 ENTRY(FREERDP_ERROR_PRE_CONNECT_FAILED, SDL_EXIT_PRE_CONNECT_FAILED),
189 ENTRY(FREERDP_ERROR_CONNECT_UNDEFINED, SDL_EXIT_CONNECT_UNDEFINED),
190 ENTRY(FREERDP_ERROR_POST_CONNECT_FAILED, SDL_EXIT_POST_CONNECT_FAILED),
191 ENTRY(FREERDP_ERROR_DNS_ERROR, SDL_EXIT_DNS_ERROR),
192 ENTRY(FREERDP_ERROR_DNS_NAME_NOT_FOUND, SDL_EXIT_DNS_NAME_NOT_FOUND),
193 ENTRY(FREERDP_ERROR_CONNECT_FAILED, SDL_EXIT_CONNECT_FAILED),
194 ENTRY(FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, SDL_EXIT_MCS_CONNECT_INITIAL_ERROR),
195 ENTRY(FREERDP_ERROR_TLS_CONNECT_FAILED, SDL_EXIT_TLS_CONNECT_FAILED),
196 ENTRY(FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, SDL_EXIT_INSUFFICIENT_PRIVILEGES),
197 ENTRY(FREERDP_ERROR_CONNECT_CANCELLED, SDL_EXIT_CONNECT_CANCELLED),
198 ENTRY(FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, SDL_EXIT_CONNECT_TRANSPORT_FAILED),
199 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, SDL_EXIT_CONNECT_PASSWORD_EXPIRED),
200 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE),
201 ENTRY(FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, SDL_EXIT_CONNECT_KDC_UNREACHABLE),
202 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, SDL_EXIT_CONNECT_ACCOUNT_DISABLED),
203 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED,
204 SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED),
205 ENTRY(FREERDP_ERROR_CONNECT_CLIENT_REVOKED, SDL_EXIT_CONNECT_CLIENT_REVOKED),
206 ENTRY(FREERDP_ERROR_CONNECT_WRONG_PASSWORD, SDL_EXIT_CONNECT_WRONG_PASSWORD),
207 ENTRY(FREERDP_ERROR_CONNECT_ACCESS_DENIED, SDL_EXIT_CONNECT_ACCESS_DENIED),
208 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION),
209 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, SDL_EXIT_CONNECT_ACCOUNT_EXPIRED),
210 ENTRY(FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED),
211 ENTRY(FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS,
212 SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS)
215static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(
int exit_code)
217 for (
const auto& x : sdl_exit_code_map)
219 const struct sdl_exit_code_map_t* cur = &x;
220 if (cur->code == exit_code)
226static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(UINT32 error)
228 for (
const auto& x : sdl_exit_code_map)
230 const struct sdl_exit_code_map_t* cur = &x;
231 if (cur->error == error)
237static int sdl_map_error_to_exit_code(DWORD error)
239 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
243 return SDL_EXIT_CONN_FAILED;
246static const char* sdl_map_error_to_code_tag(UINT32 error)
248 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
250 return entry->code_tag;
254static const char* sdl_map_to_code_tag(
int code)
256 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_code(code);
258 return entry->code_tag;
262static int error_info_to_error(freerdp* instance, DWORD* pcode,
char** msg,
size_t* len)
264 const DWORD code = freerdp_error_info(instance);
265 const char* name = freerdp_get_error_info_name(code);
266 const char* str = freerdp_get_error_info_string(code);
267 const int exit_code = sdl_map_error_to_exit_code(code);
269 winpr_asprintf(msg, len,
"Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32
"]: %s",
270 sdl_map_error_to_code_tag(code), name, code, str);
271 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"%s", *msg);
279static BOOL sdl_begin_paint(rdpContext* context)
281 auto gdi = context->gdi;
283 WINPR_ASSERT(gdi->primary);
284 WINPR_ASSERT(gdi->primary->hdc);
285 WINPR_ASSERT(gdi->primary->hdc->hwnd);
286 WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
287 gdi->primary->hdc->hwnd->invalid->null = TRUE;
288 gdi->primary->hdc->hwnd->ninvalid = 0;
294 SDL_Surface* surface, SDL_Point offset,
const SDL_Rect& srcRect)
296 WINPR_ASSERT(surface);
297 SDL_Rect dstRect = { offset.x + srcRect.x, offset.y + srcRect.y, srcRect.w, srcRect.h };
298 return window.blit(surface, srcRect, dstRect);
301static bool sdl_draw_to_window_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
302 SDL_Point offset,
const std::vector<SDL_Rect>& rects = {})
306 return sdl_draw_to_window_rect(sdl, window, surface, offset,
307 { 0, 0, surface->w, surface->h });
309 for (
auto& srcRect : rects)
311 if (!sdl_draw_to_window_rect(sdl, window, surface, offset, srcRect))
317static bool sdl_draw_to_window_scaled_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
318 const SDL_Rect& srcRect)
320 SDL_Rect dstRect = srcRect;
321 sdl_scale_coordinates(sdl, window.id(), &dstRect.x, &dstRect.y, FALSE, TRUE);
322 sdl_scale_coordinates(sdl, window.id(), &dstRect.w, &dstRect.h, FALSE, TRUE);
323 return window.blit(surface, srcRect, dstRect);
326static BOOL sdl_draw_to_window_scaled_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
327 const std::vector<SDL_Rect>& rects = {})
331 return sdl_draw_to_window_scaled_rect(sdl, window, surface,
332 { 0, 0, surface->w, surface->h });
334 for (
const auto& srcRect : rects)
336 if (!sdl_draw_to_window_scaled_rect(sdl, window, surface, srcRect))
343 const std::vector<SDL_Rect>& rects = {})
347 if (!sdl->isConnected())
350 auto context = sdl->context();
351 auto gdi = context->gdi;
354 auto size = window.rect();
358 window.setOffsetX(0);
359 window.setOffsetY(0);
360 if (gdi->width < size.w)
362 window.setOffsetX((size.w - gdi->width) / 2);
364 if (gdi->height < size.h)
366 window.setOffsetY((size.h - gdi->height) / 2);
369 auto surface = sdl->primary.get();
370 if (!sdl_draw_to_window_rect(sdl, window, surface, { window.offsetX(), window.offsetY() },
376 if (!sdl_draw_to_window_scaled_rect(sdl, window, sdl->primary.get(), rects))
379 window.updateSurface();
383static BOOL sdl_draw_to_window(
SdlContext* sdl, std::map<Uint32, SdlWindow>& windows,
384 const std::vector<SDL_Rect>& rects = {})
386 for (
auto& window : windows)
388 if (!sdl_draw_to_window(sdl, window.second, rects))
399static BOOL sdl_end_paint(rdpContext* context)
401 auto sdl = get_context(context);
404 auto gdi = context->gdi;
406 WINPR_ASSERT(gdi->primary);
407 WINPR_ASSERT(gdi->primary->hdc);
408 WINPR_ASSERT(gdi->primary->hdc->hwnd);
409 WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
410 if (gdi->suppressOutput || gdi->primary->hdc->hwnd->invalid->null)
413 const INT32 ninvalid = gdi->primary->hdc->hwnd->ninvalid;
414 const GDI_RGN* cinvalid = gdi->primary->hdc->hwnd->cinvalid;
419 std::vector<SDL_Rect> rects;
420 for (INT32 x = 0; x < ninvalid; x++)
422 auto& rgn = cinvalid[x];
423 rects.push_back({ rgn.x, rgn.y, rgn.w, rgn.h });
426 sdl->push(std::move(rects));
427 return sdl_push_user_event(SDL_EVENT_USER_UPDATE);
430static void sdl_destroy_primary(
SdlContext* sdl)
434 sdl->primary.reset();
438static BOOL sdl_create_primary(
SdlContext* sdl)
440 rdpGdi* gdi =
nullptr;
444 gdi = sdl->context()->gdi;
447 sdl_destroy_primary(sdl);
449 SDLSurfacePtr(SDL_CreateSurfaceFrom(
static_cast<int>(gdi->width),
450 static_cast<int>(gdi->height), sdl->sdl_pixel_format,
451 gdi->primary_buffer,
static_cast<int>(gdi->stride)),
456 SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE);
457 SDL_Rect surfaceRect = { 0, 0, gdi->width, gdi->height };
458 SDL_FillSurfaceRect(sdl->primary.get(), &surfaceRect,
459 SDL_MapSurfaceRGBA(sdl->primary.get(), 0, 0, 0, 0xff));
464static BOOL sdl_desktop_resize(rdpContext* context)
466 rdpGdi* gdi =
nullptr;
467 rdpSettings* settings =
nullptr;
468 auto sdl = get_context(context);
471 WINPR_ASSERT(context);
473 settings = context->settings;
474 WINPR_ASSERT(settings);
476 std::lock_guard<CriticalSection> lock(sdl->critical);
481 return sdl_create_primary(sdl);
485static BOOL sdl_play_sound(rdpContext* context,
const PLAY_SOUND_UPDATE* play_sound)
488 WINPR_UNUSED(context);
489 WINPR_UNUSED(play_sound);
496 sdl->initialize.set();
498 HANDLE handles[] = { sdl->initialized.handle(), freerdp_abort_event(sdl->context()) };
500 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
512static BOOL sdl_pre_connect(freerdp* instance)
514 WINPR_ASSERT(instance);
515 WINPR_ASSERT(instance->context);
517 auto sdl = get_context(instance->context);
519 auto settings = instance->context->settings;
520 WINPR_ASSERT(settings);
535 PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler);
536 PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
537 sdl_OnChannelDisconnectedEventHandler);
542 UINT32 maxHeight = 0;
544 if (!sdl_wait_for_init(sdl))
547 if (!sdl_detect_monitors(sdl, &maxWidth, &maxHeight))
550 if ((maxWidth != 0) && (maxHeight != 0) &&
553 WLog_Print(sdl->log, WLOG_INFO,
"Update size to %ux%u", maxWidth, maxHeight);
565 WLog_Print(sdl->log, WLOG_INFO,
"auth-only, but no password set. Please provide one.");
572 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only. Don't connect SDL.");
575 if (!sdl->input.initialize())
582static const char* sdl_window_get_title(rdpSettings* settings)
584 const char* windowTitle =
nullptr;
587 const char* name =
nullptr;
588 const char* prefix =
"FreeRDP:";
600 addPort = (port != 3389);
602 char buffer[MAX_PATH + 64] = {};
605 (void)sprintf_s(buffer,
sizeof(buffer),
"%s %s", prefix, name);
607 (
void)sprintf_s(buffer,
sizeof(buffer),
"%s %s:%" PRIu32, prefix, name, port);
614static void sdl_term_handler([[maybe_unused]]
int signum, [[maybe_unused]]
const char* signame,
615 [[maybe_unused]]
void* context)
625 std::lock_guard<CriticalSection> lock(sdl->critical);
626 sdl->windows.clear();
627 sdl->dialog.destroy();
629 sdl_destroy_primary(sdl);
631 freerdp_del_signal_cleanup_handler(sdl->context(), sdl_term_handler);
632 sdl_dialogs_uninit();
636static BOOL sdl_create_windows(
SdlContext* sdl)
640 auto settings = sdl->context()->settings;
641 auto title = sdl_window_get_title(settings);
645 for (UINT32 x = 0; x < windowCount; x++)
647 auto id = sdl->monitorId(x);
652 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
654 auto w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
655 auto h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
663 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
664 auto startupX = SDL_WINDOWPOS_CENTERED_DISPLAY(
id);
665 auto startupY = SDL_WINDOWPOS_CENTERED_DISPLAY(
id);
670 flags |= SDL_WINDOW_FULLSCREEN;
675 flags |= SDL_WINDOW_BORDERLESS;
679 flags |= SDL_WINDOW_BORDERLESS;
682 static_cast<int>(startupX),
683 static_cast<int>(startupY),
687 ScopeGuard guard1([&]() { sdl->windows_created.set(); });
688 if (!window.window())
693 auto r = window.rect();
694 window.setOffsetX(0 - r.x);
695 window.setOffsetY(0 - r.y);
698 sdl->windows.insert({ window.id(), std::move(window) });
704static BOOL sdl_wait_create_windows(
SdlContext* sdl)
707 std::unique_lock<CriticalSection> lock(sdl->critical);
708 sdl->windows_created.clear();
709 if (!sdl_push_user_event(SDL_EVENT_USER_CREATE_WINDOWS, sdl))
713 HANDLE handles[] = { sdl->windows_created.handle(), freerdp_abort_event(sdl->context()) };
715 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
727 std::lock_guard<CriticalSection> lock(sdl->critical);
728 if (freerdp_shall_disconnect_context(sdl->context()))
730 if (sdl->rdp_thread_running)
732 return !sdl->dialog.isRunning();
742 HANDLE handles[] = { sdl->initialize.handle(), freerdp_abort_event(sdl->context()) };
743 const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
752 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
755 SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED,
"0");
756 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR,
"0");
758 freerdp_add_signal_cleanup_handler(sdl->context(), sdl_term_handler);
759 sdl->dialog.create(sdl->context());
760 sdl->dialog.setTitle(
"Connecting to '%s'",
762 sdl->dialog.showInfo(
"The connection is being established\n\nPlease wait...");
765 sdl->dialog.show(
true);
768 sdl->initialized.set();
770 while (!shall_abort(sdl))
772 SDL_Event windowEvent = {};
773 while (!shall_abort(sdl) && SDL_WaitEventTimeout(
nullptr, 1000))
778 const int prc = SDL_PeepEvents(&windowEvent, 1, SDL_GETEVENT, SDL_EVENT_FIRST,
779 SDL_EVENT_USER_RETRY_DIALOG);
782 if (sdl_log_error(prc, sdl->log,
"SDL_PeepEvents"))
786#if defined(WITH_DEBUG_SDL_EVENTS)
787 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"got event %s [0x%08" PRIx32
"]",
788 sdl_event_type_str(windowEvent.type), windowEvent.type);
791 std::lock_guard<CriticalSection> lock(sdl->critical);
794 if (freerdp_shall_disconnect_context(sdl->context()))
798 if (sdl->dialog.handleEvent(windowEvent))
803 auto point2pix = [](Uint32 win_id,
float& x,
float& y)
805 auto win = SDL_GetWindowFromID(win_id);
808 auto scale = SDL_GetWindowDisplayScale(win);
815 switch (windowEvent.type)
818 freerdp_abort_connect_context(sdl->context());
820 case SDL_EVENT_KEY_DOWN:
821 case SDL_EVENT_KEY_UP:
823 const SDL_KeyboardEvent* ev = &windowEvent.key;
824 sdl->input.keyboard_handle_event(ev);
827 case SDL_EVENT_KEYMAP_CHANGED:
831 case SDL_EVENT_MOUSE_MOTION:
833 SDL_MouseMotionEvent& ev = windowEvent.motion;
834 point2pix(ev.windowID, ev.x, ev.y);
835 point2pix(ev.windowID, ev.xrel, ev.yrel);
836 sdl_handle_mouse_motion(sdl, &ev);
839 case SDL_EVENT_MOUSE_BUTTON_DOWN:
840 case SDL_EVENT_MOUSE_BUTTON_UP:
842 SDL_MouseButtonEvent& ev = windowEvent.button;
843 point2pix(ev.windowID, ev.x, ev.y);
844 sdl_handle_mouse_button(sdl, &ev);
847 case SDL_EVENT_MOUSE_WHEEL:
849 const SDL_MouseWheelEvent* ev = &windowEvent.wheel;
850 sdl_handle_mouse_wheel(sdl, ev);
853 case SDL_EVENT_FINGER_DOWN:
855 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
856 sdl_handle_touch_down(sdl, ev);
859 case SDL_EVENT_FINGER_UP:
861 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
862 sdl_handle_touch_up(sdl, ev);
865 case SDL_EVENT_FINGER_MOTION:
867 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
868 sdl_handle_touch_motion(sdl, ev);
872 case SDL_EVENT_RENDER_TARGETS_RESET:
875 case SDL_EVENT_RENDER_DEVICE_RESET:
878 case SDL_EVENT_WILL_ENTER_FOREGROUND:
881 case SDL_EVENT_USER_CERT_DIALOG:
884 auto title =
static_cast<const char*
>(windowEvent.user.data1);
885 auto msg =
static_cast<const char*
>(windowEvent.user.data2);
886 sdl_cert_dialog_show(title, msg);
889 case SDL_EVENT_USER_SHOW_DIALOG:
892 auto title =
static_cast<const char*
>(windowEvent.user.data1);
893 auto msg =
static_cast<const char*
>(windowEvent.user.data2);
894 sdl_message_dialog_show(title, msg, windowEvent.user.code);
897 case SDL_EVENT_USER_SCARD_DIALOG:
900 auto title =
static_cast<const char*
>(windowEvent.user.data1);
901 auto msg =
static_cast<const char**
>(windowEvent.user.data2);
902 sdl_scard_dialog_show(title, windowEvent.user.code, msg);
905 case SDL_EVENT_USER_AUTH_DIALOG:
908 sdl_auth_dialog_show(
912 case SDL_EVENT_USER_UPDATE:
914 std::vector<SDL_Rect> rectangles;
917 rectangles = sdl->pop();
918 sdl_draw_to_window(sdl, sdl->windows, rectangles);
919 }
while (!rectangles.empty());
922 case SDL_EVENT_USER_CREATE_WINDOWS:
924 auto ctx =
static_cast<SdlContext*
>(windowEvent.user.data1);
925 sdl_create_windows(ctx);
928 case SDL_EVENT_USER_WINDOW_RESIZEABLE:
930 auto window =
static_cast<SdlWindow*
>(windowEvent.user.data1);
931 const bool use = windowEvent.user.code != 0;
933 window->resizeable(use);
936 case SDL_EVENT_USER_WINDOW_FULLSCREEN:
938 auto window =
static_cast<SdlWindow*
>(windowEvent.user.data1);
939 const bool enter = windowEvent.user.code != 0;
941 window->fullscreen(enter);
944 case SDL_EVENT_USER_WINDOW_MINIMIZE:
945 for (
auto& window : sdl->windows)
947 window.second.minimize();
950 case SDL_EVENT_USER_POINTER_NULL:
952 sdl->setCursor(
nullptr);
953 sdl->setHasCursor(
false);
955 case SDL_EVENT_USER_POINTER_DEFAULT:
957 SDL_Cursor* def = SDL_GetDefaultCursor();
960 sdl->setCursor(
nullptr);
961 sdl->setHasCursor(
true);
964 case SDL_EVENT_USER_POINTER_POSITION:
967 static_cast<INT32
>(
reinterpret_cast<uintptr_t
>(windowEvent.user.data1));
969 static_cast<INT32
>(
reinterpret_cast<uintptr_t
>(windowEvent.user.data2));
971 SDL_Window* window = SDL_GetMouseFocus();
974 const Uint32
id = SDL_GetWindowID(window);
978 if (sdl_scale_coordinates(sdl,
id, &sx, &sy, FALSE, FALSE))
979 SDL_WarpMouseInWindow(window,
static_cast<float>(sx),
980 static_cast<float>(sy));
984 case SDL_EVENT_USER_POINTER_SET:
985 sdl->setCursor(
static_cast<rdpPointer*
>(windowEvent.user.data1));
986 sdl_Pointer_Set_Process(sdl);
988 case SDL_EVENT_CLIPBOARD_UPDATE:
989 sdl->clip.handle_update(windowEvent.clipboard);
991 case SDL_EVENT_USER_QUIT:
993 if ((windowEvent.type >= SDL_EVENT_DISPLAY_FIRST) &&
994 (windowEvent.type <= SDL_EVENT_DISPLAY_LAST))
996 const SDL_DisplayEvent* ev = &windowEvent.display;
997 (void)sdl->disp.handle_display_event(ev);
999 else if ((windowEvent.type >= SDL_EVENT_WINDOW_FIRST) &&
1000 (windowEvent.type <= SDL_EVENT_WINDOW_LAST))
1002 const SDL_WindowEvent* ev = &windowEvent.window;
1003 auto window = sdl->windows.find(ev->windowID);
1004 if (window != sdl->windows.end())
1006 (void)sdl->disp.handle_window_event(ev);
1010 case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
1011 if (sdl->isConnected())
1013 sdl_Pointer_Set_Process(sdl);
1015 sdl->context()->settings,
1016 FreeRDP_DynamicResolutionUpdate))
1020 auto win = window->second.window();
1023 [[maybe_unused]]
auto rcpix =
1024 SDL_GetWindowSizeInPixels(win, &w_pix, &h_pix);
1026 auto scale = SDL_GetWindowDisplayScale(win);
1027 if (scale <= SDL_FLT_EPSILON)
1029 auto err = SDL_GetError();
1031 SDL_LOG_CATEGORY_APPLICATION,
1032 "SDL_GetWindowDisplayScale() failed with %s", err);
1036 assert(SDL_isnanf(scale) == 0);
1037 assert(SDL_isinff(scale) == 0);
1038 assert(scale > SDL_FLT_EPSILON);
1039 auto w_gdi = sdl->context()->gdi->width;
1040 auto h_gdi = sdl->context()->gdi->height;
1041 auto pix2point = [=](
int pix)
1043 return static_cast<int>(
static_cast<float>(pix) /
1046 if (w_pix != w_gdi || h_pix != h_gdi)
1048 const auto ssws = SDL_SetWindowSize(
1049 win, pix2point(w_gdi), pix2point(h_gdi));
1052 auto err = SDL_GetError();
1054 SDL_LOG_CATEGORY_APPLICATION,
1055 "SDL_SetWindowSize() failed with %s", err);
1061 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
1062 window->second.fill();
1063 sdl_draw_to_window(sdl, window->second);
1064 sdl_Pointer_Set_Process(sdl);
1066 case SDL_EVENT_WINDOW_MOVED:
1068 auto r = window->second.rect();
1069 auto id = window->second.id();
1070 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"%u: %dx%d-%dx%d",
1071 id, r.x, r.y, r.w, r.h);
1074 case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
1076 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
1077 "Window closed, terminating RDP session...");
1078 freerdp_abort_connect_context(sdl->context());
1093 sdl_cleanup_sdl(sdl);
1105static BOOL sdl_post_connect(freerdp* instance)
1107 WINPR_ASSERT(instance);
1109 auto context = instance->context;
1110 WINPR_ASSERT(context);
1112 auto sdl = get_context(context);
1115 sdl->dialog.show(
false);
1122 WLog_Print(sdl->log, WLOG_INFO,
"auth-only, but no password set. Please provide one.");
1126 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only. Don't connect to X.");
1130 if (!sdl_wait_create_windows(sdl))
1133 sdl->sdl_pixel_format = SDL_PIXELFORMAT_BGRA32;
1134 if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
1137 if (!sdl_create_primary(sdl))
1140 if (!sdl_register_pointer(instance->context->graphics))
1143 WINPR_ASSERT(context->update);
1145 context->update->BeginPaint = sdl_begin_paint;
1146 context->update->EndPaint = sdl_end_paint;
1147 context->update->PlaySound = sdl_play_sound;
1148 context->update->DesktopResize = sdl_desktop_resize;
1149 context->update->SetKeyboardIndicators = sdlInput::keyboard_set_indicators;
1150 context->update->SetKeyboardImeStatus = sdlInput::keyboard_set_ime_status;
1152 if (!sdl->update_resizeable(
false))
1157 sdl->setConnected(
true);
1164static void sdl_post_disconnect(freerdp* instance)
1169 if (!instance->context)
1172 auto sdl = get_context(instance->context);
1173 sdl->setConnected(
false);
1175 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
1176 sdl_OnChannelConnectedEventHandler);
1177 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
1178 sdl_OnChannelDisconnectedEventHandler);
1182static void sdl_post_final_disconnect(freerdp* instance)
1187 if (!instance->context)
1191static void sdl_client_cleanup(
SdlContext* sdl,
int exit_code,
const std::string& error_msg)
1195 rdpContext* context = sdl->context();
1196 WINPR_ASSERT(context);
1197 rdpSettings* settings = context->settings;
1198 WINPR_ASSERT(settings);
1200 sdl->rdp_thread_running =
false;
1201 bool showError =
false;
1203 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only, exit status %s [%" PRId32
"]",
1204 sdl_map_to_code_tag(exit_code), exit_code);
1209 case SDL_EXIT_SUCCESS:
1210 case SDL_EXIT_DISCONNECT:
1211 case SDL_EXIT_LOGOFF:
1212 case SDL_EXIT_DISCONNECT_BY_USER:
1213 case SDL_EXIT_CONNECT_CANCELLED:
1217 sdl->dialog.showError(error_msg);
1224 sdl->dialog.show(
false);
1226 sdl->exit_code = exit_code;
1227 sdl_push_user_event(SDL_EVENT_USER_QUIT);
1231static int sdl_client_thread_connect(
SdlContext* sdl, std::string& error_msg)
1235 auto instance = sdl->context()->instance;
1236 WINPR_ASSERT(instance);
1238 sdl->rdp_thread_running =
true;
1239 BOOL rc = freerdp_connect(instance);
1241 rdpContext* context = sdl->context();
1242 rdpSettings* settings = context->settings;
1243 WINPR_ASSERT(settings);
1245 int exit_code = SDL_EXIT_SUCCESS;
1248 UINT32 error = freerdp_get_last_error(context);
1249 exit_code = sdl_map_error_to_exit_code(error);
1254 DWORD code = freerdp_get_last_error(context);
1255 freerdp_abort_connect_context(context);
1256 WLog_Print(sdl->log, WLOG_ERROR,
"Authentication only, %s [0x%08" PRIx32
"] %s",
1257 freerdp_get_last_error_name(code), code, freerdp_get_last_error_string(code));
1263 DWORD code = freerdp_error_info(instance);
1264 if (exit_code == SDL_EXIT_SUCCESS)
1266 char* msg =
nullptr;
1268 exit_code = error_info_to_error(instance, &code, &msg, &len);
1274 auto last = freerdp_get_last_error(context);
1275 if (error_msg.empty())
1277 char* msg =
nullptr;
1279 winpr_asprintf(&msg, &len,
"%s [0x%08" PRIx32
"]\n%s",
1280 freerdp_get_last_error_name(last), last,
1281 freerdp_get_last_error_string(last));
1287 if (exit_code == SDL_EXIT_SUCCESS)
1289 if (last == FREERDP_ERROR_AUTHENTICATION_FAILED)
1290 exit_code = SDL_EXIT_AUTH_FAILURE;
1291 else if (code == ERRINFO_SUCCESS)
1292 exit_code = SDL_EXIT_CONN_FAILED;
1295 sdl->dialog.show(
false);
1301static int sdl_client_thread_run(
SdlContext* sdl, std::string& error_msg)
1305 auto context = sdl->context();
1306 WINPR_ASSERT(context);
1308 auto instance = context->instance;
1309 WINPR_ASSERT(instance);
1311 int exit_code = SDL_EXIT_SUCCESS;
1312 while (!freerdp_shall_disconnect_context(context))
1314 HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {};
1320 if (freerdp_focus_required(instance))
1322 auto ctx = get_context(context);
1324 if (!ctx->input.keyboard_focus_in())
1326 if (!ctx->input.keyboard_focus_in())
1330 const DWORD nCount = freerdp_get_event_handles(context, handles, ARRAYSIZE(handles));
1334 WLog_Print(sdl->log, WLOG_ERROR,
"freerdp_get_event_handles failed");
1338 const DWORD status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
1340 if (status == WAIT_FAILED)
1343 if (!freerdp_check_event_handles(context))
1345 if (client_auto_reconnect(instance))
1348 sdl->dialog.show(
false);
1357 if (freerdp_error_info(instance) == 0)
1358 exit_code = SDL_EXIT_CONN_FAILED;
1361 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1362 WLog_Print(sdl->log, WLOG_ERROR,
"WaitForMultipleObjects failed with %" PRIu32
"",
1364 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1365 WLog_Print(sdl->log, WLOG_ERROR,
"Failed to check FreeRDP event handles");
1370 if (exit_code == SDL_EXIT_SUCCESS)
1374 char* emsg =
nullptr;
1376 exit_code = error_info_to_error(instance, &code, &emsg, &elen);
1382 if ((code == ERRINFO_LOGOFF_BY_USER) &&
1383 (freerdp_get_disconnect_ultimatum(context) == Disconnect_Ultimatum_user_requested))
1385 const char* msg =
"Error info says user did not initiate but disconnect ultimatum says "
1386 "they did; treat this as a user logoff";
1388 char* emsg =
nullptr;
1390 winpr_asprintf(&emsg, &elen,
"%s", msg);
1396 WLog_Print(sdl->log, WLOG_INFO,
"%s", msg);
1397 exit_code = SDL_EXIT_LOGOFF;
1401 freerdp_disconnect(instance);
1409static DWORD WINAPI sdl_client_thread_proc(
SdlContext* sdl)
1413 std::string error_msg;
1414 int exit_code = sdl_client_thread_connect(sdl, error_msg);
1415 if (exit_code == SDL_EXIT_SUCCESS)
1416 exit_code = sdl_client_thread_run(sdl, error_msg);
1417 sdl_client_cleanup(sdl, exit_code, error_msg);
1419 return static_cast<DWORD
>(exit_code);
1425static BOOL sdl_client_global_init()
1429 const DWORD wVersionRequested = MAKEWORD(1, 1);
1430 const int rc = WSAStartup(wVersionRequested, &wsaData);
1433 WLog_ERR(SDL_TAG,
"WSAStartup failed with %s [%d]", gai_strerrorA(rc), rc);
1438 return (freerdp_handle_signals() == 0);
1442static void sdl_client_global_uninit()
1449static BOOL sdl_client_new(freerdp* instance, rdpContext* context)
1453 if (!instance || !context)
1460 instance->PreConnect = sdl_pre_connect;
1461 instance->PostConnect = sdl_post_connect;
1462 instance->PostDisconnect = sdl_post_disconnect;
1463 instance->PostFinalDisconnect = sdl_post_final_disconnect;
1464 instance->AuthenticateEx = sdl_authenticate_ex;
1465 instance->VerifyCertificateEx = sdl_verify_certificate_ex;
1466 instance->VerifyChangedCertificateEx = sdl_verify_changed_certificate_ex;
1467 instance->LogonErrorInfo = sdl_logon_error_info;
1468 instance->PresentGatewayMessage = sdl_present_gateway_message;
1469 instance->ChooseSmartcard = sdl_choose_smartcard;
1470 instance->RetryDialog = sdl_retry_dialog;
1473 instance->GetAccessToken = sdl_webview_get_access_token;
1475 instance->GetAccessToken = client_cli_get_access_token;
1482static void sdl_client_free([[maybe_unused]] freerdp* instance, rdpContext* context)
1492static int sdl_client_start(rdpContext* context)
1494 auto sdl = get_context(context);
1497 sdl->thread = std::thread(sdl_client_thread_proc, sdl);
1501static int sdl_client_stop(rdpContext* context)
1503 auto sdl = get_context(context);
1508 HANDLE
event = freerdp_abort_event(context);
1509 if (!SetEvent(event))
1516static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
1518 WINPR_ASSERT(pEntryPoints);
1520 ZeroMemory(pEntryPoints,
sizeof(RDP_CLIENT_ENTRY_POINTS));
1521 pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
1522 pEntryPoints->Size =
sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
1523 pEntryPoints->GlobalInit = sdl_client_global_init;
1524 pEntryPoints->GlobalUninit = sdl_client_global_uninit;
1526 pEntryPoints->ClientNew = sdl_client_new;
1527 pEntryPoints->ClientFree = sdl_client_free;
1528 pEntryPoints->ClientStart = sdl_client_start;
1529 pEntryPoints->ClientStop = sdl_client_stop;
1536 freerdp_client_context_free(&sdl->common.context);
1539static const char* category2str(
int category)
1543 case SDL_LOG_CATEGORY_APPLICATION:
1544 return "SDL_LOG_CATEGORY_APPLICATION";
1545 case SDL_LOG_CATEGORY_ERROR:
1546 return "SDL_LOG_CATEGORY_ERROR";
1547 case SDL_LOG_CATEGORY_ASSERT:
1548 return "SDL_LOG_CATEGORY_ASSERT";
1549 case SDL_LOG_CATEGORY_SYSTEM:
1550 return "SDL_LOG_CATEGORY_SYSTEM";
1551 case SDL_LOG_CATEGORY_AUDIO:
1552 return "SDL_LOG_CATEGORY_AUDIO";
1553 case SDL_LOG_CATEGORY_VIDEO:
1554 return "SDL_LOG_CATEGORY_VIDEO";
1555 case SDL_LOG_CATEGORY_RENDER:
1556 return "SDL_LOG_CATEGORY_RENDER";
1557 case SDL_LOG_CATEGORY_INPUT:
1558 return "SDL_LOG_CATEGORY_INPUT";
1559 case SDL_LOG_CATEGORY_TEST:
1560 return "SDL_LOG_CATEGORY_TEST";
1561 case SDL_LOG_CATEGORY_GPU:
1562 return "SDL_LOG_CATEGORY_GPU";
1563 case SDL_LOG_CATEGORY_RESERVED2:
1564 return "SDL_LOG_CATEGORY_RESERVED2";
1565 case SDL_LOG_CATEGORY_RESERVED3:
1566 return "SDL_LOG_CATEGORY_RESERVED3";
1567 case SDL_LOG_CATEGORY_RESERVED4:
1568 return "SDL_LOG_CATEGORY_RESERVED4";
1569 case SDL_LOG_CATEGORY_RESERVED5:
1570 return "SDL_LOG_CATEGORY_RESERVED5";
1571 case SDL_LOG_CATEGORY_RESERVED6:
1572 return "SDL_LOG_CATEGORY_RESERVED6";
1573 case SDL_LOG_CATEGORY_RESERVED7:
1574 return "SDL_LOG_CATEGORY_RESERVED7";
1575 case SDL_LOG_CATEGORY_RESERVED8:
1576 return "SDL_LOG_CATEGORY_RESERVED8";
1577 case SDL_LOG_CATEGORY_RESERVED9:
1578 return "SDL_LOG_CATEGORY_RESERVED9";
1579 case SDL_LOG_CATEGORY_RESERVED10:
1580 return "SDL_LOG_CATEGORY_RESERVED10";
1581 case SDL_LOG_CATEGORY_CUSTOM:
1583 return "SDL_LOG_CATEGORY_CUSTOM";
1587static SDL_LogPriority wloglevel2dl(DWORD level)
1592 return SDL_LOG_PRIORITY_VERBOSE;
1594 return SDL_LOG_PRIORITY_DEBUG;
1596 return SDL_LOG_PRIORITY_INFO;
1598 return SDL_LOG_PRIORITY_WARN;
1600 return SDL_LOG_PRIORITY_ERROR;
1602 return SDL_LOG_PRIORITY_CRITICAL;
1605 return SDL_LOG_PRIORITY_VERBOSE;
1609static DWORD sdlpriority2wlog(SDL_LogPriority priority)
1611 DWORD level = WLOG_OFF;
1614 case SDL_LOG_PRIORITY_VERBOSE:
1617 case SDL_LOG_PRIORITY_DEBUG:
1620 case SDL_LOG_PRIORITY_INFO:
1623 case SDL_LOG_PRIORITY_WARN:
1626 case SDL_LOG_PRIORITY_ERROR:
1629 case SDL_LOG_PRIORITY_CRITICAL:
1639static void SDLCALL winpr_LogOutputFunction(
void* userdata,
int category, SDL_LogPriority priority,
1640 const char* message)
1642 auto sdl =
static_cast<SdlContext*
>(userdata);
1645 const DWORD level = sdlpriority2wlog(priority);
1646 auto log = sdl->log;
1647 if (!WLog_IsLevelActive(log, level))
1650 WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, __LINE__, __FILE__, __func__,
"[%s] %s",
1651 category2str(category), message);
1654int main(
int argc,
char* argv[])
1658 RDP_CLIENT_ENTRY_POINTS clientEntryPoints = {};
1660 RdpClientEntry(&clientEntryPoints);
1662 reinterpret_cast<sdl_rdp_context*
>(freerdp_client_context_new(&clientEntryPoints)),
1667 auto sdl = sdl_rdp->sdl;
1669 auto settings = sdl->context()->settings;
1670 WINPR_ASSERT(settings);
1672 status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
1675 rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
1677 sdl_list_monitors(sdl);
1682 case COMMAND_LINE_STATUS_PRINT:
1683 case COMMAND_LINE_STATUS_PRINT_VERSION:
1684 case COMMAND_LINE_STATUS_PRINT_BUILDCONFIG:
1686 case COMMAND_LINE_STATUS_PRINT_HELP:
1688 SdlPref::print_config_file_help(3);
1695 SDL_SetLogOutputFunction(winpr_LogOutputFunction, sdl);
1696 auto level = WLog_GetLogLevel(sdl->log);
1697 SDL_SetLogPriorities(wloglevel2dl(level));
1699 auto context = sdl->context();
1700 WINPR_ASSERT(context);
1702 if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
1705 if (freerdp_client_start(context) != 0)
1710 if (freerdp_client_stop(context) != 0)
1713 if (sdl->exit_code != 0)
1714 rc = sdl->exit_code;
1719bool SdlContext::update_fullscreen(
bool enter)
1721 for (
const auto& window : windows)
1723 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter))
1730bool SdlContext::update_minimize()
1732 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1735bool SdlContext::update_resizeable(
bool enable)
1737 const auto settings = context()->settings;
1740 bool use = (dyn && enable) || smart;
1742 for (
const auto& window : windows)
1744 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1752SdlContext::SdlContext(rdpContext* context)
1753 : _context(context), log(WLog_Get(SDL_TAG)), disp(this), input(this), clip(this),
1754 primary(nullptr, SDL_DestroySurface), rdp_thread_running(false)
1756 WINPR_ASSERT(context);
1759void SdlContext::setHasCursor(
bool val)
1761 this->_cursor_visible = val;
1764bool SdlContext::hasCursor()
const
1766 return _cursor_visible;
1769bool SdlContext::redraw(
bool suppress)
const
1774 auto gdi = context()->gdi;
1776 return gdi_send_suppress_output(gdi, suppress);
1779void SdlContext::setConnected(
bool val)
1784bool SdlContext::isConnected()
const
1789rdpContext* SdlContext::context()
const
1791 WINPR_ASSERT(_context);
1795rdpClientContext* SdlContext::common()
const
1797 return reinterpret_cast<rdpClientContext*
>(context());
1800void SdlContext::setCursor(rdpPointer* cursor)
1805rdpPointer* SdlContext::cursor()
const
1810void SdlContext::setMonitorIds(
const std::vector<SDL_DisplayID>& ids)
1812 _monitorIds.clear();
1815 _monitorIds.push_back(
id);
1819const std::vector<SDL_DisplayID>& SdlContext::monitorIds()
const
1824int64_t SdlContext::monitorId(uint32_t index)
const
1826 if (index >= _monitorIds.size())
1830 return _monitorIds[index];
1833void SdlContext::push(std::vector<SDL_Rect>&& rects)
1835 std::unique_lock lock(_queue_mux);
1836 _queue.emplace(std::move(rects));
1839std::vector<SDL_Rect> SdlContext::pop()
1841 std::unique_lock lock(_queue_mux);
1846 auto val = std::move(_queue.front());
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_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 const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.