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