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