FreeRDP
SDL3/sdl_utils.hpp
1 
20 #pragma once
21 
22 #include <winpr/synch.h>
23 #include <winpr/wlog.h>
24 
25 #include <SDL3/SDL.h>
26 #include <string>
27 #include <vector>
28 #include <memory>
29 #include <functional>
30 
31 template <typename T> using deleted_unique_ptr = std::unique_ptr<T, std::function<void(T*)>>;
32 
33 class CriticalSection
34 {
35  public:
37  CriticalSection(const CriticalSection& other) = delete;
38  CriticalSection(CriticalSection&& other) = delete;
39  ~CriticalSection();
40 
41  CriticalSection& operator=(const CriticalSection& other) = delete;
42  CriticalSection& operator=(CriticalSection&& other) = delete;
43 
44  void lock();
45  void unlock();
46 
47  private:
48  CRITICAL_SECTION _section{};
49 };
50 
51 class WinPREvent
52 {
53  public:
54  explicit WinPREvent(bool initial = false);
55  ~WinPREvent();
56 
57  void set();
58  void clear();
59  [[nodiscard]] bool isSet() const;
60 
61  [[nodiscard]] HANDLE handle() const;
62 
63  private:
64  HANDLE _handle;
65 };
66 
67 enum
68 {
69  SDL_EVENT_USER_UPDATE = SDL_EVENT_USER + 1,
70  SDL_EVENT_USER_CREATE_WINDOWS,
71  SDL_EVENT_USER_WINDOW_RESIZEABLE,
72  SDL_EVENT_USER_WINDOW_FULLSCREEN,
73  SDL_EVENT_USER_WINDOW_MINIMIZE,
74  SDL_EVENT_USER_POINTER_NULL,
75  SDL_EVENT_USER_POINTER_DEFAULT,
76  SDL_EVENT_USER_POINTER_POSITION,
77  SDL_EVENT_USER_POINTER_SET,
78  SDL_EVENT_USER_QUIT,
79  SDL_EVENT_USER_CERT_DIALOG,
80  SDL_EVENT_USER_SHOW_DIALOG,
81  SDL_EVENT_USER_AUTH_DIALOG,
82  SDL_EVENT_USER_SCARD_DIALOG,
83  SDL_EVENT_USER_RETRY_DIALOG,
84 
85  SDL_EVENT_USER_CERT_RESULT,
86  SDL_EVENT_USER_SHOW_RESULT,
87  SDL_EVENT_USER_AUTH_RESULT,
88  SDL_EVENT_USER_SCARD_RESULT
89 };
90 
91 typedef struct
92 {
93  Uint32 type;
94  Uint32 timestamp;
95  char* title;
96  char* user;
97  char* domain;
98  char* password;
99  Sint32 result;
101 
102 BOOL sdl_push_user_event(Uint32 type, ...);
103 
104 bool sdl_push_quit();
105 
106 std::string sdl_window_event_str(Uint32 ev);
107 const char* sdl_event_type_str(Uint32 type);
108 const char* sdl_error_string(Uint32 res);
109 
110 #define sdl_log_error(res, log, what) sdl_log_error_ex(res, log, what, __FILE__, __LINE__, __func__)
111 BOOL sdl_log_error_ex(Uint32 res, wLog* log, const char* what, const char* file, size_t line,
112  const char* fkt);