1 /+
2 +            Copyright 2022 – 2024 Aya Partridge
3 +          Copyright 2018 - 2022 Michael D. Parker
4 + Distributed under the Boost Software License, Version 1.0.
5 +     (See accompanying file LICENSE_1_0.txt or copy at
6 +           http://www.boost.org/LICENSE_1_0.txt)
7 +/
8 module sdl.syswm;
9 
10 import bindbc.sdl.config;
11 import bindbc.sdl.codegen;
12 
13 import sdl.stdinc: SDL_bool;
14 import sdl.video;
15 
16 version(Windows){
17 	import core.sys.windows.windef: HWND, UINT, WPARAM, LPARAM, HDC, HINSTANCE;
18 }
19 
20 alias SDL_SYSWM_TYPE = int;
21 enum: SDL_SYSWM_TYPE{
22 	SDL_SYSWM_UNKNOWN     = 0,
23 	SDL_SYSWM_WINDOWS     = 1,
24 	SDL_SYSWM_X11         = 2,
25 	SDL_SYSWM_DIRECTFB    = 3,
26 	SDL_SYSWM_COCOA       = 4,
27 	SDL_SYSWM_UIKIT       = 5,
28 }
29 static if(sdlSupport >= SDLSupport.v2_0_2)
30 enum: SDL_SYSWM_TYPE{
31 	SDL_SYSWM_WAYLAND     = 6,
32 	SDL_SYSWM_MIR         = 7,
33 }
34 static if(sdlSupport >= SDLSupport.v2_0_3)
35 enum: SDL_SYSWM_TYPE{
36 	SDL_SYSWM_WINRT       = 8,
37 }
38 static if(sdlSupport >= SDLSupport.v2_0_4)
39 enum: SDL_SYSWM_TYPE{
40 	SDL_SYSWM_ANDROID     = 9,
41 }
42 static if(sdlSupport >= SDLSupport.v2_0_5)
43 enum: SDL_SYSWM_TYPE{
44 	SDL_SYSWM_VIVANTE     = 10,
45 }
46 static if(sdlSupport >= SDLSupport.v2_0_6)
47 enum: SDL_SYSWM_TYPE{
48 	SDL_SYSWM_OS2         = 11,
49 }
50 static if(sdlSupport >= SDLSupport.v2_0_12)
51 enum: SDL_SYSWM_TYPE{
52 	SDL_SYSWM_HAIKU       = 12,
53 }
54 static if(sdlSupport >= SDLSupport.v2_0_16)
55 enum: SDL_SYSWM_TYPE{
56 	SDL_SYSWM_KMSDRM      = 13,
57 }
58 static if(sdlSupport >= SDLSupport.v2_0_18)
59 enum: SDL_SYSWM_TYPE{
60 	SDL_SYSWM_RISCOS      = 14,
61 }
62 
63 struct SDL_SysWMmsg{
64 	SDL_version version_;
65 	SDL_SYSWM_TYPE subsystem;
66 	union _Msg{
67 		version(Windows){
68 			struct _Win{
69 				HWND hwnd;
70 				UINT msg;
71 				WPARAM wParam;
72 				LPARAM lParam;
73 			}
74 			_Win win;
75 		}
76 		version(linux){
77 			version(SDL_NoX11){}
78 			else:
79 			struct _X11{
80 				//XEvent event;
81 				int pad1;
82 				c_long[24] pad2;
83 			}
84 			_X11 x11;
85 		}
86 		version(DirectFB){
87 			struct _DFB{
88 				//DFBEvent event;
89 				int clazz; //DFBEventClass clazz;
90 				void* pad;
91 			}
92 			_DFB dfb;
93 		}
94 		version(OSX){
95 			struct _Cocoa{
96 				int dummy;
97 			}
98 			_Cocoa cocoa;
99 		}
100 		version(iOS){
101 			struct _UIKit{
102 				int dummy;
103 			}
104 			_UIKit uikit;
105 		}
106 		static if(sdlSupport >= SDLSupport.v2_0_5) version(Vivante){
107 			struct _Vivante{
108 				int dummy;
109 			}
110 			_Vivante vivante;
111 		}
112 		static if(sdlSupport >= SDLSupport.v2_0_14) version(OS2){
113 			struct _OS2{
114 				c_ulong fFrame; //BOOL fFrame;
115 				c_ulong hwnd; //HWND hwnd;
116 				c_ulong msg; //ULONG msg;
117 				void* mp1; //MPARAM mp1;
118 				void* mp2; //MPARAM mp2;
119 			}
120 			_OS2 os2;
121 		}
122 		int dummy;
123 	}
124 	_Msg msg;
125 }
126 
127 struct SDL_SysWMinfo{
128 	SDL_version version_;
129 	SDL_SYSWM_TYPE subsystem;
130 	
131 	union _Info{
132 		version(Windows){
133 			struct _Win{
134 				HWND window;
135 				static if(sdlSupport >= SDLSupport.v2_0_4):
136 				HDC hdc;
137 				static if(sdlSupport >= SDLSupport.v2_0_6):
138 				HINSTANCE hinstance;
139 			}
140 			_Win win;
141 		}
142 		version(WinRT){
143 			struct _WinRT{
144 				void* window;
145 			}
146 			_WinRT winrt;
147 		}
148 		version(linux){
149 			version(SDL_NoX11){}
150 			else:
151 			struct _X11{
152 				void* display;
153 				uint window;
154 			}
155 			_X11 x11;
156 		}
157 		version(DirectFB){
158 			struct _DFB{
159 				void* dfb;
160 				void* window;
161 				void* surface;
162 			}
163 			_DFB dfb;
164 		}
165 		version(OSX){
166 			struct _Cocoa{
167 				void* window;
168 			}
169 			_Cocoa cocoa;
170 		}
171 		version(iOS){
172 			struct _UIKit{
173 				void* window;
174 				static if(sdlSupport >= SDLSupport.v2_0_4){
175 					uint framebuffer;
176 					uint colorbuffer;
177 					alias colourbuffer = colorbuffer;
178 					uint resolveFramebuffer;
179 				}
180 			}
181 			_UIKit uikit;
182 		}
183 		static if(sdlSupport >= SDLSupport.v2_0_2) version(linux){
184 			struct _WL{
185 				void* display;
186 				void* surface;
187 				void* shell_surface;
188 				static if(sdlSupport >= SDLSupport.v2_0_16):
189 				void* egl_window;
190 				void* xdg_surface;
191 				static if(sdlSupport >= SDLSupport.v2_0_18):
192 				void* xdg_toplevel;
193 				static if(sdlSupport >= SDLSupport.v2_0_22):
194 				void* xdg_popup;
195 				void* xdg_positioner;
196 			}
197 			_WL wl;
198 		}
199 		static if(sdlSupport >= SDLSupport.v2_0_2) version(Mir){
200 			struct _Mir{
201 				void* connection;
202 				void* surface;
203 			}
204 			_Mir mir;
205 		}
206 		static if(sdlSupport >= SDLSupport.v2_0_4) version(Android){
207 			struct _Android{
208 				void* window;
209 				void* surface;
210 			}
211 			_Android android;
212 		}
213 		static if(sdlSupport >= SDLSupport.v2_0_14) version(OS2){
214 			struct _OS2{
215 				void* hwnd; //HWND hwnd;
216 				void* hwndFrame; //HWND hwndFrame;
217 			}
218 			_OS2 os2;
219 		}
220 		static if(sdlSupport >= SDLSupport.v2_0_5) version(Vivante){
221 			struct _Vivante{
222 				void* display;
223 				void* window;
224 			}
225 			_Vivante vivante;
226 		}
227 		static if(sdlSupport >= SDLSupport.v2_0_16) version(KMSDRM){
228 			struct _KMSDRM{
229 				int dev_index;
230 				int drm_fd;
231 				void* gbm_dev;
232 			}
233 			_KMSDRM kmsdrm;
234 		}
235 		static if(sdlSupport >= SDLSupport.v2_0_6) ubyte[64] dummy;
236 		else int dummy;
237 	}
238 	_Info info;
239 }
240 
241 mixin(joinFnBinds((){
242 	FnBind[] ret = [
243 		{q{SDL_bool}, q{SDL_GetWindowWMInfo}, q{SDL_Window* window, SDL_SysWMinfo* info}},
244 	];
245 	return ret;
246 }()));