diff --git a/examples/open_window.rs b/examples/open_window.rs index 745fec7..d40f66d 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -25,7 +25,7 @@ impl baseview::AppWindow for MyProgram { fn create_context( &mut self, - _window: raw_window_handle::RawWindowHandle, + _window: baseview::RawWindow, _window_info: &baseview::WindowInfo, ) { } diff --git a/src/lib.rs b/src/lib.rs index 5ed9f41..0fe21e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,12 +36,20 @@ pub struct WindowOpenOptions<'a> { pub trait AppWindow { type AppMessage; - fn create_context( - &mut self, - window: raw_window_handle::RawWindowHandle, - window_info: &WindowInfo, - ); + fn create_context(&mut self, window: RawWindow, window_info: &WindowInfo); fn draw(&mut self); fn on_event(&mut self, event: Event); fn on_app_message(&mut self, message: Self::AppMessage); } + +/// A wrapper for a `RawWindowHandle`. Some context creators expect an `&impl HasRawWindowHandle`. +#[derive(Debug, Copy, Clone)] +pub struct RawWindow { + pub raw_window_handle: raw_window_handle::RawWindowHandle, +} + +unsafe impl raw_window_handle::HasRawWindowHandle for RawWindow { + fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle { + self.raw_window_handle + } +} diff --git a/src/x11/window.rs b/src/x11/window.rs index d90a8a4..8975fda 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -6,7 +6,9 @@ use ::x11::xlib; // use xcb::dri2; // needed later use super::XcbConnection; -use crate::{AppWindow, Event, MouseButtonID, MouseScroll, Parent, WindowInfo, WindowOpenOptions}; +use crate::{ + AppWindow, Event, MouseButtonID, MouseScroll, Parent, RawWindow, WindowInfo, WindowOpenOptions, +}; use raw_window_handle::RawWindowHandle; @@ -130,6 +132,9 @@ impl Window { connection: xcb_connection.conn.get_raw_conn() as *mut c_void, ..raw_window_handle::unix::XcbHandle::empty() }); + let raw_window = RawWindow { + raw_window_handle: raw_handle, + }; let scaling = { let maybe_scaling = @@ -158,7 +163,7 @@ impl Window { x11_window .app_window - .create_context(raw_handle, &window_info); + .create_context(raw_window, &window_info); x11_window.run_event_loop();