Skip to content

Commit

Permalink
Merge pull request #1183 from nathanvoglsam/raw-window-handle-winrt
Browse files Browse the repository at this point in the history
Implement WinRT support in SDL2 raw-window-handle shim
  • Loading branch information
Cobrand committed Dec 21, 2021
2 parents 0e864ce + 9859558 commit cfdb435
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/sdl2/raw_window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ unsafe impl HasRawWindowHandle for Window {

RawWindowHandle::Win32(handle)
}
#[cfg(target_os = "windows")]
SDL_SYSWM_WINRT => {
use self::raw_window_handle::WinRtHandle;

let mut handle = WinRtHandle::empty();
handle.core_window = unsafe { wm_info.info.winrt }.core_window;

RawWindowHandle::WinRt(handle)
}
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
Expand Down Expand Up @@ -95,7 +104,6 @@ unsafe impl HasRawWindowHandle for Window {
let window_system = match x {
SDL_SYSWM_DIRECTFB => "DirectFB",
SDL_SYSWM_MIR => "Mir",
SDL_SYSWM_WINRT => "WinRT",
SDL_SYSWM_VIVANTE => "Vivante",
_ => unreachable!(),
};
Expand Down Expand Up @@ -175,30 +183,31 @@ pub mod windows {
#[repr(C)]
#[derive(Copy, Clone)]
pub union WindowsSysWMinfo {
pub win: Handles,
pub win: Win32Handles,
pub winrt: WinRtHandles,
pub dummy: [u8; 64usize],
_bindgen_union_align: [u64; 8usize],
}

impl Default for WindowsSysWMinfo {
fn default() -> Self {
WindowsSysWMinfo {
win: Handles::default(),
win: Win32Handles::default(),
}
}
}

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Handles {
pub struct Win32Handles {
pub window: *mut HWND,
pub hdc: *mut HDC,
pub hinstance: *mut HINSTANCE,
}

impl Default for Handles {
impl Default for Win32Handles {
fn default() -> Self {
Handles {
Win32Handles {
window: 0 as *mut HWND,
hdc: 0 as *mut HDC,
hinstance: 0 as *mut HINSTANCE,
Expand All @@ -223,6 +232,20 @@ pub mod windows {
pub struct HINSTANCE {
pub unused: libc::c_int,
}

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct WinRtHandles {
pub core_window: *mut core::ffi::c_void,
}

impl Default for WinRtHandles {
fn default() -> Self {
WinRtHandles {
core_window: core::ptr::null_mut(),
}
}
}
}

#[cfg(any(
Expand Down

0 comments on commit cfdb435

Please sign in to comment.