SDL 3.0
SDL_syswm.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 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 * \brief Include file for SDL custom system window manager hooks.
26 */
27
28#ifndef SDL_syswm_h_
29#define SDL_syswm_h_
30
31#include <SDL3/SDL_stdinc.h>
32#include <SDL3/SDL_error.h>
34#include <SDL3/SDL_video.h>
35
36/**
37 * \brief SDL_syswm.h
38 *
39 * Your application has access to a special type of event ::SDL_EVENT_SYSWM,
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_SetEventEnabled().
43 */
44
45/**
46 * The available subsystems based on platform
47 */
48#if !defined(SDL_DISABLE_SYSWM_PLATFORMS)
49
50#ifndef SDL_DISABLE_SYSWM_ANDROID
51#ifdef __ANDROID__
52#define SDL_ENABLE_SYSWM_ANDROID
53#endif
54#endif /* !SDL_DISABLE_SYSWM_ANDROID */
55
56#ifndef SDL_DISABLE_SYSWM_COCOA
57#ifdef __MACOS__
58#define SDL_ENABLE_SYSWM_COCOA
59#endif
60#endif /* !SDL_DISABLE_SYSWM_COCOA */
61
62#ifndef SDL_DISABLE_SYSWM_HAIKU
63#ifdef __HAIKU__
64#define SDL_ENABLE_SYSWM_HAIKU
65#endif
66#endif /* !SDL_DISABLE_SYSWM_HAIKU */
67
68#ifndef SDL_DISABLE_SYSWM_KMSDRM
69#if defined(__LINUX__) || defined(__FREEBSD__) || defined(__OPENBSD__)
70#define SDL_ENABLE_SYSWM_KMSDRM
71#endif
72#endif /* !SDL_DISABLE_SYSWM_KMSDRM */
73
74#ifndef SDL_DISABLE_SYSWM_RISCOS
75#ifdef __RISCOS__
76#define SDL_ENABLE_SYSWM_RISCOS
77#endif
78#endif /* !SDL_DISABLE_SYSWM_RISCOS */
79
80#ifndef SDL_DISABLE_SYSWM_UIKIT
81#if defined(__IOS__) || defined(__TVOS__)
82#define SDL_ENABLE_SYSWM_UIKIT
83#endif
84#endif /* !SDL_DISABLE_SYSWM_UIKIT */
85
86#ifndef SDL_DISABLE_SYSWM_VIVANTE
87/* Not enabled by default */
88#endif /* !SDL_DISABLE_SYSWM_VIVANTE */
89
90#ifndef SDL_DISABLE_SYSWM_WAYLAND
91#if defined(__LINUX__) || defined(__FREEBSD__)
92#define SDL_ENABLE_SYSWM_WAYLAND
93#endif
94#endif /* !SDL_DISABLE_SYSWM_WAYLAND */
95
96#ifndef SDL_DISABLE_SYSWM_WINDOWS
97#ifdef __WIN32__
98#define SDL_ENABLE_SYSWM_WINDOWS
99#endif
100#endif /* !SDL_DISABLE_SYSWM_WINDOWS */
101
102#ifndef SDL_DISABLE_SYSWM_WINRT
103#ifdef __WINRT__
104#define SDL_ENABLE_SYSWM_WINRT
105#endif
106#endif /* !SDL_DISABLE_SYSWM_WINRT */
107
108#ifndef SDL_DISABLE_SYSWM_X11
109#if defined(__unix__) && !defined(__WIN32__) && !defined(__ANDROID__)
110#define SDL_ENABLE_SYSWM_X11
111#endif
112#endif /* !SDL_DISABLE_SYSWM_X11 */
113
114#endif /* !SDL_DISABLE_SYSWM_PLATFORMS */
115
116/**
117 * Forward declaration of types used by subsystems
118 */
119#ifndef SDL_DISABLE_SYSWM_TYPES
120
121#if defined(SDL_ENABLE_SYSWM_ANDROID) && !defined(SDL_DISABLE_SYSWM_ANDROID_TYPES)
122typedef struct ANativeWindow ANativeWindow;
123typedef void *EGLSurface;
124#endif /* SDL_ENABLE_SYSWM_ANDROID */
125
126#if defined(SDL_ENABLE_SYSWM_COCOA) && !defined(SDL_DISABLE_SYSWM_COCOA_TYPES)
127#ifdef __OBJC__
128@class NSWindow;
129#else
130typedef struct _NSWindow NSWindow;
131#endif
132#endif /* SDL_ENABLE_SYSWM_COCOA */
133
134#if defined(SDL_ENABLE_SYSWM_KMSDRM) && !defined(SDL_DISABLE_SYSWM_KMSDRM_TYPES)
135struct gbm_device;
136#endif /* SDL_ENABLE_SYSWM_KMSDRM */
137
138#if defined(SDL_ENABLE_SYSWM_UIKIT) && !defined(SDL_DISABLE_SYSWM_UIKIT_TYPES)
139#ifdef __OBJC__
140#include <UIKit/UIKit.h>
141#else
142typedef struct _UIWindow UIWindow;
143typedef struct _UIViewController UIViewController;
144#endif
145typedef Uint32 GLuint;
146#endif /* SDL_ENABLE_SYSWM_UIKIT */
147
148#if defined(SDL_ENABLE_SYSWM_VIVANTE) && !defined(SDL_DISABLE_SYSWM_VIVANTE_TYPES)
149#include <SDL3/SDL_egl.h>
150#endif /* SDL_ENABLE_SYSWM_VIVANTE */
151
152#if defined(SDL_ENABLE_SYSWM_WAYLAND) && !defined(SDL_DISABLE_SYSWM_WAYLAND_TYPES)
153struct wl_display;
154struct wl_egl_window;
155struct wl_surface;
156struct xdg_popup;
157struct xdg_positioner;
158struct xdg_surface;
159struct xdg_toplevel;
160#endif /* SDL_ENABLE_SYSWM_WAYLAND */
161
162#if defined(SDL_ENABLE_SYSWM_WINDOWS) && !defined(SDL_DISABLE_SYSWM_WINDOWS_TYPES)
163#ifndef WIN32_LEAN_AND_MEAN
164#define WIN32_LEAN_AND_MEAN
165#endif
166#ifndef NOMINMAX /* don't define min() and max(). */
167#define NOMINMAX
168#endif
169#include <windows.h>
170#endif /* SDL_ENABLE_SYSWM_WINDOWS */
171
172#if defined(SDL_ENABLE_SYSWM_WINRT) && !defined(SDL_DISABLE_SYSWM_WINRT_TYPES)
173#include <Inspectable.h>
174#endif /* SDL_ENABLE_SYSWM_WINRT */
175
176#if defined(SDL_ENABLE_SYSWM_X11) && !defined(SDL_DISABLE_SYSWM_X11_TYPES)
177#include <X11/Xlib.h>
178#include <X11/Xatom.h>
179#endif /* SDL_ENABLE_SYSWM_X11 */
180
181#endif /* !SDL_DISABLE_SYSWM_TYPES */
182
183
184#include <SDL3/SDL_begin_code.h>
185/* Set up for C function definitions, even when using C++ */
186#ifdef __cplusplus
187extern "C" {
188#endif
189
190/* This is the current version of structures in this file */
191#define SDL_SYSWM_CURRENT_VERSION 1
192#define SDL_SYSWM_INFO_SIZE_V1 (16 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)))
193#define SDL_SYSWM_CURRENT_INFO_SIZE SDL_SYSWM_INFO_SIZE_V1
194
195/* This is the tag associated with a Metal view so you can find it */
196#define SDL_METALVIEW_TAG 255
197
198
199/**
200 * These are the various supported windowing subsystems
201 */
202typedef enum
203{
217
218/**
219 * The custom event structure.
220 */
222{
224 Uint32 subsystem; /**< SDL_SYSWM_TYPE */
225
226 Uint32 padding[(2 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)) - 2 * sizeof(Uint32)) / sizeof(Uint32)];
227
228 union
229 {
230#if defined(SDL_ENABLE_SYSWM_WINDOWS)
231 struct {
232 HWND hwnd; /**< The window for the message */
233 UINT msg; /**< The type of message */
234 WPARAM wParam; /**< WORD message parameter */
235 LPARAM lParam; /**< LONG message parameter */
236 } win;
237#endif
238#if defined(SDL_ENABLE_SYSWM_X11)
239 struct {
240 XEvent event;
241 } x11;
242#endif
243 /* Can't have an empty union */
244 int dummy;
246};
247
248/**
249 * The custom window manager information structure.
250 *
251 * When this structure is returned, it holds information about which
252 * low level system it is using, and will be one of SDL_SYSWM_TYPE.
253 */
255{
257 Uint32 subsystem; /**< SDL_SYSWM_TYPE */
258
259 Uint32 padding[(2 * (sizeof (void *) >= 8 ? sizeof (void *) : sizeof(Uint64)) - 2 * sizeof(Uint32)) / sizeof(Uint32)];
260
261 union
262 {
263#if defined(SDL_ENABLE_SYSWM_WINDOWS)
264 struct
265 {
266 HWND window; /**< The window handle */
267 HDC hdc; /**< The window device context */
268 HINSTANCE hinstance; /**< The instance handle */
269 } win;
270#endif
271#if defined(SDL_ENABLE_SYSWM_WINRT)
272 struct
273 {
274 IInspectable * window; /**< The WinRT CoreWindow */
275 } winrt;
276#endif
277#if defined(SDL_ENABLE_SYSWM_X11)
278 struct
279 {
280 Display *display; /**< The X11 display */
281 int screen; /**< The X11 screen */
282 Window window; /**< The X11 window */
283 } x11;
284#endif
285#if defined(SDL_ENABLE_SYSWM_COCOA)
286 struct
287 {
288#if defined(__OBJC__) && defined(__has_feature)
289 #if __has_feature(objc_arc)
290 NSWindow __unsafe_unretained *window; /**< The Cocoa window */
291 #else
292 NSWindow *window; /**< The Cocoa window */
293 #endif
294#else
295 NSWindow *window; /**< The Cocoa window */
296#endif
297 } cocoa;
298#endif
299#if defined(SDL_ENABLE_SYSWM_UIKIT)
300 struct
301 {
302#if defined(__OBJC__) && defined(__has_feature)
303 #if __has_feature(objc_arc)
304 UIWindow __unsafe_unretained *window; /**< The UIKit window */
305 #else
306 UIWindow *window; /**< The UIKit window */
307 #endif
308#else
309 UIWindow *window; /**< The UIKit window */
310#endif
311 GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
312 GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
313 GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
314 } uikit;
315#endif
316#if defined(SDL_ENABLE_SYSWM_WAYLAND)
317 struct
318 {
319 struct wl_display *display; /**< Wayland display */
320 struct wl_surface *surface; /**< Wayland surface */
321 struct wl_egl_window *egl_window; /**< Wayland EGL window (native window) */
322 struct xdg_surface *xdg_surface; /**< Wayland xdg surface (window manager handle) */
323 struct xdg_toplevel *xdg_toplevel; /**< Wayland xdg toplevel role */
324 struct xdg_popup *xdg_popup; /**< Wayland xdg popup role */
325 struct xdg_positioner *xdg_positioner; /**< Wayland xdg positioner, for popup */
326 } wl;
327#endif
328
329#if defined(SDL_ENABLE_SYSWM_ANDROID)
330 struct
331 {
332 ANativeWindow *window;
333 EGLSurface surface;
334 } android;
335#endif
336
337#if defined(SDL_ENABLE_SYSWM_VIVANTE)
338 struct
339 {
340 EGLNativeDisplayType display;
341 EGLNativeWindowType window;
342 } vivante;
343#endif
344
345#if defined(SDL_ENABLE_SYSWM_KMSDRM)
346 struct
347 {
348 int dev_index; /**< Device index (ex: the X in /dev/dri/cardX) */
349 int drm_fd; /**< DRM FD (unavailable on Vulkan windows) */
350 struct gbm_device *gbm_dev; /**< GBM device (unavailable on Vulkan windows) */
351 } kmsdrm;
352#endif
353
354 /* Make sure this union has enough room for 14 pointers */
355 void *dummy_ptrs[14];
358};
360
361typedef struct SDL_SysWMinfo SDL_SysWMinfo;
362
363
364/**
365 * Get driver-specific information about a window.
366 *
367 * You must include SDL_syswm.h for the declaration of SDL_SysWMinfo.
368 *
369 * \param window the window about which information is being requested
370 * \param info an SDL_SysWMinfo structure filled in with window information
371 * \param version the version of info being requested, should be
372 * SDL_SYSWM_CURRENT_VERSION
373 * \returns 0 on success or a negative error code on failure; call
374 * SDL_GetError() for more information.
375 *
376 * \since This function is available since SDL 3.0.0.
377 */
378extern DECLSPEC int SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info, Uint32 version);
379
380
381/* Ends C function definitions when using C++ */
382#ifdef __cplusplus
383}
384#endif
385#include <SDL3/SDL_close_code.h>
386
387#endif /* SDL_syswm_h_ */
Try to get a standard set of platform defines.
This is a general header that includes C language support.
uint64_t Uint64
Definition: SDL_stdinc.h:184
uint32_t Uint32
Definition: SDL_stdinc.h:171
SDL_SYSWM_TYPE
Definition: SDL_syswm.h:203
@ SDL_SYSWM_X11
Definition: SDL_syswm.h:215
@ SDL_SYSWM_RISCOS
Definition: SDL_syswm.h:209
@ SDL_SYSWM_UNKNOWN
Definition: SDL_syswm.h:204
@ SDL_SYSWM_HAIKU
Definition: SDL_syswm.h:207
@ SDL_SYSWM_KMSDRM
Definition: SDL_syswm.h:208
@ SDL_SYSWM_WINDOWS
Definition: SDL_syswm.h:213
@ SDL_SYSWM_UIKIT
Definition: SDL_syswm.h:210
@ SDL_SYSWM_COCOA
Definition: SDL_syswm.h:206
@ SDL_SYSWM_WAYLAND
Definition: SDL_syswm.h:212
@ SDL_SYSWM_VIVANTE
Definition: SDL_syswm.h:211
@ SDL_SYSWM_ANDROID
Definition: SDL_syswm.h:205
@ SDL_SYSWM_WINRT
Definition: SDL_syswm.h:214
#define SDL_SYSWM_CURRENT_INFO_SIZE
Definition: SDL_syswm.h:193
SDL_COMPILE_TIME_ASSERT(SDL_SysWMinfo_size, sizeof(struct SDL_SysWMinfo)==SDL_SYSWM_CURRENT_INFO_SIZE)
int SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info, Uint32 version)
Header file for SDL video functions.
struct SDL_Window SDL_Window
The type used to identify a window.
Definition: SDL_video.h:101
void * dummy_ptrs[14]
Definition: SDL_syswm.h:355
Uint32 padding[(2 *(sizeof(void *) >=8 ? sizeof(void *) :sizeof(Uint64)) - 2 *sizeof(Uint32))/sizeof(Uint32)]
Definition: SDL_syswm.h:259
Uint32 version
Definition: SDL_syswm.h:256
Uint64 dummy_ints[14]
Definition: SDL_syswm.h:356
Uint32 subsystem
Definition: SDL_syswm.h:257
union SDL_SysWMinfo::@7 info
union SDL_SysWMmsg::@6 msg
Uint32 padding[(2 *(sizeof(void *) >=8 ? sizeof(void *) :sizeof(Uint64)) - 2 *sizeof(Uint32))/sizeof(Uint32)]
Definition: SDL_syswm.h:226
Uint32 version
Definition: SDL_syswm.h:223
Uint32 subsystem
Definition: SDL_syswm.h:224