1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//! SDL's custom system window manager hooks.
//!
//! This is mostly needed to make support for the
//! [`raw-window-handle`](https://docs.rs/raw-window-handle) crate possible.

use crate::{c_uint, c_ulong, c_void, stdinc::*, version::*, video::*};

/// These are the various supported windowing subsystems.
///
/// See `SDL_SYSWM_*` constants
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct SDL_SYSWM_TYPE(pub i32);

#[allow(missing_docs)]
pub const SDL_SYSWM_UNKNOWN: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(0);
#[allow(missing_docs)]
pub const SDL_SYSWM_WINDOWS: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(1);
#[allow(missing_docs)]
pub const SDL_SYSWM_X11: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(2);
#[allow(missing_docs)]
pub const SDL_SYSWM_DIRECTFB: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(3);
#[allow(missing_docs)]
pub const SDL_SYSWM_COCOA: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(4);
#[allow(missing_docs)]
pub const SDL_SYSWM_UIKIT: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(5);
#[allow(missing_docs)]
pub const SDL_SYSWM_WAYLAND: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(6);
#[allow(missing_docs)]
pub const SDL_SYSWM_MIR: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(7);
#[allow(missing_docs)]
pub const SDL_SYSWM_WINRT: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(8);
#[allow(missing_docs)]
pub const SDL_SYSWM_ANDROID: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(9);
#[allow(missing_docs)]
pub const SDL_SYSWM_VIVANTE: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(10);
#[allow(missing_docs)]
pub const SDL_SYSWM_OS2: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(11);
#[allow(missing_docs)]
pub const SDL_SYSWM_HAIKU: SDL_SYSWM_TYPE = SDL_SYSWM_TYPE(12);

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_windows {
  /// The window handle (`HWND`)
  pub window: *mut c_void,
  /// The window device context (`HDC`)
  pub hdc: *mut c_void,
  /// The instance handle (`HINSTANCE`)
  pub hinstance: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_winrt {
  /// The WinRT CoreWindow (`IInspectable*`)
  pub window: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_x11 {
  /// The X11 display (`Display*`)
  pub display: *mut c_void,
  /// The X11 window (`Window`)
  pub window: c_ulong,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_directfb {
  /// The directfb main interface (`IDirectFB*`)
  pub dfb: *mut c_void,
  /// The directfb window handle (`IDirectFBWindow*`)
  pub window: *mut c_void,
  /// The directfb client surface (`IDirectFBSurface*`)
  pub surface: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_cocoa {
  /// The Cocoa window (`NSWindow*`)
  pub window: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_uikit {
  /// The UIKit window (`UIWindow*`)
  pub window: *mut c_void,
  /// The GL view's Framebuffer Object. It must be bound when rendering to the
  /// screen using GL. (`GLuint`)
  pub framebuffer: c_uint,
  /// The GL view's color Renderbuffer Object. It must be bound when
  /// SDL_GL_SwapWindow is called.
  pub colorbuffer: c_uint,
  /// The Framebuffer Object which holds the resolve color Renderbuffer, when
  /// MSAA is used.
  pub resolveFramebuffer: c_uint,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_wayland {
  /// Wayland display (`wl_display*`)
  pub display: *mut c_void,
  /// Wayland surface (`wl_surface*`)
  pub surface: *mut c_void,
  /// Wayland shell_surface (window manager handle) (`wl_shell_surface*`)
  pub shell_surface: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_android {
  /// Android native window (`ANativeWindow*`)
  pub window: *mut c_void,
  /// Embedded GL surface (`EGLSurface`)
  pub surface: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo_vivante {
  /// (`EGLNativeDisplayType`)
  pub display: *mut c_void,
  /// (`EGLNativeWindowType`)
  pub window: *mut c_void,
}

#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub union SDL_SysWMinfo_union {
  pub win: SDL_SysWMinfo_windows,
  pub winrt: SDL_SysWMinfo_winrt,
  pub x11: SDL_SysWMinfo_x11,
  pub dfb: SDL_SysWMinfo_directfb,
  pub cocoa: SDL_SysWMinfo_cocoa,
  pub uikit: SDL_SysWMinfo_uikit,
  pub wl: SDL_SysWMinfo_wayland,
  /* MIR entry skipped because it's no longer available */
  pub android: SDL_SysWMinfo_android,
  pub vivante: SDL_SysWMinfo_vivante,
  /* os2 support skipped, file an issue if you care. */
  /// Dummy field to ensure that the union is always at least 64 bytes.
  pub dummy: [u8; 64],
}

/// The custom window manager information structure.
///
/// When this structure is returned, it holds information about which low level
/// system it is using, and will be one of SDL_SYSWM_TYPE.
#[derive(Clone, Copy)]
#[repr(C)]
#[allow(missing_docs)]
pub struct SDL_SysWMinfo {
  pub version: SDL_version,
  pub subsystem: SDL_SYSWM_TYPE,
  pub info: SDL_SysWMinfo_union,
}
impl Default for SDL_SysWMinfo {
  #[inline]
  #[must_use]
  fn default() -> Self {
    unsafe { core::mem::zeroed() }
  }
}

extern "C" {
  /// This function allows access to driver-dependent window information.
  ///
  /// * `window` The window about which information is being requested
  /// * `info` This structure must be initialized with the SDL version, and is
  ///   then filled in with information about the given window.
  ///
  /// **Returns:** `SDL_TRUE` if the function is implemented and the version
  /// member of the `info` struct is valid, `SDL_FALSE` otherwise.
  ///
  /// You typically use this function like this:
  /// ```no_run
  /// # use fermium::prelude::*;
  /// let window = unimplemented!("make the window");
  /// let mut info = SDL_SysWMinfo::default();
  /// SDL_VERSION(&mut info.version);
  /// if SDL_TRUE == unsafe { SDL_GetWindowWMInfo(window, &mut info) } {
  ///   unimplemented!("now you have your info");
  /// }
  /// ```
  pub fn SDL_GetWindowWMInfo(
    window: *mut SDL_Window, info: *mut SDL_SysWMinfo,
  ) -> SDL_bool;
}