SDL_syswm.h 11 KB

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