SDL_syswm.h 11 KB

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