Solve version through Into instead of using sys::SDL_version

This commit is contained in:
Lewis Clement
2020-02-14 11:09:08 +01:00
parent 68a7ae90f4
commit c53bcc71a5
+19 -6
View File
@@ -7,10 +7,17 @@ unsafe impl HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> RawWindowHandle {
use self::SDL_SYSWM_TYPE::*;
let mut wm_info = SDL_SysWMinfo::default();
// Make certain to retrieve version before querying `SDL_GetWindowWMInfo`
// as that gives an error on certain systems
unsafe { sys::SDL_GetVersion(&mut wm_info.version) }
if unsafe { sys::SDL_GetWindowWMInfo(self.raw(), &mut wm_info) } == SDL_bool::SDL_FALSE {
#[cfg(not(target_os = "macos"))]
unsafe {
let mut version: sys::SDL_version = std::mem::zeroed();
sys::SDL_GetVersion(&mut version);
wm_info.version = version.into();
}
if unsafe { SDL_GetWindowWMInfo(self.raw(), &mut wm_info) } == SDL_bool::SDL_FALSE {
panic!("Couldn't get SDL window info: {}", crate::get_error());
}
match wm_info.subsystem {
@@ -87,10 +94,6 @@ extern "C" {
fn SDL_GetWindowWMInfo(window: *mut SDL_Window, info: *mut SDL_SysWMinfo) -> SDL_bool;
}
extern "C" {
pub fn SDL_GetVersion(version: *mut SDL_version);
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -109,6 +112,16 @@ pub struct SDL_version {
pub patch: u8,
}
impl Into<SDL_version> for sys::SDL_version {
fn into(self) -> SDL_version {
SDL_version {
major: self.major,
minor: self.minor,
patch: self.patch
}
}
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types, dead_code)]