24#include <freerdp/config.h>
30#include <freerdp/constants.h>
31#include <freerdp/freerdp.h>
32#include <freerdp/gdi/gdi.h>
33#include <freerdp/streamdump.h>
34#include <freerdp/utils/signal.h>
36#include <freerdp/channels/channels.h>
37#include <freerdp/client/channels.h>
38#include <freerdp/client/cliprdr.h>
39#include <freerdp/client/cmdline.h>
40#include <freerdp/client/file.h>
42#include <freerdp/log.h>
43#include <winpr/assert.h>
44#include <winpr/config.h>
46#include <winpr/synch.h>
49#if !defined(__MINGW32__)
50#include <SDL3/SDL_main.h>
52#include <SDL3/SDL_hints.h>
53#include <SDL3/SDL_oldnames.h>
54#include <SDL3/SDL_video.h>
56#include <sdl_config.hpp>
58#include "dialogs/sdl_connection_dialog_hider.hpp"
59#include "dialogs/sdl_dialogs.hpp"
60#include "scoped_guard.hpp"
61#include "sdl_channels.hpp"
62#include "sdl_disp.hpp"
63#include "sdl_freerdp.hpp"
65#include "sdl_monitor.hpp"
66#include "sdl_pointer.hpp"
67#include "sdl_prefs.hpp"
68#include "sdl_touch.hpp"
69#include "sdl_utils.hpp"
71#if defined(WITH_WEBVIEW)
72#include <aad/sdl_webview.hpp>
75#define SDL_TAG CLIENT_TAG("SDL")
81 SDL_EXIT_DISCONNECT = 1,
83 SDL_EXIT_IDLE_TIMEOUT = 3,
84 SDL_EXIT_LOGON_TIMEOUT = 4,
85 SDL_EXIT_CONN_REPLACED = 5,
86 SDL_EXIT_OUT_OF_MEMORY = 6,
87 SDL_EXIT_CONN_DENIED = 7,
88 SDL_EXIT_CONN_DENIED_FIPS = 8,
89 SDL_EXIT_USER_PRIVILEGES = 9,
90 SDL_EXIT_FRESH_CREDENTIALS_REQUIRED = 10,
91 SDL_EXIT_DISCONNECT_BY_USER = 11,
94 SDL_EXIT_LICENSE_INTERNAL = 16,
95 SDL_EXIT_LICENSE_NO_LICENSE_SERVER = 17,
96 SDL_EXIT_LICENSE_NO_LICENSE = 18,
97 SDL_EXIT_LICENSE_BAD_CLIENT_MSG = 19,
98 SDL_EXIT_LICENSE_HWID_DOESNT_MATCH = 20,
99 SDL_EXIT_LICENSE_BAD_CLIENT = 21,
100 SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22,
101 SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23,
102 SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24,
103 SDL_EXIT_LICENSE_CANT_UPGRADE = 25,
104 SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26,
110 SDL_EXIT_PARSE_ARGUMENTS = 128,
111 SDL_EXIT_MEMORY = 129,
112 SDL_EXIT_PROTOCOL = 130,
113 SDL_EXIT_CONN_FAILED = 131,
114 SDL_EXIT_AUTH_FAILURE = 132,
115 SDL_EXIT_NEGO_FAILURE = 133,
116 SDL_EXIT_LOGON_FAILURE = 134,
117 SDL_EXIT_ACCOUNT_LOCKED_OUT = 135,
118 SDL_EXIT_PRE_CONNECT_FAILED = 136,
119 SDL_EXIT_CONNECT_UNDEFINED = 137,
120 SDL_EXIT_POST_CONNECT_FAILED = 138,
121 SDL_EXIT_DNS_ERROR = 139,
122 SDL_EXIT_DNS_NAME_NOT_FOUND = 140,
123 SDL_EXIT_CONNECT_FAILED = 141,
124 SDL_EXIT_MCS_CONNECT_INITIAL_ERROR = 142,
125 SDL_EXIT_TLS_CONNECT_FAILED = 143,
126 SDL_EXIT_INSUFFICIENT_PRIVILEGES = 144,
127 SDL_EXIT_CONNECT_CANCELLED = 145,
129 SDL_EXIT_CONNECT_TRANSPORT_FAILED = 147,
130 SDL_EXIT_CONNECT_PASSWORD_EXPIRED = 148,
131 SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE = 149,
132 SDL_EXIT_CONNECT_KDC_UNREACHABLE = 150,
133 SDL_EXIT_CONNECT_ACCOUNT_DISABLED = 151,
134 SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
135 SDL_EXIT_CONNECT_CLIENT_REVOKED = 153,
136 SDL_EXIT_CONNECT_WRONG_PASSWORD = 154,
137 SDL_EXIT_CONNECT_ACCESS_DENIED = 155,
138 SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION = 156,
139 SDL_EXIT_CONNECT_ACCOUNT_EXPIRED = 157,
140 SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
141 SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
142 SDL_EXIT_CONNECT_TARGET_BOOTING = 160,
144 SDL_EXIT_UNKNOWN = 255,
147struct sdl_exit_code_map_t
151 const char* code_tag;
154#define ENTRY(x, y) { x, y, #y }
155static const struct sdl_exit_code_map_t sdl_exit_code_map[] = {
156 ENTRY(FREERDP_ERROR_SUCCESS, SDL_EXIT_SUCCESS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_DISCONNECT),
157 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGOFF), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_IDLE_TIMEOUT),
158 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGON_TIMEOUT),
159 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_REPLACED),
160 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_OUT_OF_MEMORY),
161 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED),
162 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED_FIPS),
163 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_USER_PRIVILEGES),
164 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_FRESH_CREDENTIALS_REQUIRED),
165 ENTRY(ERRINFO_LOGOFF_BY_USER, SDL_EXIT_DISCONNECT_BY_USER),
166 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_UNKNOWN),
169 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_INTERNAL),
170 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE_SERVER),
171 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE),
172 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_MSG),
173 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_HWID_DOESNT_MATCH),
174 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT),
175 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL),
176 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL),
177 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION),
178 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
179 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS),
180 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
183 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_RDP),
186 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PARSE_ARGUMENTS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_MEMORY),
187 ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PROTOCOL), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_FAILED),
189 ENTRY(FREERDP_ERROR_AUTHENTICATION_FAILED, SDL_EXIT_AUTH_FAILURE),
190 ENTRY(FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, SDL_EXIT_NEGO_FAILURE),
191 ENTRY(FREERDP_ERROR_CONNECT_LOGON_FAILURE, SDL_EXIT_LOGON_FAILURE),
192 ENTRY(FREERDP_ERROR_CONNECT_TARGET_BOOTING, SDL_EXIT_CONNECT_TARGET_BOOTING),
193 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, SDL_EXIT_ACCOUNT_LOCKED_OUT),
194 ENTRY(FREERDP_ERROR_PRE_CONNECT_FAILED, SDL_EXIT_PRE_CONNECT_FAILED),
195 ENTRY(FREERDP_ERROR_CONNECT_UNDEFINED, SDL_EXIT_CONNECT_UNDEFINED),
196 ENTRY(FREERDP_ERROR_POST_CONNECT_FAILED, SDL_EXIT_POST_CONNECT_FAILED),
197 ENTRY(FREERDP_ERROR_DNS_ERROR, SDL_EXIT_DNS_ERROR),
198 ENTRY(FREERDP_ERROR_DNS_NAME_NOT_FOUND, SDL_EXIT_DNS_NAME_NOT_FOUND),
199 ENTRY(FREERDP_ERROR_CONNECT_FAILED, SDL_EXIT_CONNECT_FAILED),
200 ENTRY(FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, SDL_EXIT_MCS_CONNECT_INITIAL_ERROR),
201 ENTRY(FREERDP_ERROR_TLS_CONNECT_FAILED, SDL_EXIT_TLS_CONNECT_FAILED),
202 ENTRY(FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, SDL_EXIT_INSUFFICIENT_PRIVILEGES),
203 ENTRY(FREERDP_ERROR_CONNECT_CANCELLED, SDL_EXIT_CONNECT_CANCELLED),
204 ENTRY(FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, SDL_EXIT_CONNECT_TRANSPORT_FAILED),
205 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, SDL_EXIT_CONNECT_PASSWORD_EXPIRED),
206 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE),
207 ENTRY(FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, SDL_EXIT_CONNECT_KDC_UNREACHABLE),
208 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, SDL_EXIT_CONNECT_ACCOUNT_DISABLED),
209 ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED,
210 SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED),
211 ENTRY(FREERDP_ERROR_CONNECT_CLIENT_REVOKED, SDL_EXIT_CONNECT_CLIENT_REVOKED),
212 ENTRY(FREERDP_ERROR_CONNECT_WRONG_PASSWORD, SDL_EXIT_CONNECT_WRONG_PASSWORD),
213 ENTRY(FREERDP_ERROR_CONNECT_ACCESS_DENIED, SDL_EXIT_CONNECT_ACCESS_DENIED),
214 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION),
215 ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, SDL_EXIT_CONNECT_ACCOUNT_EXPIRED),
216 ENTRY(FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED),
217 ENTRY(FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS,
218 SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS)
221static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(
int exit_code)
223 for (
const auto& x : sdl_exit_code_map)
225 const struct sdl_exit_code_map_t* cur = &x;
226 if (cur->code == exit_code)
232static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(UINT32 error)
234 for (
const auto& x : sdl_exit_code_map)
236 const struct sdl_exit_code_map_t* cur = &x;
237 if (cur->error == error)
243static int sdl_map_error_to_exit_code(DWORD error)
245 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
249 return SDL_EXIT_CONN_FAILED;
252static const char* sdl_map_error_to_code_tag(UINT32 error)
254 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
256 return entry->code_tag;
260static const char* sdl_map_to_code_tag(
int code)
262 const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_code(code);
264 return entry->code_tag;
268static int error_info_to_error(freerdp* instance, DWORD* pcode,
char** msg,
size_t* len)
270 const DWORD code = freerdp_error_info(instance);
271 const char* name = freerdp_get_error_info_name(code);
272 const char* str = freerdp_get_error_info_string(code);
273 const int exit_code = sdl_map_error_to_exit_code(code);
275 winpr_asprintf(msg, len,
"Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32
"]: %s",
276 sdl_map_error_to_code_tag(code), name, code, str);
277 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"%s", *msg);
285static BOOL sdl_begin_paint(rdpContext* context)
287 auto gdi = context->gdi;
289 WINPR_ASSERT(gdi->primary);
291 HGDI_DC hdc = gdi->primary->hdc;
297 WINPR_ASSERT(hwnd->invalid);
298 hwnd->invalid->null = TRUE;
305 SDL_Surface* surface, SDL_Point offset,
const SDL_Rect& srcRect)
307 WINPR_ASSERT(surface);
308 SDL_Rect dstRect = { offset.x + srcRect.x, offset.y + srcRect.y, srcRect.w, srcRect.h };
309 return window.blit(surface, srcRect, dstRect);
312static bool sdl_draw_to_window_rect(
SdlContext* sdl,
SdlWindow& window, SDL_Surface* surface,
313 SDL_Point offset,
const std::vector<SDL_Rect>& rects = {})
317 return sdl_draw_to_window_rect(sdl, window, surface, offset,
318 { 0, 0, surface->w, surface->h });
320 for (
auto& srcRect : rects)
322 if (!sdl_draw_to_window_rect(sdl, window, surface, offset, srcRect))
329 const std::vector<SDL_Rect>& rects = {})
333 if (!sdl->isConnected())
336 auto context = sdl->context();
337 auto gdi = context->gdi;
340 auto size = window.rect();
344 window.setOffsetX(0);
345 window.setOffsetY(0);
346 if (gdi->width < size.w)
348 window.setOffsetX((size.w - gdi->width) / 2);
350 if (gdi->height < size.h)
352 window.setOffsetY((size.h - gdi->height) / 2);
355 auto surface = sdl->primary.get();
356 if (!sdl_draw_to_window_rect(sdl, window, surface, { window.offsetX(), window.offsetY() },
359 window.updateSurface();
363static BOOL sdl_draw_to_window(
SdlContext* sdl, std::map<Uint32, SdlWindow>& windows,
364 const std::vector<SDL_Rect>& rects = {})
366 for (
auto& window : windows)
368 if (!sdl_draw_to_window(sdl, window.second, rects))
379static BOOL sdl_end_paint(rdpContext* context)
381 auto sdl = get_context(context);
384 auto gdi = context->gdi;
386 WINPR_ASSERT(gdi->primary);
388 HGDI_DC hdc = gdi->primary->hdc;
394 WINPR_ASSERT(hwnd->invalid || (hwnd->ninvalid == 0));
396 if (hwnd->invalid->null)
399 WINPR_ASSERT(hwnd->invalid);
400 if (gdi->suppressOutput || hwnd->invalid->null)
403 const INT32 ninvalid = hwnd->ninvalid;
404 const GDI_RGN* cinvalid = hwnd->cinvalid;
409 std::vector<SDL_Rect> rects;
410 for (INT32 x = 0; x < ninvalid; x++)
412 auto& rgn = cinvalid[x];
413 rects.push_back({ rgn.x, rgn.y, rgn.w, rgn.h });
416 sdl->push(std::move(rects));
417 return sdl_push_user_event(SDL_EVENT_USER_UPDATE);
420static void sdl_destroy_primary(
SdlContext* sdl)
424 sdl->primary.reset();
428static BOOL sdl_create_primary(
SdlContext* sdl)
430 rdpGdi* gdi =
nullptr;
434 gdi = sdl->context()->gdi;
437 sdl_destroy_primary(sdl);
439 SDLSurfacePtr(SDL_CreateSurfaceFrom(
static_cast<int>(gdi->width),
440 static_cast<int>(gdi->height), sdl->sdl_pixel_format,
441 gdi->primary_buffer,
static_cast<int>(gdi->stride)),
446 SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE);
447 SDL_Rect surfaceRect = { 0, 0, gdi->width, gdi->height };
448 SDL_FillSurfaceRect(sdl->primary.get(), &surfaceRect,
449 SDL_MapSurfaceRGBA(sdl->primary.get(), 0, 0, 0, 0xff));
454static BOOL sdl_desktop_resize(rdpContext* context)
456 rdpGdi* gdi =
nullptr;
457 rdpSettings* settings =
nullptr;
458 auto sdl = get_context(context);
461 WINPR_ASSERT(context);
463 settings = context->settings;
464 WINPR_ASSERT(settings);
466 std::lock_guard<CriticalSection> lock(sdl->critical);
471 return sdl_create_primary(sdl);
475static BOOL sdl_play_sound(rdpContext* context,
const PLAY_SOUND_UPDATE* play_sound)
478 WINPR_UNUSED(context);
479 WINPR_UNUSED(play_sound);
486 sdl->initialize.set();
488 HANDLE handles[] = { sdl->initialized.handle(), freerdp_abort_event(sdl->context()) };
490 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
502static BOOL sdl_pre_connect(freerdp* instance)
504 WINPR_ASSERT(instance);
505 WINPR_ASSERT(instance->context);
507 auto sdl = get_context(instance->context);
509 auto settings = instance->context->settings;
510 WINPR_ASSERT(settings);
525 PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler);
526 PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
527 sdl_OnChannelDisconnectedEventHandler);
532 UINT32 maxHeight = 0;
534 if (!sdl_wait_for_init(sdl))
537 if (!sdl_detect_monitors(sdl, &maxWidth, &maxHeight))
540 if ((maxWidth != 0) && (maxHeight != 0) &&
543 WLog_Print(sdl->log, WLOG_INFO,
"Update size to %ux%u", maxWidth, maxHeight);
555 WLog_Print(sdl->log, WLOG_INFO,
"auth-only, but no password set. Please provide one.");
562 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only. Don't connect SDL.");
565 if (!sdl->input.initialize())
572static const char* sdl_window_get_title(rdpSettings* settings)
574 const char* windowTitle =
nullptr;
577 const char* name =
nullptr;
578 const char* prefix =
"FreeRDP:";
590 addPort = (port != 3389);
592 char buffer[MAX_PATH + 64] = {};
595 (void)sprintf_s(buffer,
sizeof(buffer),
"%s %s", prefix, name);
597 (
void)sprintf_s(buffer,
sizeof(buffer),
"%s %s:%" PRIu32, prefix, name, port);
604static void sdl_term_handler([[maybe_unused]]
int signum, [[maybe_unused]]
const char* signame,
605 [[maybe_unused]]
void* context)
615 std::lock_guard<CriticalSection> lock(sdl->critical);
616 sdl->windows.clear();
617 sdl->dialog.destroy();
619 sdl_destroy_primary(sdl);
621 freerdp_del_signal_cleanup_handler(sdl->context(), sdl_term_handler);
622 sdl_dialogs_uninit();
626static BOOL sdl_create_windows(
SdlContext* sdl)
630 auto settings = sdl->context()->settings;
631 auto title = sdl_window_get_title(settings);
633 ScopeGuard guard1([&]() { sdl->windows_created.set(); });
639 for (UINT32 x = 0; x < windowCount; x++)
641 auto id = sdl->monitorId(x);
646 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
648 originX = std::min<Sint32>(monitor->x, originX);
649 originY = std::min<Sint32>(monitor->y, originY);
652 for (UINT32 x = 0; x < windowCount; x++)
654 auto id = sdl->monitorId(x);
659 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
661 auto w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
662 auto h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
670 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
671 auto startupX = SDL_WINDOWPOS_CENTERED_DISPLAY(
id);
672 auto startupY = SDL_WINDOWPOS_CENTERED_DISPLAY(
id);
677 flags |= SDL_WINDOW_FULLSCREEN;
682 flags |= SDL_WINDOW_BORDERLESS;
686 flags |= SDL_WINDOW_BORDERLESS;
688 char buffer[MAX_PATH + 64] = {};
689 (void)sprintf_s(buffer,
sizeof(buffer),
"%s:%" PRIu32, title, x);
691 static_cast<int>(startupX),
692 static_cast<int>(startupY),
696 if (!window.window())
701 window.setOffsetX(originX - monitor->x);
702 window.setOffsetY(originY - monitor->y);
705 sdl->windows.insert({ window.id(), std::move(window) });
711static BOOL sdl_wait_create_windows(
SdlContext* sdl)
714 std::unique_lock<CriticalSection> lock(sdl->critical);
715 sdl->windows_created.clear();
716 if (!sdl_push_user_event(SDL_EVENT_USER_CREATE_WINDOWS, sdl))
720 HANDLE handles[] = { sdl->windows_created.handle(), freerdp_abort_event(sdl->context()) };
722 const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
734 std::lock_guard<CriticalSection> lock(sdl->critical);
735 if (freerdp_shall_disconnect_context(sdl->context()))
737 if (sdl->rdp_thread_running)
739 return !sdl->dialog.isRunning();
749 HANDLE handles[] = { sdl->initialize.handle(), freerdp_abort_event(sdl->context()) };
750 const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
759 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
760 auto backend = SDL_GetCurrentVideoDriver();
761 WLog_Print(sdl->log, WLOG_DEBUG,
"client is using backend '%s'", backend);
764 SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED,
"0");
765 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR,
"0");
767 freerdp_add_signal_cleanup_handler(sdl->context(), sdl_term_handler);
768 sdl->dialog.create(sdl->context());
769 sdl->dialog.setTitle(
"Connecting to '%s'",
771 sdl->dialog.showInfo(
"The connection is being established\n\nPlease wait...");
774 sdl->dialog.show(
true);
777 sdl->initialized.set();
779 while (!shall_abort(sdl))
781 SDL_Event windowEvent = {};
782 while (!shall_abort(sdl) && SDL_WaitEventTimeout(
nullptr, 1000))
787 const int prc = SDL_PeepEvents(&windowEvent, 1, SDL_GETEVENT, SDL_EVENT_FIRST,
788 SDL_EVENT_USER_RETRY_DIALOG);
791 if (sdl_log_error(prc, sdl->log,
"SDL_PeepEvents"))
795#if defined(WITH_DEBUG_SDL_EVENTS)
796 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"got event %s [0x%08" PRIx32
"]",
797 sdl_event_type_str(windowEvent.type), windowEvent.type);
800 std::lock_guard<CriticalSection> lock(sdl->critical);
803 if (freerdp_shall_disconnect_context(sdl->context()))
807 if (sdl->dialog.handleEvent(windowEvent))
812 auto point2pix = [](Uint32 win_id,
float& x,
float& y)
814 auto win = SDL_GetWindowFromID(win_id);
817 auto scale = SDL_GetWindowDisplayScale(win);
824 switch (windowEvent.type)
827 freerdp_abort_connect_context(sdl->context());
829 case SDL_EVENT_KEY_DOWN:
830 case SDL_EVENT_KEY_UP:
832 const SDL_KeyboardEvent* ev = &windowEvent.key;
833 sdl->input.keyboard_handle_event(ev);
836 case SDL_EVENT_KEYMAP_CHANGED:
840 case SDL_EVENT_MOUSE_MOTION:
842 SDL_MouseMotionEvent& ev = windowEvent.motion;
843 point2pix(ev.windowID, ev.x, ev.y);
844 point2pix(ev.windowID, ev.xrel, ev.yrel);
845 sdl_handle_mouse_motion(sdl, &ev);
848 case SDL_EVENT_MOUSE_BUTTON_DOWN:
849 case SDL_EVENT_MOUSE_BUTTON_UP:
851 SDL_MouseButtonEvent& ev = windowEvent.button;
852 point2pix(ev.windowID, ev.x, ev.y);
853 sdl_handle_mouse_button(sdl, &ev);
856 case SDL_EVENT_MOUSE_WHEEL:
858 const SDL_MouseWheelEvent* ev = &windowEvent.wheel;
859 sdl_handle_mouse_wheel(sdl, ev);
862 case SDL_EVENT_FINGER_DOWN:
864 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
865 sdl_handle_touch_down(sdl, ev);
868 case SDL_EVENT_FINGER_UP:
870 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
871 sdl_handle_touch_up(sdl, ev);
874 case SDL_EVENT_FINGER_MOTION:
876 const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
877 sdl_handle_touch_motion(sdl, ev);
881 case SDL_EVENT_RENDER_TARGETS_RESET:
884 case SDL_EVENT_RENDER_DEVICE_RESET:
887 case SDL_EVENT_WILL_ENTER_FOREGROUND:
890 case SDL_EVENT_USER_CERT_DIALOG:
893 auto title =
static_cast<const char*
>(windowEvent.user.data1);
894 auto msg =
static_cast<const char*
>(windowEvent.user.data2);
895 sdl_cert_dialog_show(title, msg);
898 case SDL_EVENT_USER_SHOW_DIALOG:
901 auto title =
static_cast<const char*
>(windowEvent.user.data1);
902 auto msg =
static_cast<const char*
>(windowEvent.user.data2);
903 sdl_message_dialog_show(title, msg, windowEvent.user.code);
906 case SDL_EVENT_USER_SCARD_DIALOG:
909 auto title =
static_cast<const char*
>(windowEvent.user.data1);
910 auto msg =
static_cast<const char**
>(windowEvent.user.data2);
911 sdl_scard_dialog_show(title, windowEvent.user.code, msg);
914 case SDL_EVENT_USER_AUTH_DIALOG:
917 sdl_auth_dialog_show(
921 case SDL_EVENT_USER_UPDATE:
923 std::vector<SDL_Rect> rectangles;
926 rectangles = sdl->pop();
927 sdl_draw_to_window(sdl, sdl->windows, rectangles);
928 }
while (!rectangles.empty());
931 case SDL_EVENT_USER_CREATE_WINDOWS:
933 auto ctx =
static_cast<SdlContext*
>(windowEvent.user.data1);
934 sdl_create_windows(ctx);
937 case SDL_EVENT_USER_WINDOW_RESIZEABLE:
939 auto window =
static_cast<SdlWindow*
>(windowEvent.user.data1);
940 const bool use = windowEvent.user.code != 0;
942 window->resizeable(use);
945 case SDL_EVENT_USER_WINDOW_FULLSCREEN:
947 auto window =
static_cast<SdlWindow*
>(windowEvent.user.data1);
948 const bool enter = windowEvent.user.code != 0;
950 window->fullscreen(enter);
953 case SDL_EVENT_USER_WINDOW_MINIMIZE:
954 for (
auto& window : sdl->windows)
956 window.second.minimize();
959 case SDL_EVENT_USER_POINTER_NULL:
961 sdl->setCursor(
nullptr);
962 sdl->setHasCursor(
false);
964 case SDL_EVENT_USER_POINTER_DEFAULT:
966 SDL_Cursor* def = SDL_GetDefaultCursor();
969 sdl->setCursor(
nullptr);
970 sdl->setHasCursor(
true);
973 case SDL_EVENT_USER_POINTER_POSITION:
976 static_cast<INT32
>(
reinterpret_cast<uintptr_t
>(windowEvent.user.data1));
978 static_cast<INT32
>(
reinterpret_cast<uintptr_t
>(windowEvent.user.data2));
980 SDL_Window* window = SDL_GetMouseFocus();
983 const Uint32
id = SDL_GetWindowID(window);
987 if (sdl_scale_coordinates(sdl,
id, &sx, &sy, FALSE, FALSE))
988 SDL_WarpMouseInWindow(window,
static_cast<float>(sx),
989 static_cast<float>(sy));
993 case SDL_EVENT_USER_POINTER_SET:
994 sdl->setCursor(
static_cast<rdpPointer*
>(windowEvent.user.data1));
995 sdl_Pointer_Set_Process(sdl);
997 case SDL_EVENT_CLIPBOARD_UPDATE:
998 sdl->clip.handle_update(windowEvent.clipboard);
1000 case SDL_EVENT_USER_QUIT:
1002 if ((windowEvent.type >= SDL_EVENT_DISPLAY_FIRST) &&
1003 (windowEvent.type <= SDL_EVENT_DISPLAY_LAST))
1005 const SDL_DisplayEvent* ev = &windowEvent.display;
1006 (void)sdl->disp.handle_display_event(ev);
1008 else if ((windowEvent.type >= SDL_EVENT_WINDOW_FIRST) &&
1009 (windowEvent.type <= SDL_EVENT_WINDOW_LAST))
1011 const SDL_WindowEvent* ev = &windowEvent.window;
1012 auto window = sdl->windows.find(ev->windowID);
1013 if (window != sdl->windows.end())
1015 (void)sdl->disp.handle_window_event(ev);
1019 case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
1020 if (sdl->isConnected())
1022 sdl_Pointer_Set_Process(sdl);
1024 sdl->context()->settings,
1025 FreeRDP_DynamicResolutionUpdate))
1029 auto win = window->second.window();
1032 [[maybe_unused]]
auto rcpix =
1033 SDL_GetWindowSizeInPixels(win, &w_pix, &h_pix);
1035 auto scale = SDL_GetWindowDisplayScale(win);
1036 if (scale <= SDL_FLT_EPSILON)
1038 auto err = SDL_GetError();
1040 SDL_LOG_CATEGORY_APPLICATION,
1041 "SDL_GetWindowDisplayScale() failed with %s", err);
1045 assert(SDL_isnanf(scale) == 0);
1046 assert(SDL_isinff(scale) == 0);
1047 assert(scale > SDL_FLT_EPSILON);
1048 auto w_gdi = sdl->context()->gdi->width;
1049 auto h_gdi = sdl->context()->gdi->height;
1050 auto pix2point = [=](
int pix)
1052 return static_cast<int>(
static_cast<float>(pix) /
1055 if (w_pix != w_gdi || h_pix != h_gdi)
1057 const auto ssws = SDL_SetWindowSize(
1058 win, pix2point(w_gdi), pix2point(h_gdi));
1061 auto err = SDL_GetError();
1063 SDL_LOG_CATEGORY_APPLICATION,
1064 "SDL_SetWindowSize() failed with %s", err);
1070 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
1071 window->second.fill();
1072 sdl_draw_to_window(sdl, window->second);
1073 sdl_Pointer_Set_Process(sdl);
1075 case SDL_EVENT_WINDOW_MOVED:
1077 auto r = window->second.rect();
1078 auto id = window->second.id();
1079 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"%u: %dx%d-%dx%d",
1080 id, r.x, r.y, r.w, r.h);
1083 case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
1085 SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
1086 "Window closed, terminating RDP session...");
1087 freerdp_abort_connect_context(sdl->context());
1102 sdl_cleanup_sdl(sdl);
1114static BOOL sdl_post_connect(freerdp* instance)
1116 WINPR_ASSERT(instance);
1118 auto context = instance->context;
1119 WINPR_ASSERT(context);
1121 auto sdl = get_context(context);
1124 sdl->dialog.show(
false);
1131 WLog_Print(sdl->log, WLOG_INFO,
"auth-only, but no password set. Please provide one.");
1135 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only. Don't connect to X.");
1139 if (!sdl_wait_create_windows(sdl))
1142 sdl->sdl_pixel_format = SDL_PIXELFORMAT_BGRA32;
1143 if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
1146 if (!sdl_create_primary(sdl))
1149 if (!sdl_register_pointer(instance->context->graphics))
1152 WINPR_ASSERT(context->update);
1154 context->update->BeginPaint = sdl_begin_paint;
1155 context->update->EndPaint = sdl_end_paint;
1156 context->update->PlaySound = sdl_play_sound;
1157 context->update->DesktopResize = sdl_desktop_resize;
1158 context->update->SetKeyboardIndicators = sdlInput::keyboard_set_indicators;
1159 context->update->SetKeyboardImeStatus = sdlInput::keyboard_set_ime_status;
1161 if (!sdl->update_resizeable(
false))
1166 sdl->setConnected(
true);
1173static void sdl_post_disconnect(freerdp* instance)
1178 if (!instance->context)
1181 auto sdl = get_context(instance->context);
1182 sdl->setConnected(
false);
1187static void sdl_post_final_disconnect(freerdp* instance)
1192 if (!instance->context)
1195 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
1196 sdl_OnChannelConnectedEventHandler);
1197 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
1198 sdl_OnChannelDisconnectedEventHandler);
1201static void sdl_client_cleanup(
SdlContext* sdl,
int exit_code,
const std::string& error_msg)
1205 rdpContext* context = sdl->context();
1206 WINPR_ASSERT(context);
1207 rdpSettings* settings = context->settings;
1208 WINPR_ASSERT(settings);
1210 sdl->rdp_thread_running =
false;
1211 bool showError =
false;
1213 WLog_Print(sdl->log, WLOG_INFO,
"Authentication only, exit status %s [%" PRId32
"]",
1214 sdl_map_to_code_tag(exit_code), exit_code);
1219 case SDL_EXIT_SUCCESS:
1220 case SDL_EXIT_DISCONNECT:
1221 case SDL_EXIT_LOGOFF:
1222 case SDL_EXIT_DISCONNECT_BY_USER:
1223 case SDL_EXIT_CONNECT_CANCELLED:
1227 sdl->dialog.showError(error_msg);
1234 sdl->dialog.show(
false);
1236 sdl->exit_code = exit_code;
1237 sdl_push_user_event(SDL_EVENT_USER_QUIT);
1241static int sdl_client_thread_connect(
SdlContext* sdl, std::string& error_msg)
1245 auto instance = sdl->context()->instance;
1246 WINPR_ASSERT(instance);
1248 sdl->rdp_thread_running =
true;
1249 BOOL rc = freerdp_connect(instance);
1251 rdpContext* context = sdl->context();
1252 rdpSettings* settings = context->settings;
1253 WINPR_ASSERT(settings);
1255 int exit_code = SDL_EXIT_SUCCESS;
1258 UINT32 error = freerdp_get_last_error(context);
1259 exit_code = sdl_map_error_to_exit_code(error);
1264 DWORD code = freerdp_get_last_error(context);
1265 freerdp_abort_connect_context(context);
1266 WLog_Print(sdl->log, WLOG_ERROR,
"Authentication only, %s [0x%08" PRIx32
"] %s",
1267 freerdp_get_last_error_name(code), code, freerdp_get_last_error_string(code));
1273 DWORD code = freerdp_error_info(instance);
1274 if (exit_code == SDL_EXIT_SUCCESS)
1276 char* msg =
nullptr;
1278 exit_code = error_info_to_error(instance, &code, &msg, &len);
1284 auto last = freerdp_get_last_error(context);
1285 if (error_msg.empty())
1287 char* msg =
nullptr;
1289 winpr_asprintf(&msg, &len,
"%s [0x%08" PRIx32
"]\n%s",
1290 freerdp_get_last_error_name(last), last,
1291 freerdp_get_last_error_string(last));
1297 if (exit_code == SDL_EXIT_SUCCESS)
1299 if (last == FREERDP_ERROR_AUTHENTICATION_FAILED)
1300 exit_code = SDL_EXIT_AUTH_FAILURE;
1301 else if (code == ERRINFO_SUCCESS)
1302 exit_code = SDL_EXIT_CONN_FAILED;
1305 sdl->dialog.show(
false);
1311static int sdl_client_thread_run(
SdlContext* sdl, std::string& error_msg)
1315 auto context = sdl->context();
1316 WINPR_ASSERT(context);
1318 auto instance = context->instance;
1319 WINPR_ASSERT(instance);
1321 int exit_code = SDL_EXIT_SUCCESS;
1322 while (!freerdp_shall_disconnect_context(context))
1324 HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {};
1330 if (freerdp_focus_required(instance))
1332 auto ctx = get_context(context);
1334 if (!ctx->input.keyboard_focus_in())
1336 if (!ctx->input.keyboard_focus_in())
1340 const DWORD nCount = freerdp_get_event_handles(context, handles, ARRAYSIZE(handles));
1344 WLog_Print(sdl->log, WLOG_ERROR,
"freerdp_get_event_handles failed");
1348 const DWORD status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
1350 if (status == WAIT_FAILED)
1353 if (!freerdp_check_event_handles(context))
1355 if (client_auto_reconnect(instance))
1358 sdl->dialog.show(
false);
1367 if (freerdp_error_info(instance) == 0)
1368 exit_code = SDL_EXIT_CONN_FAILED;
1371 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1372 WLog_Print(sdl->log, WLOG_ERROR,
"WaitForMultipleObjects failed with %" PRIu32
"",
1374 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1375 WLog_Print(sdl->log, WLOG_ERROR,
"Failed to check FreeRDP event handles");
1380 if (exit_code == SDL_EXIT_SUCCESS)
1384 char* emsg =
nullptr;
1386 exit_code = error_info_to_error(instance, &code, &emsg, &elen);
1392 if ((code == ERRINFO_LOGOFF_BY_USER) &&
1393 (freerdp_get_disconnect_ultimatum(context) == Disconnect_Ultimatum_user_requested))
1395 const char* msg =
"Error info says user did not initiate but disconnect ultimatum says "
1396 "they did; treat this as a user logoff";
1398 char* emsg =
nullptr;
1400 winpr_asprintf(&emsg, &elen,
"%s", msg);
1406 WLog_Print(sdl->log, WLOG_INFO,
"%s", msg);
1407 exit_code = SDL_EXIT_LOGOFF;
1411 freerdp_disconnect(instance);
1419static DWORD WINAPI sdl_client_thread_proc(
SdlContext* sdl)
1423 std::string error_msg;
1424 int exit_code = sdl_client_thread_connect(sdl, error_msg);
1425 if (exit_code == SDL_EXIT_SUCCESS)
1426 exit_code = sdl_client_thread_run(sdl, error_msg);
1427 sdl_client_cleanup(sdl, exit_code, error_msg);
1429 return static_cast<DWORD
>(exit_code);
1435static BOOL sdl_client_global_init()
1439 const DWORD wVersionRequested = MAKEWORD(1, 1);
1440 const int rc = WSAStartup(wVersionRequested, &wsaData);
1443 WLog_ERR(SDL_TAG,
"WSAStartup failed with %s [%d]", gai_strerrorA(rc), rc);
1448 return (freerdp_handle_signals() == 0);
1452static void sdl_client_global_uninit()
1459static BOOL sdl_client_new(freerdp* instance, rdpContext* context)
1463 if (!instance || !context)
1470 instance->PreConnect = sdl_pre_connect;
1471 instance->PostConnect = sdl_post_connect;
1472 instance->PostDisconnect = sdl_post_disconnect;
1473 instance->PostFinalDisconnect = sdl_post_final_disconnect;
1474 instance->AuthenticateEx = sdl_authenticate_ex;
1475 instance->VerifyCertificateEx = sdl_verify_certificate_ex;
1476 instance->VerifyChangedCertificateEx = sdl_verify_changed_certificate_ex;
1477 instance->LogonErrorInfo = sdl_logon_error_info;
1478 instance->PresentGatewayMessage = sdl_present_gateway_message;
1479 instance->ChooseSmartcard = sdl_choose_smartcard;
1480 instance->RetryDialog = sdl_retry_dialog;
1483 instance->GetAccessToken = sdl_webview_get_access_token;
1485 instance->GetAccessToken = client_cli_get_access_token;
1492static void sdl_client_free([[maybe_unused]] freerdp* instance, rdpContext* context)
1502static int sdl_client_start(rdpContext* context)
1504 auto sdl = get_context(context);
1507 sdl->thread = std::thread(sdl_client_thread_proc, sdl);
1511static int sdl_client_stop(rdpContext* context)
1513 auto sdl = get_context(context);
1518 HANDLE
event = freerdp_abort_event(context);
1519 if (!SetEvent(event))
1526static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
1528 WINPR_ASSERT(pEntryPoints);
1530 ZeroMemory(pEntryPoints,
sizeof(RDP_CLIENT_ENTRY_POINTS));
1531 pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
1532 pEntryPoints->Size =
sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
1533 pEntryPoints->GlobalInit = sdl_client_global_init;
1534 pEntryPoints->GlobalUninit = sdl_client_global_uninit;
1536 pEntryPoints->ClientNew = sdl_client_new;
1537 pEntryPoints->ClientFree = sdl_client_free;
1538 pEntryPoints->ClientStart = sdl_client_start;
1539 pEntryPoints->ClientStop = sdl_client_stop;
1546 freerdp_client_context_free(&sdl->common.context);
1549static const char* category2str(
int category)
1553 case SDL_LOG_CATEGORY_APPLICATION:
1554 return "SDL_LOG_CATEGORY_APPLICATION";
1555 case SDL_LOG_CATEGORY_ERROR:
1556 return "SDL_LOG_CATEGORY_ERROR";
1557 case SDL_LOG_CATEGORY_ASSERT:
1558 return "SDL_LOG_CATEGORY_ASSERT";
1559 case SDL_LOG_CATEGORY_SYSTEM:
1560 return "SDL_LOG_CATEGORY_SYSTEM";
1561 case SDL_LOG_CATEGORY_AUDIO:
1562 return "SDL_LOG_CATEGORY_AUDIO";
1563 case SDL_LOG_CATEGORY_VIDEO:
1564 return "SDL_LOG_CATEGORY_VIDEO";
1565 case SDL_LOG_CATEGORY_RENDER:
1566 return "SDL_LOG_CATEGORY_RENDER";
1567 case SDL_LOG_CATEGORY_INPUT:
1568 return "SDL_LOG_CATEGORY_INPUT";
1569 case SDL_LOG_CATEGORY_TEST:
1570 return "SDL_LOG_CATEGORY_TEST";
1571 case SDL_LOG_CATEGORY_GPU:
1572 return "SDL_LOG_CATEGORY_GPU";
1573 case SDL_LOG_CATEGORY_RESERVED2:
1574 return "SDL_LOG_CATEGORY_RESERVED2";
1575 case SDL_LOG_CATEGORY_RESERVED3:
1576 return "SDL_LOG_CATEGORY_RESERVED3";
1577 case SDL_LOG_CATEGORY_RESERVED4:
1578 return "SDL_LOG_CATEGORY_RESERVED4";
1579 case SDL_LOG_CATEGORY_RESERVED5:
1580 return "SDL_LOG_CATEGORY_RESERVED5";
1581 case SDL_LOG_CATEGORY_RESERVED6:
1582 return "SDL_LOG_CATEGORY_RESERVED6";
1583 case SDL_LOG_CATEGORY_RESERVED7:
1584 return "SDL_LOG_CATEGORY_RESERVED7";
1585 case SDL_LOG_CATEGORY_RESERVED8:
1586 return "SDL_LOG_CATEGORY_RESERVED8";
1587 case SDL_LOG_CATEGORY_RESERVED9:
1588 return "SDL_LOG_CATEGORY_RESERVED9";
1589 case SDL_LOG_CATEGORY_RESERVED10:
1590 return "SDL_LOG_CATEGORY_RESERVED10";
1591 case SDL_LOG_CATEGORY_CUSTOM:
1593 return "SDL_LOG_CATEGORY_CUSTOM";
1597static SDL_LogPriority wloglevel2dl(DWORD level)
1602 return SDL_LOG_PRIORITY_VERBOSE;
1604 return SDL_LOG_PRIORITY_DEBUG;
1606 return SDL_LOG_PRIORITY_INFO;
1608 return SDL_LOG_PRIORITY_WARN;
1610 return SDL_LOG_PRIORITY_ERROR;
1612 return SDL_LOG_PRIORITY_CRITICAL;
1615 return SDL_LOG_PRIORITY_VERBOSE;
1619static DWORD sdlpriority2wlog(SDL_LogPriority priority)
1621 DWORD level = WLOG_OFF;
1624 case SDL_LOG_PRIORITY_VERBOSE:
1627 case SDL_LOG_PRIORITY_DEBUG:
1630 case SDL_LOG_PRIORITY_INFO:
1633 case SDL_LOG_PRIORITY_WARN:
1636 case SDL_LOG_PRIORITY_ERROR:
1639 case SDL_LOG_PRIORITY_CRITICAL:
1649static void SDLCALL winpr_LogOutputFunction(
void* userdata,
int category, SDL_LogPriority priority,
1650 const char* message)
1652 auto sdl =
static_cast<SdlContext*
>(userdata);
1655 const DWORD level = sdlpriority2wlog(priority);
1656 auto log = sdl->log;
1657 if (!WLog_IsLevelActive(log, level))
1660 WLog_PrintTextMessage(log, level, __LINE__, __FILE__, __func__,
"[%s] %s",
1661 category2str(category), message);
1664int main(
int argc,
char* argv[])
1668 RDP_CLIENT_ENTRY_POINTS clientEntryPoints = {};
1670 RdpClientEntry(&clientEntryPoints);
1672 reinterpret_cast<sdl_rdp_context*
>(freerdp_client_context_new(&clientEntryPoints)),
1677 auto sdl = sdl_rdp->sdl;
1679 auto settings = sdl->context()->settings;
1680 WINPR_ASSERT(settings);
1682 status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
1683 sdl_rdp->sdl->setMetadata();
1686 rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
1688 sdl_list_monitors(sdl);
1693 case COMMAND_LINE_STATUS_PRINT:
1694 case COMMAND_LINE_STATUS_PRINT_VERSION:
1695 case COMMAND_LINE_STATUS_PRINT_BUILDCONFIG:
1697 case COMMAND_LINE_STATUS_PRINT_HELP:
1699 SdlPref::print_config_file_help(3);
1706 SDL_SetLogOutputFunction(winpr_LogOutputFunction, sdl);
1707 auto level = WLog_GetLogLevel(sdl->log);
1708 SDL_SetLogPriorities(wloglevel2dl(level));
1710 auto context = sdl->context();
1711 WINPR_ASSERT(context);
1713 if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
1716 if (freerdp_client_start(context) != 0)
1721 if (freerdp_client_stop(context) != 0)
1724 if (sdl->exit_code != 0)
1725 rc = sdl->exit_code;
1730bool SdlContext::update_fullscreen(
bool enter)
1732 for (
const auto& window : windows)
1734 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter))
1741bool SdlContext::update_minimize()
1743 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1746bool SdlContext::update_resizeable(
bool enable)
1748 const auto settings = context()->settings;
1751 bool use = (dyn && enable) || smart;
1753 for (
const auto& window : windows)
1755 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1763SdlContext::SdlContext(rdpContext* context)
1764 : _context(context), log(WLog_Get(SDL_TAG)), disp(this), input(this), clip(this),
1765 primary(nullptr, SDL_DestroySurface), rdp_thread_running(false), dialog(log)
1767 WINPR_ASSERT(context);
1771void SdlContext::setHasCursor(
bool val)
1773 this->_cursor_visible = val;
1776bool SdlContext::hasCursor()
const
1778 return _cursor_visible;
1781void SdlContext::setMetadata()
1784 if (!wmclass || (strlen(wmclass) == 0))
1785 wmclass = SDL_CLIENT_UUID;
1787 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
1788 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
1789 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
1790 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
1791 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
1792 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
1793 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
1796bool SdlContext::redraw(
bool suppress)
const
1801 auto gdi = context()->gdi;
1803 return gdi_send_suppress_output(gdi, suppress);
1806void SdlContext::setConnected(
bool val)
1811bool SdlContext::isConnected()
const
1816rdpContext* SdlContext::context()
const
1818 WINPR_ASSERT(_context);
1822rdpClientContext* SdlContext::common()
const
1824 return reinterpret_cast<rdpClientContext*
>(context());
1827void SdlContext::setCursor(rdpPointer* cursor)
1832rdpPointer* SdlContext::cursor()
const
1837void SdlContext::setMonitorIds(
const std::vector<SDL_DisplayID>& ids)
1839 _monitorIds.clear();
1842 _monitorIds.push_back(
id);
1846const std::vector<SDL_DisplayID>& SdlContext::monitorIds()
const
1851int64_t SdlContext::monitorId(uint32_t index)
const
1853 if (index >= _monitorIds.size())
1857 return _monitorIds[index];
1860void SdlContext::push(std::vector<SDL_Rect>&& rects)
1862 std::unique_lock lock(_queue_mux);
1863 _queue.emplace(std::move(rects));
1866std::vector<SDL_Rect> SdlContext::pop()
1868 std::unique_lock lock(_queue_mux);
1873 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.