SDL_syswm.h 10 KB

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