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