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