SDL_syswm.h 9.4 KB

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