chore: remove platform WindowId's

WindowId is a window _identifier_, and as such doesn't store anything
(unlike a _handle_). So we can safely make only be defined once, in the
core crate.

There are a few backends where we still use `into_raw` internally; I
consider these patterns discouraged, we should not be passing around
important state in the window id.
This commit is contained in:
Mads Marquart 2024-10-08 15:29:40 +02:00 committed by GitHub
parent eccd9e415d
commit da2268ae22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 226 additions and 379 deletions

View file

@ -14,7 +14,7 @@ use crate::icon::Icon;
use crate::monitor::MonitorHandle as RootMonitorHandle;
use crate::window::{
Cursor, CursorGrabMode, Fullscreen as RootFullscreen, ImePurpose, ResizeDirection, Theme,
UserAttentionType, Window as RootWindow, WindowAttributes, WindowButtons, WindowId as RootWI,
UserAttentionType, Window as RootWindow, WindowAttributes, WindowButtons, WindowId,
WindowLevel,
};
@ -53,7 +53,7 @@ impl Window {
target.register(&canvas, id);
let runner = target.runner.clone();
let destroy_fn = Box::new(move || runner.notify_destroy_window(RootWI(id)));
let destroy_fn = Box::new(move || runner.notify_destroy_window(id));
let inner = Inner {
id,
@ -65,7 +65,7 @@ impl Window {
let canvas = Rc::downgrade(&inner.canvas);
let (dispatcher, runner) = Dispatcher::new(target.runner.main_thread(), inner);
target.runner.add_canvas(RootWI(id), canvas, runner);
target.runner.add_canvas(id, canvas, runner);
Ok(Window { inner: dispatcher })
}
@ -91,8 +91,8 @@ impl Window {
}
impl RootWindow for Window {
fn id(&self) -> RootWI {
RootWI(self.inner.queue(|inner| inner.id))
fn id(&self) -> WindowId {
self.inner.queue(|inner| inner.id)
}
fn scale_factor(&self) -> f64 {
@ -429,19 +429,6 @@ impl Drop for Inner {
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(pub(crate) u64);
impl WindowId {
pub const fn into_raw(self) -> u64 {
self.0
}
pub const fn from_raw(id: u64) -> Self {
Self(id)
}
}
#[derive(Clone, Debug)]
pub struct PlatformSpecificWindowAttributes {
pub(crate) canvas: Option<Arc<MainThreadSafe<backend::RawCanvasType>>>,