Implement raw_window_handle::HasRawWindowHandle for Window type (#1105)

* Implement raw_window_handle::HasRawWindowHandle for Window type

* Format

* Address compilation issues

* Fix Linux build hopefully

* Fix iOS build
This commit is contained in:
Osspial 2019-08-14 07:57:16 -04:00 committed by GitHub
parent 1aab328e2a
commit 604016d69d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 0 deletions

View file

@ -3,6 +3,7 @@
use std::{collections::VecDeque, env, ffi::CStr, fmt, mem::MaybeUninit, os::raw::*, sync::Arc};
use parking_lot::Mutex;
use raw_window_handle::RawWindowHandle;
use smithay_client_toolkit::reexports::client::ConnectError;
pub use self::x11::XNotSupported;
@ -440,6 +441,13 @@ impl Window {
&Window::Wayland(ref window) => MonitorHandle::Wayland(window.primary_monitor()),
}
}
pub fn raw_window_handle(&self) -> RawWindowHandle {
match self {
&Window::X(ref window) => RawWindowHandle::X11(window.raw_window_handle()),
&Window::Wayland(ref window) => RawWindowHandle::Wayland(window.raw_window_handle()),
}
}
}
unsafe extern "C" fn x_error_callback(

View file

@ -1,3 +1,4 @@
use raw_window_handle::unix::WaylandHandle;
use std::{
collections::VecDeque,
sync::{Arc, Mutex, Weak},
@ -333,6 +334,14 @@ impl Window {
pub fn primary_monitor(&self) -> MonitorHandle {
primary_monitor(&self.outputs)
}
pub fn raw_window_handle(&self) -> WaylandHandle {
WaylandHandle {
surface: self.surface().as_ref().c_ptr() as *mut _,
display: self.display().as_ref().c_ptr() as *mut _,
..WaylandHandle::empty()
}
}
}
impl Drop for Window {

View file

@ -1,3 +1,4 @@
use raw_window_handle::unix::X11Handle;
use std::{
cmp,
collections::HashSet,
@ -1375,4 +1376,13 @@ impl UnownedWindow {
.unwrap()
.insert(WindowId(self.xwindow));
}
#[inline]
pub fn raw_window_handle(&self) -> X11Handle {
X11Handle {
window: self.xwindow,
display: self.xconn.display as _,
..X11Handle::empty()
}
}
}