SDL_syswm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  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 "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_video.h"
  28. #include "SDL_version.h"
  29. /*
  30. * \file 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_EventState().
  36. */
  37. /* WIKI CATEGORY: SYSWM */
  38. struct SDL_SysWMinfo;
  39. #if !defined(SDL_PROTOTYPES_ONLY)
  40. #if defined(SDL_VIDEO_DRIVER_WINDOWS)
  41. #ifndef WIN32_LEAN_AND_MEAN
  42. #define WIN32_LEAN_AND_MEAN
  43. #endif
  44. #ifndef NOMINMAX /* don't define min() and max(). */
  45. #define NOMINMAX
  46. #endif
  47. #include <windows.h>
  48. #endif
  49. #if defined(SDL_VIDEO_DRIVER_WINRT)
  50. #include <Inspectable.h>
  51. #endif
  52. /* This is the structure for custom window manager events */
  53. #if defined(SDL_VIDEO_DRIVER_X11)
  54. #if defined(__APPLE__) && defined(__MACH__)
  55. /* conflicts with Quickdraw.h */
  56. #define Cursor X11Cursor
  57. #endif
  58. #include <X11/Xlib.h>
  59. #include <X11/Xatom.h>
  60. #if defined(__APPLE__) && defined(__MACH__)
  61. /* matches the re-define above */
  62. #undef Cursor
  63. #endif
  64. #endif /* defined(SDL_VIDEO_DRIVER_X11) */
  65. #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
  66. #include <directfb.h>
  67. #endif
  68. #if defined(SDL_VIDEO_DRIVER_COCOA)
  69. #ifdef __OBJC__
  70. @class NSWindow;
  71. #else
  72. typedef struct _NSWindow NSWindow;
  73. #endif
  74. #endif
  75. #if defined(SDL_VIDEO_DRIVER_UIKIT)
  76. #ifdef __OBJC__
  77. #include <UIKit/UIKit.h>
  78. #else
  79. typedef struct _UIWindow UIWindow;
  80. typedef struct _UIViewController UIViewController;
  81. #endif
  82. typedef Uint32 GLuint;
  83. #endif
  84. #if defined(SDL_VIDEO_VULKAN) || defined(SDL_VIDEO_METAL)
  85. #define SDL_METALVIEW_TAG 255
  86. #endif
  87. #if defined(SDL_VIDEO_DRIVER_ANDROID)
  88. typedef struct ANativeWindow ANativeWindow;
  89. typedef void *EGLSurface;
  90. #endif
  91. #if defined(SDL_VIDEO_DRIVER_VIVANTE)
  92. #include "SDL_egl.h"
  93. #endif
  94. #if defined(SDL_VIDEO_DRIVER_OS2)
  95. #define INCL_WIN
  96. #include <os2.h>
  97. #endif
  98. #endif /* SDL_PROTOTYPES_ONLY */
  99. #if defined(SDL_VIDEO_DRIVER_KMSDRM)
  100. struct gbm_device;
  101. #endif
  102. #include "begin_code.h"
  103. /* Set up for C function definitions, even when using C++ */
  104. #ifdef __cplusplus
  105. extern "C" {
  106. #endif
  107. #if !defined(SDL_PROTOTYPES_ONLY)
  108. /**
  109. * These are the various supported windowing subsystems
  110. */
  111. typedef enum SDL_SYSWM_TYPE
  112. {
  113. SDL_SYSWM_UNKNOWN,
  114. SDL_SYSWM_WINDOWS,
  115. SDL_SYSWM_X11,
  116. SDL_SYSWM_DIRECTFB,
  117. SDL_SYSWM_COCOA,
  118. SDL_SYSWM_UIKIT,
  119. SDL_SYSWM_WAYLAND,
  120. SDL_SYSWM_MIR, /* no longer available, left for API/ABI compatibility. Remove in 2.1! */
  121. SDL_SYSWM_WINRT,
  122. SDL_SYSWM_ANDROID,
  123. SDL_SYSWM_VIVANTE,
  124. SDL_SYSWM_OS2,
  125. SDL_SYSWM_HAIKU,
  126. SDL_SYSWM_KMSDRM,
  127. SDL_SYSWM_RISCOS
  128. } SDL_SYSWM_TYPE;
  129. /**
  130. * The custom event structure.
  131. */
  132. struct SDL_SysWMmsg
  133. {
  134. SDL_version version;
  135. SDL_SYSWM_TYPE subsystem;
  136. union
  137. {
  138. #if defined(SDL_VIDEO_DRIVER_WINDOWS)
  139. struct {
  140. HWND hwnd; /**< The window for the message */
  141. UINT msg; /**< The type of message */
  142. WPARAM wParam; /**< WORD message parameter */
  143. LPARAM lParam; /**< LONG message parameter */
  144. } win;
  145. #endif
  146. #if defined(SDL_VIDEO_DRIVER_X11)
  147. struct {
  148. XEvent event;
  149. } x11;
  150. #endif
  151. #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
  152. struct {
  153. DFBEvent event;
  154. } dfb;
  155. #endif
  156. #if defined(SDL_VIDEO_DRIVER_COCOA)
  157. struct
  158. {
  159. /* Latest version of Xcode clang complains about empty structs in C v. C++:
  160. error: empty struct has size 0 in C, size 1 in C++
  161. */
  162. int dummy;
  163. /* No Cocoa window events yet */
  164. } cocoa;
  165. #endif
  166. #if defined(SDL_VIDEO_DRIVER_UIKIT)
  167. struct
  168. {
  169. int dummy;
  170. /* No UIKit window events yet */
  171. } uikit;
  172. #endif
  173. #if defined(SDL_VIDEO_DRIVER_VIVANTE)
  174. struct
  175. {
  176. int dummy;
  177. /* No Vivante window events yet */
  178. } vivante;
  179. #endif
  180. #if defined(SDL_VIDEO_DRIVER_OS2)
  181. struct
  182. {
  183. BOOL fFrame; /**< TRUE if hwnd is a frame window */
  184. HWND hwnd; /**< The window receiving the message */
  185. ULONG msg; /**< The message identifier */
  186. MPARAM mp1; /**< The first first message parameter */
  187. MPARAM mp2; /**< The second first message parameter */
  188. } os2;
  189. #endif
  190. /* Can't have an empty union */
  191. int dummy;
  192. } msg;
  193. };
  194. /**
  195. * The custom window manager information structure.
  196. *
  197. * When this structure is returned, it holds information about which low level
  198. * system it is using, and will be one of SDL_SYSWM_TYPE.
  199. */
  200. struct SDL_SysWMinfo
  201. {
  202. SDL_version version;
  203. SDL_SYSWM_TYPE subsystem;
  204. union
  205. {
  206. #if defined(SDL_VIDEO_DRIVER_WINDOWS)
  207. struct
  208. {
  209. HWND window; /**< The window handle */
  210. HDC hdc; /**< The window device context */
  211. HINSTANCE hinstance; /**< The instance handle */
  212. } win;
  213. #endif
  214. #if defined(SDL_VIDEO_DRIVER_WINRT)
  215. struct
  216. {
  217. IInspectable * window; /**< The WinRT CoreWindow */
  218. } winrt;
  219. #endif
  220. #if defined(SDL_VIDEO_DRIVER_X11)
  221. struct
  222. {
  223. Display *display; /**< The X11 display */
  224. Window window; /**< The X11 window */
  225. } x11;
  226. #endif
  227. #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
  228. struct
  229. {
  230. IDirectFB *dfb; /**< The directfb main interface */
  231. IDirectFBWindow *window; /**< The directfb window handle */
  232. IDirectFBSurface *surface; /**< The directfb client surface */
  233. } dfb;
  234. #endif
  235. #if defined(SDL_VIDEO_DRIVER_COCOA)
  236. struct
  237. {
  238. #if defined(__OBJC__) && defined(__has_feature)
  239. #if __has_feature(objc_arc)
  240. NSWindow __unsafe_unretained *window; /**< The Cocoa window */
  241. #else
  242. NSWindow *window; /**< The Cocoa window */
  243. #endif
  244. #else
  245. NSWindow *window; /**< The Cocoa window */
  246. #endif
  247. } cocoa;
  248. #endif
  249. #if defined(SDL_VIDEO_DRIVER_UIKIT)
  250. struct
  251. {
  252. #if defined(__OBJC__) && defined(__has_feature)
  253. #if __has_feature(objc_arc)
  254. UIWindow __unsafe_unretained *window; /**< The UIKit window */
  255. #else
  256. UIWindow *window; /**< The UIKit window */
  257. #endif
  258. #else
  259. UIWindow *window; /**< The UIKit window */
  260. #endif
  261. GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
  262. GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
  263. GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
  264. } uikit;
  265. #endif
  266. #if defined(SDL_VIDEO_DRIVER_WAYLAND)
  267. struct
  268. {
  269. struct wl_display *display; /**< Wayland display */
  270. struct wl_surface *surface; /**< Wayland surface */
  271. void *shell_surface; /**< DEPRECATED Wayland shell_surface (window manager handle) */
  272. struct wl_egl_window *egl_window; /**< Wayland EGL window (native window) */
  273. struct xdg_surface *xdg_surface; /**< Wayland xdg surface (window manager handle) */
  274. struct xdg_toplevel *xdg_toplevel; /**< Wayland xdg toplevel role */
  275. struct xdg_popup *xdg_popup; /**< Wayland xdg popup role */
  276. struct xdg_positioner *xdg_positioner; /**< Wayland xdg positioner, for popup */
  277. } wl;
  278. #endif
  279. #if defined(SDL_VIDEO_DRIVER_MIR) /* no longer available, left for API/ABI compatibility. Remove in 2.1! */
  280. struct
  281. {
  282. void *connection; /**< Mir display server connection */
  283. void *surface; /**< Mir surface */
  284. } mir;
  285. #endif
  286. #if defined(SDL_VIDEO_DRIVER_ANDROID)
  287. struct
  288. {
  289. ANativeWindow *window;
  290. EGLSurface surface;
  291. } android;
  292. #endif
  293. #if defined(SDL_VIDEO_DRIVER_OS2)
  294. struct
  295. {
  296. HWND hwnd; /**< The window handle */
  297. HWND hwndFrame; /**< The frame window handle */
  298. } os2;
  299. #endif
  300. #if defined(SDL_VIDEO_DRIVER_VIVANTE)
  301. struct
  302. {
  303. EGLNativeDisplayType display;
  304. EGLNativeWindowType window;
  305. } vivante;
  306. #endif
  307. #if defined(SDL_VIDEO_DRIVER_KMSDRM)
  308. struct
  309. {
  310. int dev_index; /**< Device index (ex: the X in /dev/dri/cardX) */
  311. int drm_fd; /**< DRM FD (unavailable on Vulkan windows) */
  312. struct gbm_device *gbm_dev; /**< GBM device (unavailable on Vulkan windows) */
  313. } kmsdrm;
  314. #endif
  315. /* Make sure this union is always 64 bytes (8 64-bit pointers). */
  316. /* Be careful not to overflow this if you add a new target! */
  317. Uint8 dummy[64];
  318. } info;
  319. };
  320. #endif /* SDL_PROTOTYPES_ONLY */
  321. typedef struct SDL_SysWMinfo SDL_SysWMinfo;
  322. /**
  323. * Get driver-specific information about a window.
  324. *
  325. * You must include SDL_syswm.h for the declaration of SDL_SysWMinfo.
  326. *
  327. * The caller must initialize the `info` structure's version by using
  328. * `SDL_VERSION(&info.version)`, and then this function will fill in the rest
  329. * of the structure with information about the given window.
  330. *
  331. * \param window the window about which information is being requested
  332. * \param info an SDL_SysWMinfo structure filled in with window information
  333. * \returns SDL_TRUE if the function is implemented and the `version` member
  334. * of the `info` struct is valid, or SDL_FALSE if the information
  335. * could not be retrieved; call SDL_GetError() for more information.
  336. *
  337. * \since This function is available since SDL 2.0.0.
  338. */
  339. extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window * window,
  340. SDL_SysWMinfo * info);
  341. /* Ends C function definitions when using C++ */
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #include "close_code.h"
  346. #endif /* SDL_syswm_h_ */
  347. /* vi: set ts=4 sw=4 expandtab: */