1 
2 //          Copyright Michael D. Parker 2018.
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.sdl.bind.sdlsyswm;
8 
9 //import core.stdc.config : c_long;
10 alias int c_long;
11 import bindbc.sdl.config;
12 import bindbc.sdl.bind.sdlstdinc : SDL_bool;
13 import bindbc.sdl.bind.sdlversion : SDL_version;
14 import bindbc.sdl.bind.sdlvideo : SDL_Window;
15 
16 static if(sdlSupport >= SDLSupport.sdl205) {
17     enum SDL_SYSWM_TYPE {
18         SDL_SYSWM_UNKNOWN,
19         SDL_SYSWM_WINDOWS,
20         SDL_SYSWM_X11,
21         SDL_SYSWM_DIRECTFB,
22         SDL_SYSWM_COCOA,
23         SDL_SYSWM_UIKIT,
24         SDL_SYSWM_WAYLAND,
25         SDL_SYSWM_MIR,
26         SDL_SYSWM_WINRT,
27         SDL_SYSWM_ANDROID,
28         SDL_SYSWM_VIVANTE,
29         SDL_SYSWM_OS2,
30     }
31 }
32 else static if(sdlSupport >= SDLSupport.sdl205) {
33     enum SDL_SYSWM_TYPE {
34         SDL_SYSWM_UNKNOWN,
35         SDL_SYSWM_WINDOWS,
36         SDL_SYSWM_X11,
37         SDL_SYSWM_DIRECTFB,
38         SDL_SYSWM_COCOA,
39         SDL_SYSWM_UIKIT,
40         SDL_SYSWM_WAYLAND,
41         SDL_SYSWM_MIR,
42         SDL_SYSWM_WINRT,
43         SDL_SYSWM_ANDROID,
44         SDL_SYSWM_VIVANTE,
45     }
46 }
47 else static if(sdlSupport >= SDLSupport.sdl204) {
48     enum SDL_SYSWM_TYPE {
49         SDL_SYSWM_UNKNOWN,
50         SDL_SYSWM_WINDOWS,
51         SDL_SYSWM_X11,
52         SDL_SYSWM_DIRECTFB,
53         SDL_SYSWM_COCOA,
54         SDL_SYSWM_UIKIT,
55         SDL_SYSWM_WAYLAND,
56         SDL_SYSWM_MIR,
57         SDL_SYSWM_WINRT,
58         SDL_SYSWM_ANDROID,
59     }
60 }
61 else static if(sdlSupport >= SDLSupport.sdl203) {
62     enum SDL_SYSWM_TYPE {
63         SDL_SYSWM_UNKNOWN,
64         SDL_SYSWM_WINDOWS,
65         SDL_SYSWM_X11,
66         SDL_SYSWM_DIRECTFB,
67         SDL_SYSWM_COCOA,
68         SDL_SYSWM_UIKIT,
69         SDL_SYSWM_WAYLAND,
70         SDL_SYSWM_MIR,
71         SDL_SYSWM_WINRT,
72     }
73 }
74 else static if(sdlSupport >= SDLSupport.sdl202) {
75     enum SDL_SYSWM_TYPE {
76         SDL_SYSWM_UNKNOWN,
77         SDL_SYSWM_WINDOWS,
78         SDL_SYSWM_X11,
79         SDL_SYSWM_DIRECTFB,
80         SDL_SYSWM_COCOA,
81         SDL_SYSWM_UIKIT,
82         SDL_SYSWM_WAYLAND,
83         SDL_SYSWM_MIR,
84     }
85 }
86 else {
87     enum SDL_SYSWM_TYPE {
88         SDL_SYSWM_UNKNOWN,
89         SDL_SYSWM_WINDOWS,
90         SDL_SYSWM_X11,
91         SDL_SYSWM_DIRECTFB,
92         SDL_SYSWM_COCOA,
93         SDL_SYSWM_UIKIT,
94     }
95 }
96 mixin(expandEnum!SDL_SYSWM_TYPE);
97 
98 version(Windows) {
99     // I don't want to import core.sys.windows.windows just for these
100     version(Win64) {
101         alias wparam = ulong;
102         alias lparam = long;
103     }else {
104         alias wparam = uint;
105         alias lparam = int;
106     }
107 }
108 
109 struct SDL_SysWMmsg {
110     SDL_version version_;
111     SDL_SYSWM_TYPE subsystem;
112     union msg_ {
113         version(Windows) {
114             struct win_ {
115                 void* hwnd;
116                 uint msg;
117                 wparam wParam;
118                 lparam lParam;
119             }
120             win_ win;
121         }
122         else version(OSX) {
123             struct cocoa_ {
124                 int dummy;
125             }
126             cocoa_ cocoa;
127         }
128         else version(linux) {
129             struct dfb_ {
130                 void* event;
131             }
132             dfb_ dfb;
133         }
134 
135         version(Posix) {
136             struct x11_ {
137                 c_long[24] pad; // sufficient size for any X11 event
138             }
139             x11_ x11;
140         }
141 
142         static if(sdlSupport >= SDLSupport.sdl205) {
143             struct vivante_ {
144                 int dummy;
145             }
146             vivante_ vivante;
147         }
148 
149         int dummy;
150     }
151     msg_ msg;
152 }
153 
154 struct SDL_SysWMinfo {
155     SDL_version version_;
156     SDL_SYSWM_TYPE subsystem;
157 
158     union info_ {
159         version(Windows) {
160             struct win_ {
161                void* window;
162                static if(sdlSupport >= SDLSupport.sdl204) void* hdc;
163                static if(sdlSupport >= SDLSupport.sdl206) void* hinstance;
164             }
165             win_ win;
166         }
167         else version(OSX) {
168             struct cocoa_ {
169                void* window;
170             }
171             cocoa_ cocoa;
172 
173             struct uikit_ {
174                 void *window;
175             }
176             uikit_ uikit;
177 
178         }
179         else version(linux) {
180             struct dfb_ {
181                 void *dfb;
182                 void *window;
183                 void *surface;
184             }
185             dfb_ dfb;
186 
187             static if(sdlSupport >= SDLSupport.sdl202) {
188                 struct wl_ {
189                     void *display;
190                     void *surface;
191                     void *shell_surface;
192                 }
193                 wl_ wl;
194 
195                 struct mir_ {
196                     void *connection;
197                     void *surface;
198                 }
199                 mir_ mir;
200             }
201         }
202 
203         version(Posix) {
204             struct x11_ {
205                 void* display;
206                 uint window;
207             }
208             x11_ x11;
209         }
210 
211         static if(sdlSupport >= SDLSupport.sdl204) {
212             version(Android) {
213                 struct android_ {
214                     void* window;
215                     void* surface;
216                 }
217                 android_ android;
218             }
219         }
220 
221         static if(sdlSupport >= SDLSupport.sdl206) ubyte[64] dummy;
222         else int dummy;
223     }
224     info_ info;
225 }
226 
227 version(BindSDL_Static) {
228     extern(C) @nogc nothrow {
229         SDL_bool SDL_GetWindowWMInfo(SDL_Window*,SDL_SysWMinfo*);
230     }
231 }
232 else {
233     extern(C) @nogc nothrow {
234         alias pSDL_GetWindowWMInfo = SDL_bool function(SDL_Window*,SDL_SysWMinfo*);
235     }
236 
237     __gshared {
238         pSDL_GetWindowWMInfo SDL_GetWindowWMInfo;
239     }
240 }