Update to new raw-window-handle strategy
Signed-off-by: John Nunley <dev@notgull.net> Co-authored-by: TornaxO7 <tornax@proton.me>
This commit is contained in:
parent
bbeacc46d5
commit
e41fac825c
26 changed files with 662 additions and 242 deletions
|
|
@ -45,7 +45,6 @@ use std::{
|
|||
use libc::{self, setlocale, LC_CTYPE};
|
||||
|
||||
use atoms::*;
|
||||
use raw_window_handle::{RawDisplayHandle, XlibDisplayHandle};
|
||||
|
||||
use x11rb::x11_utils::X11Error as LogicalError;
|
||||
use x11rb::{
|
||||
|
|
@ -704,11 +703,27 @@ impl<T> EventLoopWindowTarget<T> {
|
|||
.expect_then_ignore_error("Failed to update device event filter");
|
||||
}
|
||||
|
||||
pub fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
|
||||
let mut display_handle = XlibDisplayHandle::empty();
|
||||
#[cfg(feature = "rwh_05")]
|
||||
pub fn raw_display_handle_rwh_05(&self) -> rwh_05::RawDisplayHandle {
|
||||
let mut display_handle = rwh_05::XlibDisplayHandle::empty();
|
||||
display_handle.display = self.xconn.display as *mut _;
|
||||
display_handle.screen = self.xconn.default_screen_index() as c_int;
|
||||
RawDisplayHandle::Xlib(display_handle)
|
||||
display_handle.into()
|
||||
}
|
||||
|
||||
#[cfg(feature = "rwh_06")]
|
||||
pub fn raw_display_handle_rwh_06(
|
||||
&self,
|
||||
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
|
||||
let display_handle = rwh_06::XlibDisplayHandle::new(
|
||||
// SAFETY: display will never be null
|
||||
Some(
|
||||
std::ptr::NonNull::new(self.xconn.display as *mut _)
|
||||
.expect("X11 display should never be null"),
|
||||
),
|
||||
self.xconn.default_screen_index() as c_int,
|
||||
);
|
||||
Ok(display_handle.into())
|
||||
}
|
||||
|
||||
pub(crate) fn set_control_flow(&self, control_flow: ControlFlow) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use std::{
|
|||
sync::{Arc, Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XlibDisplayHandle, XlibWindowHandle};
|
||||
use x11rb::{
|
||||
connection::Connection,
|
||||
properties::{WmHints, WmHintsState, WmSizeHints, WmSizeHintsSpecification},
|
||||
|
|
@ -117,9 +116,11 @@ unsafe impl Sync for UnownedWindow {}
|
|||
pub(crate) struct UnownedWindow {
|
||||
pub(crate) xconn: Arc<XConnection>, // never changes
|
||||
xwindow: xproto::Window, // never changes
|
||||
visual: u32, // never changes
|
||||
#[allow(dead_code)]
|
||||
visual: u32, // never changes
|
||||
root: xproto::Window, // never changes
|
||||
screen_id: i32, // never changes
|
||||
#[allow(dead_code)]
|
||||
screen_id: i32, // never changes
|
||||
cursor: Mutex<CursorIcon>,
|
||||
cursor_grabbed_mode: Mutex<CursorGrabMode>,
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
|
|
@ -148,12 +149,15 @@ impl UnownedWindow {
|
|||
) -> Result<UnownedWindow, RootOsError> {
|
||||
let xconn = &event_loop.xconn;
|
||||
let atoms = xconn.atoms();
|
||||
#[cfg(feature = "rwh_06")]
|
||||
let root = match window_attrs.parent_window {
|
||||
Some(RawWindowHandle::Xlib(handle)) => handle.window as xproto::Window,
|
||||
Some(RawWindowHandle::Xcb(handle)) => handle.window,
|
||||
Some(rwh_06::RawWindowHandle::Xlib(handle)) => handle.window as xproto::Window,
|
||||
Some(rwh_06::RawWindowHandle::Xcb(handle)) => handle.window.get(),
|
||||
Some(raw) => unreachable!("Invalid raw window handle {raw:?} on X11"),
|
||||
None => event_loop.root,
|
||||
};
|
||||
#[cfg(not(feature = "rwh_06"))]
|
||||
let root = event_loop.root;
|
||||
|
||||
let mut monitors = leap!(xconn.available_monitors());
|
||||
let guessed_monitor = if monitors.is_empty() {
|
||||
|
|
@ -1464,11 +1468,13 @@ impl UnownedWindow {
|
|||
WindowButtons::all()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn xlib_display(&self) -> *mut c_void {
|
||||
self.xconn.display as _
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn xlib_window(&self) -> c_ulong {
|
||||
self.xwindow as ffi::Window
|
||||
|
|
@ -1817,20 +1823,55 @@ impl UnownedWindow {
|
|||
// TODO timer
|
||||
}
|
||||
|
||||
#[cfg(feature = "rwh_04")]
|
||||
#[inline]
|
||||
pub fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
let mut window_handle = XlibWindowHandle::empty();
|
||||
pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle {
|
||||
let mut window_handle = rwh_04::XlibHandle::empty();
|
||||
window_handle.display = self.xlib_display();
|
||||
window_handle.window = self.xlib_window();
|
||||
window_handle.visual_id = self.visual as c_ulong;
|
||||
RawWindowHandle::Xlib(window_handle)
|
||||
rwh_04::RawWindowHandle::Xlib(window_handle)
|
||||
}
|
||||
|
||||
#[cfg(feature = "rwh_05")]
|
||||
#[inline]
|
||||
pub fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||
let mut display_handle = XlibDisplayHandle::empty();
|
||||
pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle {
|
||||
let mut window_handle = rwh_05::XlibWindowHandle::empty();
|
||||
window_handle.window = self.xlib_window();
|
||||
window_handle.visual_id = self.visual as c_ulong;
|
||||
window_handle.into()
|
||||
}
|
||||
|
||||
#[cfg(feature = "rwh_05")]
|
||||
#[inline]
|
||||
pub fn raw_display_handle_rwh_05(&self) -> rwh_05::RawDisplayHandle {
|
||||
let mut display_handle = rwh_05::XlibDisplayHandle::empty();
|
||||
display_handle.display = self.xlib_display();
|
||||
display_handle.screen = self.screen_id;
|
||||
RawDisplayHandle::Xlib(display_handle)
|
||||
display_handle.into()
|
||||
}
|
||||
|
||||
#[cfg(feature = "rwh_06")]
|
||||
#[inline]
|
||||
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
|
||||
let mut window_handle = rwh_06::XlibWindowHandle::new(self.xlib_window());
|
||||
window_handle.visual_id = self.visual as c_ulong;
|
||||
Ok(window_handle.into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "rwh_06")]
|
||||
#[inline]
|
||||
pub fn raw_display_handle_rwh_06(
|
||||
&self,
|
||||
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
|
||||
Ok(rwh_06::XlibDisplayHandle::new(
|
||||
Some(
|
||||
std::ptr::NonNull::new(self.xlib_display())
|
||||
.expect("display pointer should never be null"),
|
||||
),
|
||||
self.screen_id,
|
||||
)
|
||||
.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue