SDL_syswm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_syswm.h
  20. *
  21. * Include file for SDL custom system window manager hooks.
  22. */
  23. #ifndef SDL_syswm_h_
  24. #define SDL_syswm_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_platform_defines.h>
  28. #include <SDL3/SDL_video.h>
  29. /**
  30. * \brief SDL_syswm.h
  31. *
  32. * Your application has access to a special type of event ::SDL_SYSWMEVENT,
  33. * which contains window-manager specific information and arrives whenever
  34. * an unhandled window event occurs. This event is ignored by default, but
  35. * you can enable it with SDL_SetEventEnabled().
  36. */
  37. /**
  38. * The available subsystems based on platform
  39. */
  40. #if !defined(SDL_DISABLE_SYSWM_PLATFORMS)
  41. #ifndef SDL_DISABLE_SYSWM_ANDROID
  42. #ifdef __ANDROID__
  43. #define SDL_ENABLE_SYSWM_ANDROID
  44. #endif
  45. #endif /* !SDL_DISABLE_SYSWM_ANDROID */
  46. #ifndef SDL_DISABLE_SYSWM_COCOA
  47. #ifdef __MACOS__
  48. #define SDL_ENABLE_SYSWM_COCOA
  49. #endif
  50. #endif /* !SDL_DISABLE_SYSWM_COCOA */
  51. #ifndef SDL_DISABLE_SYSWM_HAIKU
  52. #ifdef __HAIKU__
  53. #define SDL_ENABLE_SYSWM_HAIKU
  54. #endif
  55. #endif /* !SDL_DISABLE_SYSWM_HAIKU */
  56. #ifndef SDL_DISABLE_SYSWM_KMSDRM
  57. #if defined(__LINUX__) || defined(__FREEBSD__) || defined(__OPENBSD__)
  58. #define SDL_ENABLE_SYSWM_KMSDRM
  59. #endif
  60. #endif /* !SDL_DISABLE_SYSWM_KMSDRM */
  61. #ifndef SDL_DISABLE_SYSWM_RISCOS
  62. #ifdef __RISCOS__
  63. #define SDL_ENABLE_SYSWM_RISCOS
  64. #endif
  65. #endif /* !SDL_DISABLE_SYSWM_RISCOS */
  66. #ifndef SDL_DISABLE_SYSWM_UIKIT
  67. #if defined(__IOS__) || defined(__TVOS__)
  68. #define SDL_ENABLE_SYSWM_UIKIT
  69. #endif
  70. #endif /* !SDL_DISABLE_SYSWM_UIKIT */
  71. #ifndef SDL_DISABLE_SYSWM_VIVANTE
  72. /* Not enabled by default */
  73. #endif /* !SDL_DISABLE_SYSWM_VIVANTE */
  74. #ifndef SDL_DISABLE_SYSWM_WAYLAND
  75. #if defined(__LINUX__) || defined(__FREEBSD__)
  76. #define SDL_ENABLE_SYSWM_WAYLAND
  77. #endif
  78. #endif /* !SDL_DISABLE_SYSWM_WAYLAND */
  79. #ifndef SDL_DISABLE_SYSWM_WINDOWS
  80. #ifdef __WIN32__
  81. #define SDL_ENABLE_SYSWM_WINDOWS
  82. #endif
  83. #endif /* !SDL_DISABLE_SYSWM_WINDOWS */
  84. #ifndef SDL_DISABLE_SYSWM_WINRT
  85. #ifdef __WINRT__
  86. #define SDL_ENABLE_SYSWM_WINRT
  87. #endif
  88. #endif /* !SDL_DISABLE_SYSWM_WINRT */
  89. #ifndef SDL_DISABLE_SYSWM_X11
  90. #if defined(__unix__) && !defined(__WIN32__) && !defined(__ANDROID__)
  91. #define SDL_ENABLE_SYSWM_X11
  92. #endif
  93. #endif /* !SDL_DISABLE_SYSWM_X11 */
  94. #endif /* !SDL_DISABLE_SYSWM_PLATFORMS */
  95. /**
  96. * Forward declaration of types used by subsystems
  97. */
  98. #ifndef SDL_DISABLE_SYSWM_TYPES
  99. #if defined(SDL_ENABLE_SYSWM_ANDROID) && !defined(SDL_DISABLE_SYSWM_ANDROID_TYPES)
  100. typedef struct ANativeWindow ANativeWindow;
  101. typedef void *EGLSurface;
  102. #endif /* SDL_ENABLE_SYSWM_ANDROID */
  103. #if defined(SDL_ENABLE_SYSWM_COCOA) && !defined(SDL_DISABLE_SYSWM_COCOA_TYPES)
  104. #ifdef __OBJC__
  105. @class NSWindow;
  106. #else
  107. typedef struct _NSWindow NSWindow;
  108. #endif
  109. #endif /* SDL_ENABLE_SYSWM_COCOA */
  110. #if defined(SDL_ENABLE_SYSWM_KMSDRM) && !defined(SDL_DISABLE_SYSWM_KMSDRM_TYPES)
  111. struct gbm_device;
  112. #endif /* SDL_ENABLE_SYSWM_KMSDRM */
  113. #if defined(SDL_ENABLE_SYSWM_UIKIT) && !defined(SDL_DISABLE_SYSWM_UIKIT_TYPES)
  114. #ifdef __OBJC__
  115. #include <UIKit/UIKit.h>
  116. #else
  117. typedef struct _UIWindow UIWindow;
  118. typedef struct _UIViewController UIViewController;
  119. #endif
  120. typedef Uint32 GLuint;
  121. #endif /* SDL_ENABLE_SYSWM_UIKIT */
  122. #if defined(SDL_ENABLE_SYSWM_VIVANTE) && !defined(SDL_DISABLE_SYSWM_VIVANTE_TYPES)
  123. #include <SDL3/SDL_egl.h>
  124. #endif /* SDL_ENABLE_SYSWM_VIVANTE */
  125. #if defined(SDL_ENABLE_SYSWM_WAYLAND) && !defined(SDL_DISABLE_SYSWM_WAYLAND_TYPES)
  126. struct wl_display;
  127. struct wl_egl_window;
  128. struct wl_surface;
  129. struct xdg_popup;
  130. struct xdg_positioner;
  131. struct xdg_surface;
  132. struct xdg_toplevel;
  133. #endif /* SDL_ENABLE_SYSWM_WAYLAND */
  134. #if defined(SDL_ENABLE_SYSWM_WINDOWS) && !defined(SDL_DISABLE_SYSWM_WINDOWS_TYPES)
  135. #ifndef WIN32_LEAN_AND_MEAN
  136. #define WIN32_LEAN_AND_MEAN
  137. #endif
  138. #ifndef NOMINMAX /* don't define min() and max(). */
  139. #define NOMINMAX
  140. #endif
  141. #include <windows.h>
  142. #endif /* SDL_ENABLE_SYSWM_WINDOWS */
  143. #if defined(SDL_ENABLE_SYSWM_WINRT) && !defined(SDL_DISABLE_SYSWM_WINRT_TYPES)
  144. #include <Inspectable.h>
  145. #endif /* SDL_ENABLE_SYSWM_WINRT */
  146. #if defined(SDL_ENABLE_SYSWM_X11) && !defined(SDL_DISABLE_SYSWM_X11_TYPES)
  147. #include <X11/Xlib.h>
  148. #include <X11/Xatom.h>
  149. #endif /* SDL_ENABLE_SYSWM_X11 */
  150. #endif /* !SDL_DISABLE_SYSWM_TYPES */
  151. #include <SDL3/SDL_begin_code.h>
  152. /* Set up for C function definitions, even when using C++ */
  153. #ifdef __cplusplus
  154. extern "C" {
  155. #endif
  156. /* This is the current version of structures in this file */
  157. #define SDL_SYSWM_CURRENT_VERSION 1
  158. #define SDL_SYSWM_INFO_SIZE_V1 (16 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)))
  159. #define SDL_SYSWM_CURRENT_INFO_SIZE SDL_SYSWM_INFO_SIZE_V1
  160. /* This is the tag associated with a Metal view so you can find it */
  161. #define SDL_METALVIEW_TAG 255
  162. /**
  163. * These are the various supported windowing subsystems
  164. */
  165. typedef enum
  166. {
  167. SDL_SYSWM_UNKNOWN,
  168. SDL_SYSWM_ANDROID,
  169. SDL_SYSWM_COCOA,
  170. SDL_SYSWM_HAIKU,
  171. SDL_SYSWM_KMSDRM,
  172. SDL_SYSWM_RISCOS,
  173. SDL_SYSWM_UIKIT,
  174. SDL_SYSWM_VIVANTE,
  175. SDL_SYSWM_WAYLAND,
  176. SDL_SYSWM_WINDOWS,
  177. SDL_SYSWM_WINRT,
  178. SDL_SYSWM_X11
  179. } SDL_SYSWM_TYPE;
  180. /**
  181. * The custom event structure.
  182. */
  183. struct SDL_SysWMmsg
  184. {
  185. Uint32 version;
  186. Uint32 subsystem; /**< SDL_SYSWM_TYPE */
  187. Uint32 padding[(2 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)) - 2 * sizeof(Uint32)) / sizeof(Uint32)];
  188. union
  189. {
  190. #if defined(SDL_ENABLE_SYSWM_WINDOWS)
  191. struct {
  192. HWND hwnd; /**< The window for the message */
  193. UINT msg; /**< The type of message */
  194. WPARAM wParam; /**< WORD message parameter */
  195. LPARAM lParam; /**< LONG message parameter */
  196. } win;
  197. #endif
  198. #if defined(SDL_ENABLE_SYSWM_X11)
  199. struct {
  200. XEvent event;
  201. } x11;
  202. #endif
  203. /* Can't have an empty union */
  204. int dummy;
  205. } msg;
  206. };
  207. /**
  208. * The custom window manager information structure.
  209. *
  210. * When this structure is returned, it holds information about which
  211. * low level system it is using, and will be one of SDL_SYSWM_TYPE.
  212. */
  213. struct SDL_SysWMinfo
  214. {
  215. Uint32 version;
  216. Uint32 subsystem; /**< SDL_SYSWM_TYPE */
  217. Uint32 padding[(2 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)) - 2 * sizeof(Uint32)) / sizeof(Uint32)];
  218. union
  219. {
  220. #if defined(SDL_ENABLE_SYSWM_WINDOWS)
  221. struct
  222. {
  223. HWND window; /**< The window handle */
  224. HDC hdc; /**< The window device context */
  225. HINSTANCE hinstance; /**< The instance handle */
  226. } win;
  227. #endif
  228. #if defined(SDL_ENABLE_SYSWM_WINRT)
  229. struct
  230. {
  231. IInspectable * window; /**< The WinRT CoreWindow */
  232. } winrt;
  233. #endif
  234. #if defined(SDL_ENABLE_SYSWM_X11)
  235. struct
  236. {
  237. Display *display; /**< The X11 display */
  238. int screen; /**< The X11 screen */
  239. Window window; /**< The X11 window */
  240. } x11;
  241. #endif
  242. #if defined(SDL_ENABLE_SYSWM_COCOA)
  243. struct
  244. {
  245. #if defined(__OBJC__) && defined(__has_feature)
  246. #if __has_feature(objc_arc)
  247. NSWindow __unsafe_unretained *window; /**< The Cocoa window */
  248. #else
  249. NSWindow *window; /**< The Cocoa window */
  250. #endif
  251. #else
  252. NSWindow *window; /**< The Cocoa window */
  253. #endif
  254. } cocoa;
  255. #endif
  256. #if defined(SDL_ENABLE_SYSWM_UIKIT)
  257. struct
  258. {
  259. #if defined(__OBJC__) && defined(__has_feature)
  260. #if __has_feature(objc_arc)
  261. UIWindow __unsafe_unretained *window; /**< The UIKit window */
  262. #else
  263. UIWindow *window; /**< The UIKit window */
  264. #endif
  265. #else
  266. UIWindow *window; /**< The UIKit window */
  267. #endif
  268. GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
  269. GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
  270. GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
  271. } uikit;
  272. #endif
  273. #if defined(SDL_ENABLE_SYSWM_WAYLAND)
  274. struct
  275. {
  276. struct wl_display *display; /**< Wayland display */
  277. struct wl_surface *surface; /**< Wayland surface */
  278. struct wl_egl_window *egl_window; /**< Wayland EGL window (native window) */
  279. struct xdg_surface *xdg_surface; /**< Wayland xdg surface (window manager handle) */
  280. struct xdg_toplevel *xdg_toplevel; /**< Wayland xdg toplevel role */
  281. struct xdg_popup *xdg_popup; /**< Wayland xdg popup role */
  282. struct xdg_positioner *xdg_positioner; /**< Wayland xdg positioner, for popup */
  283. } wl;
  284. #endif
  285. #if defined(SDL_ENABLE_SYSWM_ANDROID)
  286. struct
  287. {
  288. ANativeWindow *window;
  289. EGLSurface surface;
  290. } android;
  291. #endif
  292. #if defined(SDL_ENABLE_SYSWM_VIVANTE)
  293. struct
  294. {
  295. EGLNativeDisplayType display;
  296. EGLNativeWindowType window;
  297. } vivante;
  298. #endif
  299. #if defined(SDL_ENABLE_SYSWM_KMSDRM)
  300. struct
  301. {
  302. int dev_index; /**< Device index (ex: the X in /dev/dri/cardX) */
  303. int drm_fd; /**< DRM FD (unavailable on Vulkan windows) */
  304. struct gbm_device *gbm_dev; /**< GBM device (unavailable on Vulkan windows) */
  305. } kmsdrm;
  306. #endif
  307. /* Make sure this union has enough room for 14 pointers */
  308. void *dummy_ptrs[14];
  309. Uint64 dummy_ints[14];
  310. } info;
  311. };
  312. SDL_COMPILE_TIME_ASSERT(SDL_SysWMinfo_size, sizeof(struct SDL_SysWMinfo) == SDL_SYSWM_CURRENT_INFO_SIZE);
  313. typedef struct SDL_SysWMinfo SDL_SysWMinfo;
  314. /**
  315. * Get driver-specific information about a window.
  316. *
  317. * You must include SDL_syswm.h for the declaration of SDL_SysWMinfo.
  318. *
  319. * \param window the window about which information is being requested
  320. * \param info an SDL_SysWMinfo structure filled in with window information
  321. * \param version the version of info being requested, should be
  322. * SDL_SYSWM_CURRENT_VERSION
  323. * \returns 0 on success or a negative error code on failure; call
  324. * SDL_GetError() for more information.
  325. *
  326. * \since This function is available since SDL 3.0.0.
  327. */
  328. extern DECLSPEC int SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info, Uint32 version);
  329. /* Ends C function definitions when using C++ */
  330. #ifdef __cplusplus
  331. }
  332. #endif
  333. #include <SDL3/SDL_close_code.h>
  334. #endif /* SDL_syswm_h_ */