Add small wrapper for RawWindowHandle
This commit is contained in:
parent
f3ba681877
commit
c7d9d7d107
|
@ -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,
|
||||
) {
|
||||
}
|
||||
|
|
18
src/lib.rs
18
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<A: AppWindow> Window<A> {
|
|||
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<A: AppWindow> Window<A> {
|
|||
|
||||
x11_window
|
||||
.app_window
|
||||
.create_context(raw_handle, &window_info);
|
||||
.create_context(raw_window, &window_info);
|
||||
|
||||
x11_window.run_event_loop();
|
||||
|
||||
|
|
Loading…
Reference in a new issue