x11: raw-window-handle 0.6
This commit is contained in:
parent
4e6e9737f1
commit
e31a11f1c7
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(deprecated)]
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
|
@ -52,14 +53,14 @@ impl WindowHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
if let Some(raw_window_handle) = self.raw_window_handle {
|
if let Some(raw_window_handle) = self.raw_window_handle {
|
||||||
if self.is_open.load(Ordering::Relaxed) {
|
if self.is_open.load(Ordering::Relaxed) {
|
||||||
return raw_window_handle;
|
return Ok(raw_window_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RawWindowHandle::Xlib(XlibWindowHandle::empty())
|
Ok(RawWindowHandle::Xlib(XlibWindowHandle::new(0)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,9 +127,9 @@ impl<'a> Window<'a> {
|
||||||
B: Send + 'static,
|
B: Send + 'static,
|
||||||
{
|
{
|
||||||
// Convert parent into something that X understands
|
// Convert parent into something that X understands
|
||||||
let parent_id = match parent.raw_window_handle() {
|
let parent_id = match parent.raw_window_handle().unwrap() {
|
||||||
RawWindowHandle::Xlib(h) => h.window as u32,
|
RawWindowHandle::Xlib(h) => h.window as u32,
|
||||||
RawWindowHandle::Xcb(h) => h.window,
|
RawWindowHandle::Xcb(h) => h.window.into(),
|
||||||
h => panic!("unsupported parent handle type {:?}", h),
|
h => panic!("unsupported parent handle type {:?}", h),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -292,7 +293,7 @@ impl<'a> Window<'a> {
|
||||||
// the correct dpi scaling.
|
// the correct dpi scaling.
|
||||||
handler.on_event(&mut window, Event::Window(WindowEvent::Resized(window_info)));
|
handler.on_event(&mut window, Event::Window(WindowEvent::Resized(window_info)));
|
||||||
|
|
||||||
let _ = tx.send(Ok(SendableRwh(window.raw_window_handle())));
|
let _ = tx.send(Ok(SendableRwh(window.raw_window_handle().unwrap())));
|
||||||
|
|
||||||
EventLoop::new(inner, handler, parent_handle).run()?;
|
EventLoop::new(inner, handler, parent_handle).run()?;
|
||||||
|
|
||||||
|
@ -352,25 +353,22 @@ impl<'a> Window<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> Result<RawWindowHandle, raw_window_handle::HandleError> {
|
||||||
let mut handle = XlibWindowHandle::empty();
|
let mut handle = XlibWindowHandle::new(self.inner.window_id.into());
|
||||||
|
|
||||||
handle.window = self.inner.window_id.into();
|
|
||||||
handle.visual_id = self.inner.visual_id.into();
|
handle.visual_id = self.inner.visual_id.into();
|
||||||
|
|
||||||
RawWindowHandle::Xlib(handle)
|
Ok(RawWindowHandle::Xlib(handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
fn raw_display_handle(&self) -> Result<RawDisplayHandle, raw_window_handle::HandleError> {
|
||||||
let display = self.inner.xcb_connection.dpy;
|
let display = self.inner.xcb_connection.dpy;
|
||||||
let mut handle = XlibDisplayHandle::empty();
|
Ok(RawDisplayHandle::Xlib(XlibDisplayHandle::new(
|
||||||
|
std::ptr::NonNull::new(display as *mut c_void),
|
||||||
handle.display = display as *mut c_void;
|
unsafe { x11::xlib::XDefaultScreen(display) },
|
||||||
handle.screen = unsafe { x11::xlib::XDefaultScreen(display) };
|
)))
|
||||||
|
|
||||||
RawDisplayHandle::Xlib(handle)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue