diff --git a/src/sdl2/raw_window_handle.rs b/src/sdl2/raw_window_handle.rs index 6dccae7b..ec67bd19 100644 --- a/src/sdl2/raw_window_handle.rs +++ b/src/sdl2/raw_window_handle.rs @@ -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 => { @@ -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; @@ -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; @@ -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)] @@ -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)] @@ -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, @@ -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)]