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