Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WinRT support in SDL2 raw-window-handle shim #1183

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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