Implement From<u64> for WindowId and vise-versa
This should help downstream applications to expose WindowId to the end users via e.g. IPC to control particular windows in multi window systems.
This commit is contained in:
parent
c55d97183d
commit
cb41c58f21
14 changed files with 115 additions and 60 deletions
|
|
@ -59,7 +59,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
F: Fn(&Arc<UnownedWindow>) -> Ret,
|
||||
{
|
||||
let mut deleted = false;
|
||||
let window_id = WindowId(window_id);
|
||||
let window_id = WindowId(window_id as u64);
|
||||
let wt = get_xtarget(&self.target);
|
||||
let result = wt
|
||||
.windows
|
||||
|
|
@ -513,7 +513,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
|
||||
// In the event that the window's been destroyed without being dropped first, we
|
||||
// cleanup again here.
|
||||
wt.windows.borrow_mut().remove(&WindowId(window));
|
||||
wt.windows.borrow_mut().remove(&WindowId(window as u64));
|
||||
|
||||
// Since all XIM stuff needs to happen from the same thread, we destroy the input
|
||||
// context here instead of when dropping the window.
|
||||
|
|
@ -1213,11 +1213,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
&*window.shared_state.lock(),
|
||||
);
|
||||
|
||||
let window_id = crate::window::WindowId(
|
||||
crate::platform_impl::platform::WindowId::X(
|
||||
*window_id,
|
||||
),
|
||||
);
|
||||
let window_id = crate::window::WindowId(*window_id);
|
||||
let old_inner_size = PhysicalSize::new(width, height);
|
||||
let mut new_inner_size =
|
||||
PhysicalSize::new(new_width, new_height);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,10 @@ use crate::{
|
|||
event_loop::{
|
||||
ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW,
|
||||
},
|
||||
platform_impl::{platform::sticky_exit_callback, PlatformSpecificWindowBuilderAttributes},
|
||||
platform_impl::{
|
||||
platform::{sticky_exit_callback, WindowId},
|
||||
PlatformSpecificWindowBuilderAttributes,
|
||||
},
|
||||
window::WindowAttributes,
|
||||
};
|
||||
|
||||
|
|
@ -361,7 +364,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
}
|
||||
|
||||
for window_id in windows {
|
||||
let window_id = crate::window::WindowId(super::WindowId::X(window_id));
|
||||
let window_id = crate::window::WindowId(window_id);
|
||||
sticky_exit_callback(
|
||||
Event::RedrawRequested(window_id),
|
||||
&this.target,
|
||||
|
|
@ -505,10 +508,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
target,
|
||||
control_flow,
|
||||
&mut |event, window_target, control_flow| {
|
||||
if let Event::RedrawRequested(crate::window::WindowId(
|
||||
super::WindowId::X(wid),
|
||||
)) = event
|
||||
{
|
||||
if let Event::RedrawRequested(crate::window::WindowId(wid)) = event {
|
||||
wt.redraw_sender.sender.send(wid).unwrap();
|
||||
wt.redraw_sender.waker.wake().unwrap();
|
||||
} else {
|
||||
|
|
@ -609,15 +609,6 @@ impl<'a> Deref for DeviceInfo<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct WindowId(ffi::Window);
|
||||
|
||||
impl WindowId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
WindowId(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DeviceId(c_int);
|
||||
|
||||
|
|
@ -657,7 +648,7 @@ impl Drop for Window {
|
|||
let window = self.deref();
|
||||
let xconn = &window.xconn;
|
||||
unsafe {
|
||||
(xconn.xlib.XDestroyWindow)(xconn.display, window.id().0);
|
||||
(xconn.xlib.XDestroyWindow)(xconn.display, window.id().0 as ffi::Window);
|
||||
// If the window was somehow already destroyed, we'll get a `BadWindow` error, which we don't care about.
|
||||
let _ = xconn.check_errors();
|
||||
}
|
||||
|
|
@ -700,7 +691,7 @@ struct XExtension {
|
|||
}
|
||||
|
||||
fn mkwid(w: ffi::Window) -> crate::window::WindowId {
|
||||
crate::window::WindowId(crate::platform_impl::WindowId::X(WindowId(w)))
|
||||
crate::window::WindowId(crate::platform_impl::platform::WindowId(w as u64))
|
||||
}
|
||||
fn mkdid(w: c_int) -> crate::event::DeviceId {
|
||||
crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w)))
|
||||
|
|
|
|||
|
|
@ -1496,14 +1496,14 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn id(&self) -> WindowId {
|
||||
WindowId(self.xwindow)
|
||||
WindowId(self.xwindow as u64)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn request_redraw(&self) {
|
||||
self.redraw_sender
|
||||
.sender
|
||||
.send(WindowId(self.xwindow))
|
||||
.send(WindowId(self.xwindow as u64))
|
||||
.unwrap();
|
||||
self.redraw_sender.waker.wake().unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue