SDL_syswm.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <[email protected]>
  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 <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_video.h>
  28. #include <SDL3/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. * As of SDL 3.0, this file no longer includes the platform specific headers
  38. * and types. You should include the headers you need and define one or more
  39. * of the following for the subsystems you're working with:
  40. *
  41. * SDL_ENABLE_SYSWM_ANDROID
  42. * SDL_ENABLE_SYSWM_COCOA
  43. * SDL_ENABLE_SYSWM_KMSDRM
  44. * SDL_ENABLE_SYSWM_UIKIT
  45. * SDL_ENABLE_SYSWM_VIVANTE
  46. * SDL_ENABLE_SYSWM_WAYLAND
  47. * SDL_ENABLE_SYSWM_WINDOWS
  48. * SDL_ENABLE_SYSWM_WINRT
  49. * SDL_ENABLE_SYSWM_X11
  50. */
  51. struct SDL_SysWMinfo;
  52. #include <SDL3/begin_code.h>
  53. /* Set up for C function definitions, even when using C++ */
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /* This is the current version of structures in this file */
  58. #define SDL_SYSWM_CURRENT_VERSION 1
  59. #define SDL_SYSWM_INFO_SIZE_V1 (16 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)))
  60. #define SDL_SYSWM_CURRENT_INFO_SIZE SDL_SYSWM_INFO_SIZE_V1
  61. /* This is the tag associated with a Metal view so you can find it */
  62. #define SDL_METALVIEW_TAG 255
  63. #if !defined(SDL_PROTOTYPES_ONLY)
  64. /**
  65. * These are the various supported windowing subsystems
  66. */
  67. typedef enum
  68. {
  69. SDL_SYSWM_UNKNOWN,
  70. SDL_SYSWM_ANDROID,
  71. SDL_SYSWM_COCOA,
  72. SDL_SYSWM_HAIKU,
  73. SDL_SYSWM_KMSDRM,
  74. SDL_SYSWM_RISCOS,
  75. SDL_SYSWM_UIKIT,
  76. SDL_SYSWM_VIVANTE,
  77. SDL_SYSWM_WAYLAND,
  78. SDL_SYSWM_WINDOWS,
  79. SDL_SYSWM_WINRT,
  80. SDL_SYSWM_X11
  81. } SDL_SYSWM_TYPE;
  82. /**
  83. * The custom event structure.
  84. */
  85. struct SDL_SysWMmsg
  86. {
  87. Uint32 version;
  88. Uint32 subsystem; /**< SDL_SYSWM_TYPE */
  89. Uint32 padding[(2 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)) - 2 * sizeof(Uint32)) / sizeof(Uint32)];
  90. union
  91. {
  92. #if defined(SDL_ENABLE_SYSWM_WINDOWS)
  93. struct {
  94. HWND hwnd; /**< The window for the message */
  95. UINT msg; /**< The type of message */
  96. WPARAM wParam; /**< WORD message parameter */
  97. LPARAM lParam; /**< LONG message parameter */
  98. } win;
  99. #endif
  100. #if defined(SDL_ENABLE_SYSWM_X11)
  101. struct {
  102. XEvent event;
  103. } x11;
  104. #endif
  105. /* Can't have an empty union */
  106. int dummy;
  107. } msg;
  108. };
  109. /**
  110. * The custom window manager information structure.
  111. *
  112. * When this structure is returned, it holds information about which
  113. * low level system it is using, and will be one of SDL_SYSWM_TYPE.
  114. */
  115. struct SDL_SysWMinfo
  116. {
  117. Uint32 version;
  118. Uint32 subsystem; /**< SDL_SYSWM_TYPE */
  119. Uint32 padding[(2 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)) - 2 * sizeof(Uint32)) / sizeof(Uint32)];
  120. union
  121. {
  122. #if defined(SDL_ENABLE_SYSWM_WINDOWS)
  123. struct
  124. {
  125. HWND window; /**< The window handle */
  126. HDC hdc; /**< The window device context */
  127. HINSTANCE hinstance; /**< The instance handle */
  128. } win;
  129. #endif
  130. #if defined(SDL_ENABLE_SYSWM_WINRT)
  131. struct
  132. {
  133. IInspectable * window; /**< The WinRT CoreWindow */
  134. } winrt;
  135. #endif
  136. #if defined(SDL_ENABLE_SYSWM_X11)
  137. struct
  138. {
  139. Display *display; /**< The X11 display */
  140. int screen; /**< The X11 screen */
  141. Window window; /**< The X11 window */
  142. } x11;
  143. #endif
  144. #if defined(SDL_ENABLE_SYSWM_COCOA)
  145. struct
  146. {
  147. #if defined(__OBJC__) && defined(__has_feature)
  148. #if __has_feature(objc_arc)
  149. NSWindow __unsafe_unretained *window; /**< The Cocoa window */
  150. #else
  151. NSWindow *window; /**< The Cocoa window */
  152. #endif
  153. #else
  154. NSWindow *window; /**< The Cocoa window */
  155. #endif
  156. } cocoa;
  157. #endif
  158. #if defined(SDL_ENABLE_SYSWM_UIKIT)
  159. struct
  160. {
  161. #if defined(__OBJC__) && defined(__has_feature)
  162. #if __has_feature(objc_arc)
  163. UIWindow __unsafe_unretained *window; /**< The UIKit window */
  164. #else
  165. UIWindow *window; /**< The UIKit window */
  166. #endif
  167. #else
  168. UIWindow *window; /**< The UIKit window */
  169. #endif
  170. GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
  171. GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
  172. GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
  173. } uikit;
  174. #endif
  175. #if defined(SDL_ENABLE_SYSWM_WAYLAND)
  176. struct
  177. {
  178. struct wl_display *display; /**< Wayland display */
  179. struct wl_surface *surface; /**< Wayland surface */
  180. struct wl_egl_window *egl_window; /**< Wayland EGL window (native window) */
  181. struct xdg_surface *xdg_surface; /**< Wayland xdg surface (window manager handle) */
  182. struct xdg_toplevel *xdg_toplevel; /**< Wayland xdg toplevel role */
  183. struct xdg_popup *xdg_popup; /**< Wayland xdg popup role */
  184. struct xdg_positioner *xdg_positioner; /**< Wayland xdg positioner, for popup */
  185. } wl;
  186. #endif
  187. #if defined(SDL_ENABLE_SYSWM_ANDROID)
  188. struct
  189. {
  190. ANativeWindow *window;
  191. EGLSurface surface;
  192. } android;
  193. #endif
  194. #if defined(SDL_ENABLE_SYSWM_VIVANTE)
  195. struct
  196. {
  197. EGLNativeDisplayType display;
  198. EGLNativeWindowType window;
  199. } vivante;
  200. #endif
  201. #if defined(SDL_ENABLE_SYSWM_KMSDRM)
  202. struct
  203. {
  204. int dev_index; /**< Device index (ex: the X in /dev/dri/cardX) */
  205. int drm_fd; /**< DRM FD (unavailable on Vulkan windows) */
  206. struct gbm_device *gbm_dev; /**< GBM device (unavailable on Vulkan windows) */
  207. } kmsdrm;
  208. #endif
  209. /* Make sure this union has enough room for 14 pointers */
  210. void *dummy_ptrs[14];
  211. Uint64 dummy_ints[14];
  212. } info;
  213. };
  214. SDL_COMPILE_TIME_ASSERT(SDL_SysWMinfo_size, sizeof(struct SDL_SysWMinfo) == SDL_SYSWM_CURRENT_INFO_SIZE);
  215. #endif /* SDL_PROTOTYPES_ONLY */
  216. typedef struct SDL_SysWMinfo SDL_SysWMinfo;
  217. /**
  218. * Get driver-specific information about a window.
  219. *
  220. * You must include SDL_syswm.h for the declaration of SDL_SysWMinfo.
  221. *
  222. * \param window the window about which information is being requested
  223. * \param info an SDL_SysWMinfo structure filled in with window information
  224. * \param version the version of info being requested, should be
  225. * SDL_SYSWM_CURRENT_VERSION
  226. * \returns 0 on success or a negative error code on failure; call
  227. * SDL_GetError() for more information.
  228. *
  229. * \since This function is available since SDL 3.0.0.
  230. */
  231. extern DECLSPEC int SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info, Uint32 version);
  232. /* Ends C function definitions when using C++ */
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236. #include <SDL3/close_code.h>
  237. #endif /* SDL_syswm_h_ */
  238. /* vi: set ts=4 sw=4 expandtab: */