SDL_syswm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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_TYPE;
  124. /**
  125. * The custom event structure.
  126. */
  127. struct SDL_SysWMmsg
  128. {
  129. SDL_version version;
  130. SDL_SYSWM_TYPE subsystem;
  131. union
  132. {
  133. #if defined(SDL_VIDEO_DRIVER_WINDOWS)
  134. struct {
  135. HWND hwnd; /**< The window for the message */
  136. UINT msg; /**< The type of message */
  137. WPARAM wParam; /**< WORD message parameter */
  138. LPARAM lParam; /**< LONG message parameter */
  139. } win;
  140. #endif
  141. #if defined(SDL_VIDEO_DRIVER_X11)
  142. struct {
  143. XEvent event;
  144. } x11;
  145. #endif
  146. #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
  147. struct {
  148. DFBEvent event;
  149. } dfb;
  150. #endif
  151. #if defined(SDL_VIDEO_DRIVER_COCOA)
  152. struct
  153. {
  154. /* Latest version of Xcode clang complains about empty structs in C v. C++:
  155. error: empty struct has size 0 in C, size 1 in C++
  156. */
  157. int dummy;
  158. /* No Cocoa window events yet */
  159. } cocoa;
  160. #endif
  161. #if defined(SDL_VIDEO_DRIVER_UIKIT)
  162. struct
  163. {
  164. int dummy;
  165. /* No UIKit window events yet */
  166. } uikit;
  167. #endif
  168. #if defined(SDL_VIDEO_DRIVER_VIVANTE)
  169. struct
  170. {
  171. int dummy;
  172. /* No Vivante window events yet */
  173. } vivante;
  174. #endif
  175. #if defined(SDL_VIDEO_DRIVER_OS2)
  176. struct
  177. {
  178. BOOL fFrame; /**< TRUE if hwnd is a frame window */
  179. HWND hwnd; /**< The window receiving the message */
  180. ULONG msg; /**< The message identifier */
  181. MPARAM mp1; /**< The first first message parameter */
  182. MPARAM mp2; /**< The second first message parameter */
  183. } os2;
  184. #endif
  185. /* Can't have an empty union */
  186. int dummy;
  187. } msg;
  188. };
  189. /**
  190. * The custom window manager information structure.
  191. *
  192. * When this structure is returned, it holds information about which
  193. * low level system it is using, and will be one of SDL_SYSWM_TYPE.
  194. */
  195. struct SDL_SysWMinfo
  196. {
  197. SDL_version version;
  198. SDL_SYSWM_TYPE subsystem;
  199. union
  200. {
  201. #if defined(SDL_VIDEO_DRIVER_WINDOWS)
  202. struct
  203. {
  204. HWND window; /**< The window handle */
  205. HDC hdc; /**< The window device context */
  206. HINSTANCE hinstance; /**< The instance handle */
  207. } win;
  208. #endif
  209. #if defined(SDL_VIDEO_DRIVER_WINRT)
  210. struct
  211. {
  212. IInspectable * window; /**< The WinRT CoreWindow */
  213. } winrt;
  214. #endif
  215. #if defined(SDL_VIDEO_DRIVER_X11)
  216. struct
  217. {
  218. Display *display; /**< The X11 display */
  219. Window window; /**< The X11 window */
  220. } x11;
  221. #endif
  222. #if defined(SDL_VIDEO_DRIVER_DIRECTFB)
  223. struct
  224. {
  225. IDirectFB *dfb; /**< The directfb main interface */
  226. IDirectFBWindow *window; /**< The directfb window handle */
  227. IDirectFBSurface *surface; /**< The directfb client surface */
  228. } dfb;
  229. #endif
  230. #if defined(SDL_VIDEO_DRIVER_COCOA)
  231. struct
  232. {
  233. #if defined(__OBJC__) && defined(__has_feature)
  234. #if __has_feature(objc_arc)
  235. NSWindow __unsafe_unretained *window; /**< The Cocoa window */
  236. #else
  237. NSWindow *window; /**< The Cocoa window */
  238. #endif
  239. #else
  240. NSWindow *window; /**< The Cocoa window */
  241. #endif
  242. } cocoa;
  243. #endif
  244. #if defined(SDL_VIDEO_DRIVER_UIKIT)
  245. struct
  246. {
  247. #if defined(__OBJC__) && defined(__has_feature)
  248. #if __has_feature(objc_arc)
  249. UIWindow __unsafe_unretained *window; /**< The UIKit window */
  250. #else
  251. UIWindow *window; /**< The UIKit window */
  252. #endif
  253. #else
  254. UIWindow *window; /**< The UIKit window */
  255. #endif
  256. GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
  257. GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
  258. GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
  259. } uikit;
  260. #endif
  261. #if defined(SDL_VIDEO_DRIVER_WAYLAND)
  262. struct
  263. {
  264. struct wl_display *display; /**< Wayland display */
  265. struct wl_surface *surface; /**< Wayland surface */
  266. void *shell_surface; /**< DEPRECATED Wayland shell_surface (window manager handle) */
  267. struct wl_egl_window *egl_window; /**< Wayland EGL window (native window) */
  268. struct xdg_surface *xdg_surface; /**< Wayland xdg surface (window manager handle) */
  269. } wl;
  270. #endif
  271. #if defined(SDL_VIDEO_DRIVER_MIR) /* no longer available, left for API/ABI compatibility. Remove in 2.1! */
  272. struct
  273. {
  274. void *connection; /**< Mir display server connection */
  275. void *surface; /**< Mir surface */
  276. } mir;
  277. #endif
  278. #if defined(SDL_VIDEO_DRIVER_ANDROID)
  279. struct
  280. {
  281. ANativeWindow *window;
  282. EGLSurface surface;
  283. } android;
  284. #endif
  285. #if defined(SDL_VIDEO_DRIVER_OS2)
  286. struct
  287. {
  288. HWND hwnd; /**< The window handle */
  289. HWND hwndFrame; /**< The frame window handle */
  290. } os2;
  291. #endif
  292. #if defined(SDL_VIDEO_DRIVER_VIVANTE)
  293. struct
  294. {
  295. EGLNativeDisplayType display;
  296. EGLNativeWindowType window;
  297. } vivante;
  298. #endif
  299. #if defined(SDL_VIDEO_DRIVER_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 is always 64 bytes (8 64-bit pointers). */
  308. /* Be careful not to overflow this if you add a new target! */
  309. Uint8 dummy[64];
  310. } info;
  311. };
  312. #endif /* SDL_PROTOTYPES_ONLY */
  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. * The caller must initialize the `info` structure's version by using
  320. * `SDL_VERSION(&info.version)`, and then this function will fill in the rest
  321. * of the structure with information about the given window.
  322. *
  323. * \param window the window about which information is being requested
  324. * \param info an SDL_SysWMinfo structure filled in with window information
  325. * \returns SDL_TRUE if the function is implemented and the `version` member
  326. * of the `info` struct is valid, or SDL_FALSE if the information
  327. * could not be retrieved; call SDL_GetError() for more information.
  328. *
  329. * \since This function is available since SDL 2.0.0.
  330. */
  331. extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window * window,
  332. SDL_SysWMinfo * info);
  333. /* Ends C function definitions when using C++ */
  334. #ifdef __cplusplus
  335. }
  336. #endif
  337. #include "close_code.h"
  338. #endif /* SDL_syswm_h_ */
  339. /* vi: set ts=4 sw=4 expandtab: */