Skip to content

Commit

Permalink
Merge pull request Rust-SDL2#972 from lewisclement/fix-raw-window-han…
Browse files Browse the repository at this point in the history
…dle-version

Fix version detection by calling GetVersion before GetWindowWMInfo
  • Loading branch information
Cobrand authored Feb 20, 2020
2 parents 1e9e083 + df9a5c4 commit f186a05
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/sdl2/raw_window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ use crate::{sys::SDL_Window, video::Window};
unsafe impl HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> RawWindowHandle {
use self::SDL_SYSWM_TYPE::*;
let mut wm_info = SDL_SysWMinfo::default();
if unsafe { SDL_GetWindowWMInfo(self.raw(), &mut wm_info) } == SDL_bool::SDL_FALSE {
panic!("Couldn't get SDL window info: {}", crate::get_error());

let mut wm_info: SDL_SysWMinfo = unsafe { std::mem::zeroed() };

// 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 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 {
#[cfg(target_os = "windows")]
SDL_SYSWM_WINDOWS => {
Expand All @@ -20,11 +28,11 @@ unsafe impl HasRawWindowHandle for Window {
})
},
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
SDL_SYSWM_WAYLAND => {
use self::raw_window_handle::unix::WaylandHandle;
Expand All @@ -35,11 +43,11 @@ unsafe impl HasRawWindowHandle for Window {
})
},
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
SDL_SYSWM_X11 => {
use self::raw_window_handle::unix::XlibHandle;
Expand Down Expand Up @@ -84,6 +92,7 @@ extern "C" {
fn SDL_GetWindowWMInfo(window: *mut SDL_Window, info: *mut SDL_SysWMinfo) -> SDL_bool;
}


#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types, dead_code)]
Expand All @@ -92,15 +101,6 @@ pub enum SDL_bool {
SDL_TRUE = 1,
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
#[allow(non_camel_case_types, dead_code)]
pub struct SDL_version {
pub major: u8,
pub minor: u8,
pub patch: u8,
}

#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types, dead_code)]
Expand All @@ -126,21 +126,21 @@ impl Default for SDL_SYSWM_TYPE {
}

#[repr(C)]
#[derive(Default, Copy, Clone)]
#[derive(Copy, Clone)]
#[allow(non_camel_case_types)]
pub struct SDL_SysWMinfo {
pub version: SDL_version,
pub version: sys::SDL_version,
pub subsystem: SDL_SYSWM_TYPE,

#[cfg(target_os = "windows")]
pub info: windows::WindowsSysWMinfo,

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
pub info: linux::LinuxSysWMinfo,

Expand Down Expand Up @@ -204,11 +204,11 @@ pub mod windows {
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
pub mod linux {
#[repr(C)]
Expand Down

0 comments on commit f186a05

Please sign in to comment.