From 1dbfdcaa4820a7d6f9a5451b24ffff7f42156810 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Tue, 3 Sep 2024 23:03:03 +0200 Subject: [PATCH] use raw-window-handle straight --- Cargo.toml | 4 +-- rio-window/Cargo.toml | 7 ++-- rio-window/src/event_loop.rs | 34 ++++++++++++------- rio-window/src/lib.rs | 6 +--- rio-window/src/platform/x11.rs | 3 -- .../src/platform_impl/ios/event_loop.rs | 12 +++---- rio-window/src/platform_impl/ios/window.rs | 19 +++++------ rio-window/src/platform_impl/linux/mod.rs | 16 ++++----- .../linux/wayland/event_loop/mod.rs | 5 ++- .../src/platform_impl/linux/wayland/mod.rs | 2 -- .../platform_impl/linux/wayland/window/mod.rs | 10 +++--- .../linux/x11/event_processor.rs | 2 +- .../platform_impl/linux/x11/ime/context.rs | 5 ++- rio-window/src/platform_impl/linux/x11/mod.rs | 7 ++-- .../src/platform_impl/linux/x11/window.rs | 16 ++++----- .../src/platform_impl/macos/event_loop.rs | 12 +++---- rio-window/src/platform_impl/macos/window.rs | 12 +++---- .../platform_impl/macos/window_delegate.rs | 10 +++--- .../src/platform_impl/orbital/event_loop.rs | 12 +++---- .../src/platform_impl/orbital/window.rs | 14 ++++---- .../web/event_loop/window_target.rs | 12 +++---- .../src/platform_impl/web/web_sys/canvas.rs | 3 -- rio-window/src/platform_impl/web/window.rs | 16 ++++----- .../src/platform_impl/windows/event_loop.rs | 12 +++---- .../src/platform_impl/windows/window.rs | 22 +++++------- rio-window/src/window.rs | 34 ++++++++----------- 26 files changed, 131 insertions(+), 176 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04058756..c397d1e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,10 +34,10 @@ rio-proc-macros = { path = "rio-proc-macros", version = "0.1.11" } copa = { path = "copa", default-features = true, version = "0.1.11" } teletypewriter = { path = "teletypewriter", version = "0.1.11" } rio-backend = { path = "rio-backend", version = "0.1.11" } -rio-window = { path = "rio-window", version = "0.1.11", default-features = false, features = ["rwh_06"] } +rio-window = { path = "rio-window", version = "0.1.11", default-features = false } wa = { path = "wa", version = "0.1.7" } -raw-window-handle = "0.6.2" +raw-window-handle = { version = "0.6.2", features = ["std"] } parking_lot = { version = "0.12.3", features = ["nightly", "hardware-lock-elision"] } rustc-hash = "2.0.0" unicode-width = "0.1.13" diff --git a/rio-window/Cargo.toml b/rio-window/Cargo.toml index 3b2ae933..4c55d3a6 100644 --- a/rio-window/Cargo.toml +++ b/rio-window/Cargo.toml @@ -12,9 +12,8 @@ keywords.workspace = true # Features are documented in either `lib.rs` or under `winit::platform`. [features] -default = ["rwh_06", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] +default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] x11 = ["x11-dl", "bytemuck", "percent-encoding", "xkbcommon-dl/x11", "x11rb"] -rwh_06 = ["dep:rwh_06"] wayland = [ "wayland-client", "wayland-backend", @@ -36,7 +35,7 @@ cfg_aliases = "0.2.0" bitflags = { workspace = true } cursor-icon = "1.1.0" dpi = { version = "0.1.1" } -rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"], optional = true } +raw-window-handle = { workspace = true } smol_str = { workspace = true } tracing = { version = "0.1.40", default-features = false } @@ -286,8 +285,6 @@ tracing-web = "0.1" [[example]] doc-scrape-examples = true name = "window" -required-features = ["rwh_06"] [[example]] name = "child_window" -required-features = ["rwh_06"] \ No newline at end of file diff --git a/rio-window/src/event_loop.rs b/rio-window/src/event_loop.rs index cad3c46c..a281abfd 100644 --- a/rio-window/src/event_loop.rs +++ b/rio-window/src/event_loop.rs @@ -350,10 +350,14 @@ impl EventLoop { } } -#[cfg(feature = "rwh_06")] -impl rwh_06::HasDisplayHandle for EventLoop { - fn display_handle(&self) -> Result, rwh_06::HandleError> { - rwh_06::HasDisplayHandle::display_handle(self.event_loop.window_target()) +impl raw_window_handle::HasDisplayHandle for EventLoop { + fn display_handle( + &self, + ) -> Result, raw_window_handle::HandleError> + { + raw_window_handle::HasDisplayHandle::display_handle( + self.event_loop.window_target(), + ) } } @@ -507,12 +511,14 @@ impl ActiveEventLoop { } } -#[cfg(feature = "rwh_06")] -impl rwh_06::HasDisplayHandle for ActiveEventLoop { - fn display_handle(&self) -> Result, rwh_06::HandleError> { +impl raw_window_handle::HasDisplayHandle for ActiveEventLoop { + fn display_handle( + &self, + ) -> Result, raw_window_handle::HandleError> + { let raw = self.p.raw_display_handle_rwh_06()?; // SAFETY: The display will never be deallocated while the event loop is alive. - Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw) }) + Ok(unsafe { raw_window_handle::DisplayHandle::borrow_raw(raw) }) } } @@ -530,7 +536,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop { /// - A reference-counted pointer to the underlying type. #[derive(Clone)] pub struct OwnedDisplayHandle { - #[cfg_attr(not(feature = "rwh_06"), allow(dead_code))] + #[allow(dead_code)] platform: platform_impl::OwnedDisplayHandle, } @@ -541,14 +547,16 @@ impl fmt::Debug for OwnedDisplayHandle { } } -#[cfg(feature = "rwh_06")] -impl rwh_06::HasDisplayHandle for OwnedDisplayHandle { +impl raw_window_handle::HasDisplayHandle for OwnedDisplayHandle { #[inline] - fn display_handle(&self) -> Result, rwh_06::HandleError> { + fn display_handle( + &self, + ) -> Result, raw_window_handle::HandleError> + { let raw = self.platform.raw_display_handle_rwh_06()?; // SAFETY: The underlying display handle should be safe. - let handle = unsafe { rwh_06::DisplayHandle::borrow_raw(raw) }; + let handle = unsafe { raw_window_handle::DisplayHandle::borrow_raw(raw) }; Ok(handle) } diff --git a/rio-window/src/lib.rs b/rio-window/src/lib.rs index c6cb9936..95432cb9 100644 --- a/rio-window/src/lib.rs +++ b/rio-window/src/lib.rs @@ -141,9 +141,6 @@ //! //! * `x11` (enabled by default): On Unix platforms, enables the X11 backend. //! * `wayland` (enabled by default): On Unix platforms, enables the Wayland backend. -//! * `rwh_06`: Implement `raw-window-handle v0.6` traits. -//! * `serde`: Enables serialization/deserialization of certain types with [Serde](https://crates.io/crates/serde). -//! * `mint`: Enables mint (math interoperability standard types) conversions. //! //! See the [`platform`] module for documentation on platform-specific cargo //! features. @@ -170,8 +167,7 @@ #![deny(unsafe_op_in_unsafe_fn)] #![allow(clippy::missing_safety_doc)] -#[cfg(feature = "rwh_06")] -pub use rwh_06 as raw_window_handle; +pub use raw_window_handle; // Re-export DPI types so that users don't have to put it in Cargo.toml. #[doc(inline)] diff --git a/rio-window/src/platform/x11.rs b/rio-window/src/platform/x11.rs index 97c26959..8017d4a3 100644 --- a/rio-window/src/platform/x11.rs +++ b/rio-window/src/platform/x11.rs @@ -1,6 +1,4 @@ //! # X11 -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use crate::event_loop::{ActiveEventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; @@ -11,7 +9,6 @@ use crate::dpi::Size; /// X window type. Maps directly to /// [`_NET_WM_WINDOW_TYPE`](https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html). #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum WindowType { /// A desktop feature. This can include a single window containing desktop icons with the same /// dimensions as the screen, allowing the desktop environment to have full control of the diff --git a/rio-window/src/platform_impl/ios/event_loop.rs b/rio-window/src/platform_impl/ios/event_loop.rs index 91284ff8..4656d3c6 100644 --- a/rio-window/src/platform_impl/ios/event_loop.rs +++ b/rio-window/src/platform_impl/ios/event_loop.rs @@ -59,13 +59,12 @@ impl ActiveEventLoop { #[inline] pub fn listen_device_events(&self, _allowed: DeviceEvents) {} - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::UiKit( - rwh_06::UiKitDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::UiKit( + raw_window_handle::UiKitDisplayHandle::new(), )) } @@ -96,12 +95,11 @@ impl ActiveEventLoop { pub(crate) struct OwnedDisplayHandle; impl OwnedDisplayHandle { - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::UiKitDisplayHandle::new().into()) + ) -> Result { + Ok(raw_window_handle::UiKitDisplayHandle::new().into()) } } diff --git a/rio-window/src/platform_impl/ios/window.rs b/rio-window/src/platform_impl/ios/window.rs index 8f0e7347..184d2273 100644 --- a/rio-window/src/platform_impl/ios/window.rs +++ b/rio-window/src/platform_impl/ios/window.rs @@ -422,15 +422,14 @@ impl Inner { self.window.id() } - #[cfg(feature = "rwh_06")] - pub fn raw_window_handle_rwh_06(&self) -> rwh_06::RawWindowHandle { - let mut window_handle = rwh_06::UiKitWindowHandle::new({ + pub fn raw_window_handle_rwh_06(&self) -> raw_window_handle::RawWindowHandle { + let mut window_handle = raw_window_handle::UiKitWindowHandle::new({ let ui_view = Retained::as_ptr(&self.view) as _; std::ptr::NonNull::new(ui_view).expect("Retained should never be null") }); window_handle.ui_view_controller = std::ptr::NonNull::new(Retained::as_ptr(&self.view_controller) as _); - rwh_06::RawWindowHandle::UiKit(window_handle) + raw_window_handle::RawWindowHandle::UiKit(window_handle) } pub fn theme(&self) -> Option { @@ -572,25 +571,23 @@ impl Window { self.inner.get_on_main(|inner| f(inner)) } - #[cfg(feature = "rwh_06")] #[inline] pub(crate) fn raw_window_handle_rwh_06( &self, - ) -> Result { + ) -> Result { if let Some(mtm) = MainThreadMarker::new() { Ok(self.inner.get(mtm).raw_window_handle_rwh_06()) } else { - Err(rwh_06::HandleError::Unavailable) + Err(raw_window_handle::HandleError::Unavailable) } } - #[cfg(feature = "rwh_06")] #[inline] pub(crate) fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::UiKit( - rwh_06::UiKitDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::UiKit( + raw_window_handle::UiKitDisplayHandle::new(), )) } } diff --git a/rio-window/src/platform_impl/linux/mod.rs b/rio-window/src/platform_impl/linux/mod.rs index d2c41c7f..a1dc34f4 100644 --- a/rio-window/src/platform_impl/linux/mod.rs +++ b/rio-window/src/platform_impl/linux/mod.rs @@ -595,19 +595,17 @@ impl Window { ) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06( &self, - ) -> Result { + ) -> Result { x11_or_wayland!(match self; Window(window) => window.raw_window_handle_rwh_06()) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { + ) -> Result { x11_or_wayland!(match self; Window(window) => window.raw_display_handle_rwh_06()) } @@ -902,11 +900,10 @@ impl ActiveEventLoop { x11_or_wayland!(match self; Self(evlp) => evlp.listen_device_events(allowed)) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { + ) -> Result { x11_or_wayland!(match self; Self(evlp) => evlp.raw_display_handle_rwh_06()) } @@ -960,16 +957,15 @@ pub(crate) enum OwnedDisplayHandle { } impl OwnedDisplayHandle { - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { + ) -> Result { use std::ptr::NonNull; match self { #[cfg(x11_platform)] - Self::X(xconn) => Ok(rwh_06::XlibDisplayHandle::new( + Self::X(xconn) => Ok(raw_window_handle::XlibDisplayHandle::new( NonNull::new(xconn.display.cast()), xconn.default_screen_index() as _, ) @@ -979,7 +975,7 @@ impl OwnedDisplayHandle { Self::Wayland(conn) => { use sctk::reexports::client::Proxy; - Ok(rwh_06::WaylandDisplayHandle::new( + Ok(raw_window_handle::WaylandDisplayHandle::new( NonNull::new(conn.display().id().as_ptr().cast()).unwrap(), ) .into()) diff --git a/rio-window/src/platform_impl/linux/wayland/event_loop/mod.rs b/rio-window/src/platform_impl/linux/wayland/event_loop/mod.rs index 35214f8b..159a1031 100644 --- a/rio-window/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/rio-window/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -733,14 +733,13 @@ impl ActiveEventLoop { } } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { + ) -> Result { use sctk::reexports::client::Proxy; - Ok(rwh_06::WaylandDisplayHandle::new({ + Ok(raw_window_handle::WaylandDisplayHandle::new({ let ptr = self.connection.display().id().as_ptr(); std::ptr::NonNull::new(ptr as *mut _) .expect("wl_display should never be null") diff --git a/rio-window/src/platform_impl/linux/wayland/mod.rs b/rio-window/src/platform_impl/linux/wayland/mod.rs index 48e959d0..d0806607 100644 --- a/rio-window/src/platform_impl/linux/wayland/mod.rs +++ b/rio-window/src/platform_impl/linux/wayland/mod.rs @@ -1,5 +1,3 @@ -#![cfg(wayland_platform)] - //! Winit's Wayland backend. use std::fmt::Display; diff --git a/rio-window/src/platform_impl/linux/wayland/window/mod.rs b/rio-window/src/platform_impl/linux/wayland/window/mod.rs index 331c412a..887948f7 100644 --- a/rio-window/src/platform_impl/linux/wayland/window/mod.rs +++ b/rio-window/src/platform_impl/linux/wayland/window/mod.rs @@ -678,24 +678,22 @@ impl Window { None } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::WaylandWindowHandle::new({ + ) -> Result { + Ok(raw_window_handle::WaylandWindowHandle::new({ let ptr = self.window.wl_surface().id().as_ptr(); std::ptr::NonNull::new(ptr as *mut _).expect("wl_surface will never be null") }) .into()) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::WaylandDisplayHandle::new({ + ) -> Result { + Ok(raw_window_handle::WaylandDisplayHandle::new({ let ptr = self.display.id().as_ptr(); std::ptr::NonNull::new(ptr as *mut _).expect("wl_proxy should never be null") }) diff --git a/rio-window/src/platform_impl/linux/x11/event_processor.rs b/rio-window/src/platform_impl/linux/x11/event_processor.rs index 6e807c43..56c7d9ac 100644 --- a/rio-window/src/platform_impl/linux/x11/event_processor.rs +++ b/rio-window/src/platform_impl/linux/x11/event_processor.rs @@ -450,7 +450,7 @@ impl EventProcessor { let flags = xev.data.get_long(1); let version = flags >> 24; self.dnd.version = Some(version); - let has_more_types = flags - (flags & (c_long::max_value() - 1)) == 1; + let has_more_types = flags - (flags & (c_long::MAX - 1)) == 1; if !has_more_types { let type_list = vec![ xev.data.get_long(2) as xproto::Atom, diff --git a/rio-window/src/platform_impl/linux/x11/ime/context.rs b/rio-window/src/platform_impl/linux/x11/ime/context.rs index 299d4fd0..ebfeba74 100644 --- a/rio-window/src/platform_impl/linux/x11/ime/context.rs +++ b/rio-window/src/platform_impl/linux/x11/ime/context.rs @@ -172,7 +172,10 @@ struct PreeditCallbacks { impl PreeditCallbacks { pub fn new(client_data: ffi::XPointer) -> PreeditCallbacks { let start_callback = create_xim_callback(client_data, unsafe { - mem::transmute(preedit_start_callback as usize) + mem::transmute::< + usize, + unsafe extern "C" fn(*mut x11_dl::xlib::_XIM, *mut i8, *mut i8), + >(preedit_start_callback as usize) }); let done_callback = create_xim_callback(client_data, preedit_done_callback); let caret_callback = create_xim_callback(client_data, preedit_caret_callback); diff --git a/rio-window/src/platform_impl/linux/x11/mod.rs b/rio-window/src/platform_impl/linux/x11/mod.rs index b1bffbe7..de0e3a67 100644 --- a/rio-window/src/platform_impl/linux/x11/mod.rs +++ b/rio-window/src/platform_impl/linux/x11/mod.rs @@ -1,5 +1,3 @@ -#![cfg(x11_platform)] - use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet, VecDeque}; use std::ffi::CStr; @@ -729,11 +727,10 @@ impl ActiveEventLoop { .expect_then_ignore_error("Failed to update device event filter"); } - #[cfg(feature = "rwh_06")] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - let display_handle = rwh_06::XlibDisplayHandle::new( + ) -> Result { + let display_handle = raw_window_handle::XlibDisplayHandle::new( // SAFETY: display will never be null Some( std::ptr::NonNull::new(self.xconn.display as *mut _) diff --git a/rio-window/src/platform_impl/linux/x11/window.rs b/rio-window/src/platform_impl/linux/x11/window.rs index 7f86a9ad..7b688745 100644 --- a/rio-window/src/platform_impl/linux/x11/window.rs +++ b/rio-window/src/platform_impl/linux/x11/window.rs @@ -153,12 +153,11 @@ impl UnownedWindow { ) -> Result { let xconn = &event_loop.xconn; let atoms = xconn.atoms(); - #[cfg(feature = "rwh_06")] let root = match window_attrs.parent_window.as_ref().map(|handle| handle.0) { - Some(rwh_06::RawWindowHandle::Xlib(handle)) => { + Some(raw_window_handle::RawWindowHandle::Xlib(handle)) => { handle.window as xproto::Window } - Some(rwh_06::RawWindowHandle::Xcb(handle)) => handle.window.get(), + Some(raw_window_handle::RawWindowHandle::Xcb(handle)) => handle.window.get(), Some(raw) => unreachable!("Invalid raw window handle {raw:?} on X11"), None => event_loop.root, }; @@ -1998,22 +1997,21 @@ impl UnownedWindow { // TODO timer } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06( &self, - ) -> Result { - let mut window_handle = rwh_06::XlibWindowHandle::new(self.xlib_window()); + ) -> Result { + let mut window_handle = + raw_window_handle::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 { - Ok(rwh_06::XlibDisplayHandle::new( + ) -> Result { + Ok(raw_window_handle::XlibDisplayHandle::new( Some( std::ptr::NonNull::new(self.xlib_display()) .expect("display pointer should never be null"), diff --git a/rio-window/src/platform_impl/macos/event_loop.rs b/rio-window/src/platform_impl/macos/event_loop.rs index 66b637f4..8f8f4ebc 100644 --- a/rio-window/src/platform_impl/macos/event_loop.rs +++ b/rio-window/src/platform_impl/macos/event_loop.rs @@ -105,13 +105,12 @@ impl ActiveEventLoop { #[inline] pub fn listen_device_events(&self, _allowed: DeviceEvents) {} - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::AppKit( - rwh_06::AppKitDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::AppKit( + raw_window_handle::AppKitDisplayHandle::new(), )) } @@ -390,12 +389,11 @@ impl EventLoop { pub(crate) struct OwnedDisplayHandle; impl OwnedDisplayHandle { - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::AppKitDisplayHandle::new().into()) + ) -> Result { + Ok(raw_window_handle::AppKitDisplayHandle::new().into()) } } diff --git a/rio-window/src/platform_impl/macos/window.rs b/rio-window/src/platform_impl/macos/window.rs index e090159e..6e942a6d 100644 --- a/rio-window/src/platform_impl/macos/window.rs +++ b/rio-window/src/platform_impl/macos/window.rs @@ -53,25 +53,23 @@ impl Window { self.delegate.get_on_main(|delegate| f(delegate)) } - #[cfg(feature = "rwh_06")] #[inline] pub(crate) fn raw_window_handle_rwh_06( &self, - ) -> Result { + ) -> Result { if let Some(mtm) = MainThreadMarker::new() { Ok(self.delegate.get(mtm).raw_window_handle_rwh_06()) } else { - Err(rwh_06::HandleError::Unavailable) + Err(raw_window_handle::HandleError::Unavailable) } } - #[cfg(feature = "rwh_06")] #[inline] pub(crate) fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::AppKit( - rwh_06::AppKitDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::AppKit( + raw_window_handle::AppKitDisplayHandle::new(), )) } } diff --git a/rio-window/src/platform_impl/macos/window_delegate.rs b/rio-window/src/platform_impl/macos/window_delegate.rs index 25e6db2e..e2982ba7 100644 --- a/rio-window/src/platform_impl/macos/window_delegate.rs +++ b/rio-window/src/platform_impl/macos/window_delegate.rs @@ -628,9 +628,8 @@ impl WindowDelegate { os_error!(OsError::CreationError("couldn't create `NSWindow`")) })?; - #[cfg(feature = "rwh_06")] match attrs.parent_window.map(|handle| handle.0) { - Some(rwh_06::RawWindowHandle::AppKit(handle)) => { + Some(raw_window_handle::RawWindowHandle::AppKit(handle)) => { // SAFETY: Caller ensures the pointer is valid or NULL // Unwrap is fine, since the pointer comes from `NonNull`. let parent_view: Retained = @@ -1603,14 +1602,13 @@ impl WindowDelegate { Some(monitor) } - #[cfg(feature = "rwh_06")] #[inline] - pub fn raw_window_handle_rwh_06(&self) -> rwh_06::RawWindowHandle { - let window_handle = rwh_06::AppKitWindowHandle::new({ + pub fn raw_window_handle_rwh_06(&self) -> raw_window_handle::RawWindowHandle { + let window_handle = raw_window_handle::AppKitWindowHandle::new({ let ptr = Retained::as_ptr(&self.view()) as *mut _; std::ptr::NonNull::new(ptr).expect("Retained should never be null") }); - rwh_06::RawWindowHandle::AppKit(window_handle) + raw_window_handle::RawWindowHandle::AppKit(window_handle) } fn toggle_style_mask(&self, mask: NSWindowStyleMask, on: bool) { diff --git a/rio-window/src/platform_impl/orbital/event_loop.rs b/rio-window/src/platform_impl/orbital/event_loop.rs index a47f5483..dc3fa6fd 100644 --- a/rio-window/src/platform_impl/orbital/event_loop.rs +++ b/rio-window/src/platform_impl/orbital/event_loop.rs @@ -849,13 +849,12 @@ impl ActiveEventLoop { #[inline] pub fn listen_device_events(&self, _allowed: DeviceEvents) {} - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::Orbital( - rwh_06::OrbitalDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::Orbital( + raw_window_handle::OrbitalDisplayHandle::new(), )) } @@ -884,11 +883,10 @@ impl ActiveEventLoop { pub(crate) struct OwnedDisplayHandle; impl OwnedDisplayHandle { - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::OrbitalDisplayHandle::new().into()) + ) -> Result { + Ok(raw_window_handle::OrbitalDisplayHandle::new().into()) } } diff --git a/rio-window/src/platform_impl/orbital/window.rs b/rio-window/src/platform_impl/orbital/window.rs index e6001a0d..a940082a 100644 --- a/rio-window/src/platform_impl/orbital/window.rs +++ b/rio-window/src/platform_impl/orbital/window.rs @@ -468,25 +468,23 @@ impl Window { )) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06( &self, - ) -> Result { - let handle = rwh_06::OrbitalWindowHandle::new({ + ) -> Result { + let handle = raw_window_handle::OrbitalWindowHandle::new({ let window = self.window_socket.fd as *mut _; std::ptr::NonNull::new(window).expect("orbital fd should never be null") }); - Ok(rwh_06::RawWindowHandle::Orbital(handle)) + Ok(raw_window_handle::RawWindowHandle::Orbital(handle)) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::Orbital( - rwh_06::OrbitalDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::Orbital( + raw_window_handle::OrbitalDisplayHandle::new(), )) } diff --git a/rio-window/src/platform_impl/web/event_loop/window_target.rs b/rio-window/src/platform_impl/web/event_loop/window_target.rs index 442d2b9e..af0a188f 100644 --- a/rio-window/src/platform_impl/web/event_loop/window_target.rs +++ b/rio-window/src/platform_impl/web/event_loop/window_target.rs @@ -692,13 +692,12 @@ impl ActiveEventLoop { None } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::Web( - rwh_06::WebDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::Web( + raw_window_handle::WebDisplayHandle::new(), )) } @@ -743,11 +742,10 @@ impl ActiveEventLoop { pub(crate) struct OwnedDisplayHandle; impl OwnedDisplayHandle { - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::WebDisplayHandle::new().into()) + ) -> Result { + Ok(raw_window_handle::WebDisplayHandle::new().into()) } } diff --git a/rio-window/src/platform_impl/web/web_sys/canvas.rs b/rio-window/src/platform_impl/web/web_sys/canvas.rs index 89752c55..1c41dbfb 100644 --- a/rio-window/src/platform_impl/web/web_sys/canvas.rs +++ b/rio-window/src/platform_impl/web/web_sys/canvas.rs @@ -54,9 +54,6 @@ pub struct Canvas { pub struct Common { pub window: web_sys::Window, pub document: Document, - /// Note: resizing the HTMLCanvasElement should go through `backend::set_canvas_size` to ensure - /// the DPI factor is maintained. Note: this is read-only because we use a pointer to this - /// for [`WindowHandle`][rwh_06::WindowHandle]. raw: Rc, style: Style, old_size: Rc>>, diff --git a/rio-window/src/platform_impl/web/window.rs b/rio-window/src/platform_impl/web/window.rs index 7e3aa13b..eafdb873 100644 --- a/rio-window/src/platform_impl/web/window.rs +++ b/rio-window/src/platform_impl/web/window.rs @@ -100,32 +100,30 @@ impl Window { }) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06( &self, - ) -> Result { + ) -> Result { self.inner .value() .map(|inner| { let canvas = inner.canvas.borrow(); // SAFETY: This will only work if the reference to `HtmlCanvasElement` stays valid. let canvas: &wasm_bindgen::JsValue = canvas.raw(); - let window_handle = rwh_06::WebCanvasWindowHandle::new( + let window_handle = raw_window_handle::WebCanvasWindowHandle::new( std::ptr::NonNull::from(canvas).cast(), ); - rwh_06::RawWindowHandle::WebCanvas(window_handle) + raw_window_handle::RawWindowHandle::WebCanvas(window_handle) }) - .ok_or(rwh_06::HandleError::Unavailable) + .ok_or(raw_window_handle::HandleError::Unavailable) } - #[cfg(feature = "rwh_06")] #[inline] pub(crate) fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::Web( - rwh_06::WebDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::Web( + raw_window_handle::WebDisplayHandle::new(), )) } } diff --git a/rio-window/src/platform_impl/windows/event_loop.rs b/rio-window/src/platform_impl/windows/event_loop.rs index 42797854..ecc8ef8e 100644 --- a/rio-window/src/platform_impl/windows/event_loop.rs +++ b/rio-window/src/platform_impl/windows/event_loop.rs @@ -557,12 +557,11 @@ impl ActiveEventLoop { Some(monitor) } - #[cfg(feature = "rwh_06")] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::Windows( - rwh_06::WindowsDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::Windows( + raw_window_handle::WindowsDisplayHandle::new(), )) } @@ -606,12 +605,11 @@ impl ActiveEventLoop { pub(crate) struct OwnedDisplayHandle; impl OwnedDisplayHandle { - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::WindowsDisplayHandle::new().into()) + ) -> Result { + Ok(raw_window_handle::WindowsDisplayHandle::new().into()) } } diff --git a/rio-window/src/platform_impl/windows/window.rs b/rio-window/src/platform_impl/windows/window.rs index 38007922..19745185 100644 --- a/rio-window/src/platform_impl/windows/window.rs +++ b/rio-window/src/platform_impl/windows/window.rs @@ -363,43 +363,40 @@ impl Window { self.window } - #[cfg(feature = "rwh_06")] #[inline] pub unsafe fn rwh_06_no_thread_check( &self, - ) -> Result { - let mut window_handle = rwh_06::Win32WindowHandle::new(unsafe { + ) -> Result { + let mut window_handle = raw_window_handle::Win32WindowHandle::new(unsafe { // SAFETY: Handle will never be zero. std::num::NonZeroIsize::new_unchecked(self.window) }); let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) }; window_handle.hinstance = std::num::NonZeroIsize::new(hinstance); - Ok(rwh_06::RawWindowHandle::Win32(window_handle)) + Ok(raw_window_handle::RawWindowHandle::Win32(window_handle)) } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06( &self, - ) -> Result { + ) -> Result { // TODO: Write a test once integration framework is ready to ensure that it holds. // If we aren't in the GUI thread, we can't return the window. if !self.thread_executor.in_event_loop_thread() { tracing::error!("tried to access window handle outside of the main thread"); - return Err(rwh_06::HandleError::Unavailable); + return Err(raw_window_handle::HandleError::Unavailable); } // SAFETY: We are on the correct thread. unsafe { self.rwh_06_no_thread_check() } } - #[cfg(feature = "rwh_06")] #[inline] pub fn raw_display_handle_rwh_06( &self, - ) -> Result { - Ok(rwh_06::RawDisplayHandle::Windows( - rwh_06::WindowsDisplayHandle::new(), + ) -> Result { + Ok(raw_window_handle::RawDisplayHandle::Windows( + raw_window_handle::WindowsDisplayHandle::new(), )) } @@ -1412,9 +1409,8 @@ unsafe fn init( } }; - #[cfg(feature = "rwh_06")] let parent = match attributes.parent_window.as_ref().map(|handle| handle.0) { - Some(rwh_06::RawWindowHandle::Win32(handle)) => { + Some(raw_window_handle::RawWindowHandle::Win32(handle)) => { window_flags.set(WindowFlags::CHILD, true); if attributes.platform_specific.menu.is_some() { warn!("Setting a menu on a child window is unsupported"); diff --git a/rio-window/src/window.rs b/rio-window/src/window.rs index e2c625d8..6cef0ac9 100644 --- a/rio-window/src/window.rs +++ b/rio-window/src/window.rs @@ -124,7 +124,6 @@ pub struct WindowAttributes { pub window_level: WindowLevel, pub active: bool, pub cursor: Cursor, - #[cfg(feature = "rwh_06")] pub(crate) parent_window: Option, pub fullscreen: Option, // Platform-specific configuration. @@ -155,7 +154,6 @@ impl Default for WindowAttributes { resize_increments: None, content_protected: false, cursor: Cursor::default(), - #[cfg(feature = "rwh_06")] parent_window: None, active: true, platform_specific: Default::default(), @@ -163,19 +161,16 @@ impl Default for WindowAttributes { } } -/// Wrapper for [`rwh_06::RawWindowHandle`] for [`WindowAttributes::parent_window`]. +/// Wrapper for [`raw_window_handle::RawWindowHandle`] for [`WindowAttributes::parent_window`]. /// /// # Safety /// /// The user has to account for that when using [`WindowAttributes::with_parent_window()`], /// which is `unsafe`. #[derive(Debug, Clone)] -#[cfg(feature = "rwh_06")] -pub(crate) struct SendSyncRawWindowHandle(pub(crate) rwh_06::RawWindowHandle); +pub(crate) struct SendSyncRawWindowHandle(pub(crate) raw_window_handle::RawWindowHandle); -#[cfg(feature = "rwh_06")] unsafe impl Send for SendSyncRawWindowHandle {} -#[cfg(feature = "rwh_06")] unsafe impl Sync for SendSyncRawWindowHandle {} impl WindowAttributes { @@ -189,8 +184,7 @@ impl WindowAttributes { impl WindowAttributes { /// Get the parent window stored on the attributes. - #[cfg(feature = "rwh_06")] - pub fn parent_window(&self) -> Option<&rwh_06::RawWindowHandle> { + pub fn parent_window(&self) -> Option<&raw_window_handle::RawWindowHandle> { self.parent_window.as_ref().map(|handle| &handle.0) } @@ -459,11 +453,10 @@ impl WindowAttributes { self } - #[cfg(feature = "rwh_06")] #[inline] pub unsafe fn with_parent_window( mut self, - parent_window: Option, + parent_window: Option, ) -> Self { self.parent_window = parent_window.map(SendSyncRawWindowHandle); self @@ -1684,25 +1677,28 @@ impl Window { } } -#[cfg(feature = "rwh_06")] -impl rwh_06::HasWindowHandle for Window { - fn window_handle(&self) -> Result, rwh_06::HandleError> { +impl raw_window_handle::HasWindowHandle for Window { + fn window_handle( + &self, + ) -> Result, raw_window_handle::HandleError> { let raw = self.window.raw_window_handle_rwh_06()?; // SAFETY: The window handle will never be deallocated while the window is alive, // and the main thread safety requirements are upheld internally by each platform. - Ok(unsafe { rwh_06::WindowHandle::borrow_raw(raw) }) + Ok(unsafe { raw_window_handle::WindowHandle::borrow_raw(raw) }) } } -#[cfg(feature = "rwh_06")] -impl rwh_06::HasDisplayHandle for Window { - fn display_handle(&self) -> Result, rwh_06::HandleError> { +impl raw_window_handle::HasDisplayHandle for Window { + fn display_handle( + &self, + ) -> Result, raw_window_handle::HandleError> + { let raw = self.window.raw_display_handle_rwh_06()?; // SAFETY: The window handle will never be deallocated while the window is alive, // and the main thread safety requirements are upheld internally by each platform. - Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw) }) + Ok(unsafe { raw_window_handle::DisplayHandle::borrow_raw(raw) }) } } -- 2.51.2