FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_utils.hpp
1
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_QUIT,
50 SDL_EVENT_USER_CERT_DIALOG,
51 SDL_EVENT_USER_SHOW_DIALOG,
52 SDL_EVENT_USER_AUTH_DIALOG,
53 SDL_EVENT_USER_SCARD_DIALOG,
54 SDL_EVENT_USER_RETRY_DIALOG,
55
56 SDL_EVENT_USER_CERT_RESULT,
57 SDL_EVENT_USER_SHOW_RESULT,
58 SDL_EVENT_USER_AUTH_RESULT,
59 SDL_EVENT_USER_SCARD_RESULT
60};
61
62typedef struct
63{
64 Uint32 type;
65 Uint32 timestamp;
66 char* title;
67 char* user;
68 char* domain;
69 char* password;
70 Sint32 result;
72
73[[nodiscard]] bool sdl_push_user_event(Uint32 type, ...);
74
75[[nodiscard]] bool sdl_push_quit();
76
77/* Push SDL_EVENT_USER_UPDATE once after `ms`, so the main loop re-checks a deadline. */
78[[nodiscard]] bool sdl_push_update_after(Uint32 ms);
79
80[[nodiscard]] const char* sdl_error_string(Sint32 res);
81
82#define sdl_log_error(res, log, what) sdl_log_error_ex(res, log, what, __FILE__, __LINE__, __func__)
83[[nodiscard]] BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file,
84 size_t line, const char* fkt);
85
86namespace sdl::utils
87{
88 [[nodiscard]] std::string touchFlagsToString(Uint32 flags);
89 [[nodiscard]] std::string toString(enum FreeRDP_DesktopRotationFlags orientation);
90 [[nodiscard]] std::string toString(SDL_DisplayOrientation orientation);
91 [[nodiscard]] std::string toString(const SDL_DisplayMode* mode);
92 [[nodiscard]] std::string toString(Uint32 type);
93 [[nodiscard]] std::string toString(SDL_Rect rect);
94 [[nodiscard]] std::string toString(SDL_FRect rect);
95
96 [[nodiscard]] UINT32 orientaion_to_rdp(SDL_DisplayOrientation orientation);
97
98 [[nodiscard]] std::string generate_uuid_v4();
99
100 enum HighDpiScaleMode
101 {
102 SCALE_MODE_INVALID,
103 SCALE_MODE_X11,
104 SCALE_MODE_WAYLAND
105 };
106
107 [[nodiscard]] HighDpiScaleMode platformScaleMode();
108
109 /* True on the Wayland backend (toplevel windows can not be positioned or queried). */
110 [[nodiscard]] bool isWaylandDriver();
111 /* True on the X11 backend. */
112 [[nodiscard]] bool isX11Driver();
113 [[nodiscard]] bool isWindowsDriver();
114
115 [[nodiscard]] std::string windowTitle(const rdpSettings* settings);
116
117} // namespace sdl::utils
118
119namespace sdl::error
120{
121 enum EXIT_CODE
122 {
123 /* section 0-15: protocol-independent codes */
124 SUCCESS = 0,
125 DISCONNECT = 1,
126 LOGOFF = 2,
127 IDLE_TIMEOUT = 3,
128 LOGON_TIMEOUT = 4,
129 CONN_REPLACED = 5,
130 OUT_OF_MEMORY = 6,
131 CONN_DENIED = 7,
132 CONN_DENIED_FIPS = 8,
133 USER_PRIVILEGES = 9,
134 FRESH_CREDENTIALS_REQUIRED = 10,
135 DISCONNECT_BY_USER = 11,
136
137 /* section 16-31: license error set */
138 LICENSE_INTERNAL = 16,
139 LICENSE_NO_LICENSE_SERVER = 17,
140 LICENSE_NO_LICENSE = 18,
141 LICENSE_BAD_CLIENT_MSG = 19,
142 LICENSE_HWID_DOESNT_MATCH = 20,
143 LICENSE_BAD_CLIENT = 21,
144 LICENSE_CANT_FINISH_PROTOCOL = 22,
145 LICENSE_CLIENT_ENDED_PROTOCOL = 23,
146 LICENSE_BAD_CLIENT_ENCRYPTION = 24,
147 LICENSE_CANT_UPGRADE = 25,
148 LICENSE_NO_REMOTE_CONNECTIONS = 26,
149
150 /* section 32-127: RDP protocol error set */
151 RDP = 32,
152
153 /* section 128-254: xfreerdp specific exit codes */
154 PARSE_ARGUMENTS = 128,
155 MEMORY = 129,
156 PROTOCOL = 130,
157 CONN_FAILED = 131,
158 AUTH_FAILURE = 132,
159 NEGO_FAILURE = 133,
160 LOGON_FAILURE = 134,
161 ACCOUNT_LOCKED_OUT = 135,
162 PRE_CONNECT_FAILED = 136,
163 CONNECT_UNDEFINED = 137,
164 POST_CONNECT_FAILED = 138,
165 DNS_ERROR = 139,
166 DNS_NAME_NOT_FOUND = 140,
167 CONNECT_FAILED = 141,
168 MCS_CONNECT_INITIAL_ERROR = 142,
169 TLS_CONNECT_FAILED = 143,
170 INSUFFICIENT_PRIVILEGES = 144,
171 CONNECT_CANCELLED = 145,
172
173 CONNECT_TRANSPORT_FAILED = 147,
174 CONNECT_PASSWORD_EXPIRED = 148,
175 CONNECT_PASSWORD_MUST_CHANGE = 149,
176 CONNECT_KDC_UNREACHABLE = 150,
177 CONNECT_ACCOUNT_DISABLED = 151,
178 CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
179 CONNECT_CLIENT_REVOKED = 153,
180 CONNECT_WRONG_PASSWORD = 154,
181 CONNECT_ACCESS_DENIED = 155,
182 CONNECT_ACCOUNT_RESTRICTION = 156,
183 CONNECT_ACCOUNT_EXPIRED = 157,
184 CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
185 CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
186 CONNECT_TARGET_BOOTING = 160,
187 CONNECT_HYBRID_REQUIRED_BY_SERVER = 161,
188
189 UNKNOWN = 255,
190 };
191
192 [[nodiscard]] int errorToExitCode(DWORD error);
193 [[nodiscard]] const char* errorToExitCodeTag(UINT32 error);
194 [[nodiscard]] const char* exitCodeToTag(int code);
195} // namespace sdl::error