FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_utils.hpp
1
19
20#pragma once
21
22#include <winpr/synch.h>
23#include <winpr/wlog.h>
24
25#include <freerdp/settings.h>
26
27#include <SDL3/SDL.h>
28#include <string>
29#include <vector>
30#include <memory>
31#include <functional>
32
33#include <sdl_common_utils.hpp>
34
35template <typename T> using deleted_unique_ptr = std::unique_ptr<T, std::function<void(T*)>>;
36
37enum
38{
39 SDL_EVENT_USER_UPDATE = SDL_EVENT_USER + 1,
40 SDL_EVENT_USER_CREATE_WINDOWS,
41 SDL_EVENT_USER_WINDOW_RESIZEABLE,
42 SDL_EVENT_USER_WINDOW_FULLSCREEN,
43 SDL_EVENT_USER_WINDOW_MINIMIZE,
44 SDL_EVENT_USER_POINTER_NULL,
45 SDL_EVENT_USER_POINTER_DEFAULT,
46 SDL_EVENT_USER_POINTER_POSITION,
47 SDL_EVENT_USER_POINTER_SET,
48 SDL_EVENT_USER_RAIL_MOVE,
49 SDL_EVENT_USER_OVERLAY,
50 SDL_EVENT_USER_QUIT,
51 /* a mapped renderer (rdpContext::bitmapRenderService) got a frame. Before the dialogs:
52 * sdl_run() only takes the events up to SDL_EVENT_USER_RETRY_DIALOG, the *_RESULT ones are
53 * for the dialogs' wait loops */
54 SDL_EVENT_USER_RENDERER,
55 /* RemoteApp windows' info (rdpContext::windowInfoService) to refresh */
56 SDL_EVENT_USER_WINDOW_INFO,
57 SDL_EVENT_USER_CERT_DIALOG,
58 SDL_EVENT_USER_SHOW_DIALOG,
59 SDL_EVENT_USER_AUTH_DIALOG,
60 SDL_EVENT_USER_SCARD_DIALOG,
61 SDL_EVENT_USER_RETRY_DIALOG,
62
63 SDL_EVENT_USER_CERT_RESULT,
64 SDL_EVENT_USER_SHOW_RESULT,
65 SDL_EVENT_USER_AUTH_RESULT,
66 SDL_EVENT_USER_SCARD_RESULT
67};
68
69typedef struct
70{
71 Uint32 type;
72 Uint32 timestamp;
73 char* title;
74 char* user;
75 char* domain;
76 char* password;
77 Sint32 result;
79
80[[nodiscard]] bool sdl_push_user_event(Uint32 type, ...);
81
82[[nodiscard]] bool sdl_push_quit();
83
84/* Push SDL_EVENT_USER_UPDATE once after `ms`, so the main loop re-checks a deadline. */
85[[nodiscard]] bool sdl_push_update_after(Uint32 ms);
86
87[[nodiscard]] const char* sdl_error_string(Sint32 res);
88
89#define sdl_log_error(res, log, what) sdl_log_error_ex(res, log, what, __FILE__, __LINE__, __func__)
90[[nodiscard]] BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file,
91 size_t line, const char* fkt);
92
93namespace sdl::utils
94{
95 [[nodiscard]] std::string touchFlagsToString(Uint32 flags);
96 [[nodiscard]] std::string toString(enum FreeRDP_DesktopRotationFlags orientation);
97 [[nodiscard]] std::string toString(SDL_DisplayOrientation orientation);
98 [[nodiscard]] std::string toString(const SDL_DisplayMode* mode);
99 [[nodiscard]] std::string toString(Uint32 type);
100 [[nodiscard]] std::string toString(SDL_Rect rect);
101 [[nodiscard]] std::string toString(SDL_FRect rect);
102
103 [[nodiscard]] UINT32 orientaion_to_rdp(SDL_DisplayOrientation orientation);
104
105 [[nodiscard]] std::string generate_uuid_v4();
106
107 enum HighDpiScaleMode
108 {
109 SCALE_MODE_INVALID,
110 SCALE_MODE_X11,
111 SCALE_MODE_WAYLAND
112 };
113
114 [[nodiscard]] HighDpiScaleMode platformScaleMode();
115
116 /* True on the Wayland backend (toplevel windows can not be positioned or queried). */
117 [[nodiscard]] bool isWaylandDriver();
118 /* True on the X11 backend. */
119 [[nodiscard]] bool isX11Driver();
120 [[nodiscard]] bool isWindowsDriver();
121
122 [[nodiscard]] std::string windowTitle(const rdpSettings* settings);
123
124 /* A key press, a mouse move or click, a wheel turn or a focus change is sent to the
125 * server as it happens. When the connection is lost (a dropped network, a reconnect)
126 * the session is no longer active and the send fails: the event is lost, the connection
127 * reports its own state and the reconnect recovers, so handling the event succeeds.
128 * A send that fails while the session is active is still a failure. */
129 [[nodiscard]] bool inputSent(rdpContext* context, wLog* log, BOOL sent, const char* what);
130
131} // namespace sdl::utils
132
133namespace sdl::error
134{
135 enum EXIT_CODE
136 {
137 /* section 0-15: protocol-independent codes */
138 SUCCESS = 0,
139 DISCONNECT = 1,
140 LOGOFF = 2,
141 IDLE_TIMEOUT = 3,
142 LOGON_TIMEOUT = 4,
143 CONN_REPLACED = 5,
144 OUT_OF_MEMORY = 6,
145 CONN_DENIED = 7,
146 CONN_DENIED_FIPS = 8,
147 USER_PRIVILEGES = 9,
148 FRESH_CREDENTIALS_REQUIRED = 10,
149 DISCONNECT_BY_USER = 11,
150
151 /* section 16-31: license error set */
152 LICENSE_INTERNAL = 16,
153 LICENSE_NO_LICENSE_SERVER = 17,
154 LICENSE_NO_LICENSE = 18,
155 LICENSE_BAD_CLIENT_MSG = 19,
156 LICENSE_HWID_DOESNT_MATCH = 20,
157 LICENSE_BAD_CLIENT = 21,
158 LICENSE_CANT_FINISH_PROTOCOL = 22,
159 LICENSE_CLIENT_ENDED_PROTOCOL = 23,
160 LICENSE_BAD_CLIENT_ENCRYPTION = 24,
161 LICENSE_CANT_UPGRADE = 25,
162 LICENSE_NO_REMOTE_CONNECTIONS = 26,
163
164 /* section 32-127: RDP protocol error set */
165 RDP = 32,
166
167 /* section 128-254: xfreerdp specific exit codes */
168 PARSE_ARGUMENTS = 128,
169 MEMORY = 129,
170 PROTOCOL = 130,
171 CONN_FAILED = 131,
172 AUTH_FAILURE = 132,
173 NEGO_FAILURE = 133,
174 LOGON_FAILURE = 134,
175 ACCOUNT_LOCKED_OUT = 135,
176 PRE_CONNECT_FAILED = 136,
177 CONNECT_UNDEFINED = 137,
178 POST_CONNECT_FAILED = 138,
179 DNS_ERROR = 139,
180 DNS_NAME_NOT_FOUND = 140,
181 CONNECT_FAILED = 141,
182 MCS_CONNECT_INITIAL_ERROR = 142,
183 TLS_CONNECT_FAILED = 143,
184 INSUFFICIENT_PRIVILEGES = 144,
185 CONNECT_CANCELLED = 145,
186
187 CONNECT_TRANSPORT_FAILED = 147,
188 CONNECT_PASSWORD_EXPIRED = 148,
189 CONNECT_PASSWORD_MUST_CHANGE = 149,
190 CONNECT_KDC_UNREACHABLE = 150,
191 CONNECT_ACCOUNT_DISABLED = 151,
192 CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
193 CONNECT_CLIENT_REVOKED = 153,
194 CONNECT_WRONG_PASSWORD = 154,
195 CONNECT_ACCESS_DENIED = 155,
196 CONNECT_ACCOUNT_RESTRICTION = 156,
197 CONNECT_ACCOUNT_EXPIRED = 157,
198 CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
199 CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
200 CONNECT_TARGET_BOOTING = 160,
201 CONNECT_HYBRID_REQUIRED_BY_SERVER = 161,
202
203 UNKNOWN = 255,
204 };
205
206 [[nodiscard]] int errorToExitCode(DWORD error);
207 [[nodiscard]] const char* errorToExitCodeTag(UINT32 error);
208 [[nodiscard]] const char* exitCodeToTag(int code);
209} // namespace sdl::error