api: replace WindowId From/Into u64 with WindowId::{from,into}_raw()

Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
daxpedda 2024-09-27 22:12:50 +02:00 committed by GitHub
parent 380eea0072
commit 6e1b9fa24d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 62 additions and 93 deletions

View file

@ -342,17 +342,13 @@ impl WindowId {
pub const fn dummy() -> Self {
Self(0)
}
}
impl From<WindowId> for u64 {
fn from(window_id: WindowId) -> Self {
window_id.0 as u64
pub const fn into_raw(self) -> u64 {
self.0 as u64
}
}
impl From<u64> for WindowId {
fn from(raw_id: u64) -> Self {
Self(raw_id as usize)
pub const fn from_raw(id: u64) -> Self {
Self(id as usize)
}
}

View file

@ -3,10 +3,9 @@
use std::collections::VecDeque;
use objc2::rc::Retained;
use objc2::runtime::{AnyObject, NSObject};
use objc2::{class, declare_class, msg_send, msg_send_id, mutability, ClassType, DeclaredClass};
use objc2_foundation::{
CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker, NSObjectProtocol,
CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker, NSObject, NSObjectProtocol,
};
use objc2_ui_kit::{
UIApplication, UICoordinateSpace, UIResponder, UIScreen, UIScreenOverscanCompensation,
@ -106,7 +105,7 @@ impl WinitUIWindow {
}
pub(crate) fn id(&self) -> WindowId {
(self as *const Self as usize as u64).into()
WindowId::from_window(self)
}
}
@ -942,34 +941,23 @@ impl Inner {
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId {
window: *mut WinitUIWindow,
}
pub struct WindowId(usize);
impl WindowId {
pub const fn dummy() -> Self {
WindowId { window: std::ptr::null_mut() }
WindowId(0)
}
}
impl From<WindowId> for u64 {
fn from(window_id: WindowId) -> Self {
window_id.window as u64
pub const fn into_raw(self) -> u64 {
self.0 as _
}
}
impl From<u64> for WindowId {
fn from(raw_id: u64) -> Self {
Self { window: raw_id as _ }
pub const fn from_raw(id: u64) -> Self {
Self(id as _)
}
}
unsafe impl Send for WindowId {}
unsafe impl Sync for WindowId {}
impl From<&AnyObject> for WindowId {
fn from(window: &AnyObject) -> WindowId {
WindowId { window: window as *const _ as _ }
fn from_window(window: &UIWindow) -> Self {
Self(window as *const UIWindow as usize)
}
}