From 6443c227c162ea0fa3fa61cbef047a17f07a7027 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Thu, 14 Dec 2023 12:02:56 +0100 Subject: [PATCH] Add a rwh_05 feature flag This allows using accesskit with current versions of wgpu. Winit has a similar system to widden its support. See https://github.com/rust-windowing/winit/pull/3126 --- Cargo.lock | 12 ++++++++++-- platforms/winit/Cargo.toml | 8 +++++--- platforms/winit/src/lib.rs | 3 +++ platforms/winit/src/platform_impl/macos.rs | 3 +++ platforms/winit/src/platform_impl/windows.rs | 3 +++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1e9788ad..e36fd8f06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,7 +1122,8 @@ dependencies = [ "log", "ndk-sys", "num_enum", - "raw-window-handle", + "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "thiserror", ] @@ -1501,6 +1502,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "raw-window-handle" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" + [[package]] name = "raw-window-handle" version = "0.6.0" @@ -2479,7 +2486,8 @@ dependencies = [ "once_cell", "orbclient", "percent-encoding", - "raw-window-handle", + "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "redox_syscall 0.3.5", "rustix 0.38.21", "sctk-adwaita", diff --git a/platforms/winit/Cargo.toml b/platforms/winit/Cargo.toml index 6a79a7fd3..e9b6a9c2d 100644 --- a/platforms/winit/Cargo.toml +++ b/platforms/winit/Cargo.toml @@ -14,13 +14,15 @@ edition = "2021" features = ["winit/rwh_06", "winit/x11", "winit/wayland"] [features] -default = ["accesskit_unix", "async-io"] +default = ["accesskit_unix", "async-io", "rwh_06"] +rwh_06 = ["winit/rwh_06"] +rwh_05 = ["winit/rwh_05"] async-io = ["accesskit_unix/async-io"] tokio = ["accesskit_unix/tokio"] [dependencies] accesskit = { version = "0.12.1", path = "../../common" } -winit = { version = "0.29", default-features = false, features = ["rwh_06"] } +winit = { version = "0.29", default-features = false } [target.'cfg(target_os = "windows")'.dependencies] accesskit_windows = { version = "0.15.1", path = "../windows" } @@ -34,4 +36,4 @@ accesskit_unix = { version = "0.6.1", path = "../unix", optional = true, default [dev-dependencies.winit] version = "0.29" default-features = false -features = ["rwh_06", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] +features = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] diff --git a/platforms/winit/src/lib.rs b/platforms/winit/src/lib.rs index 2bfc08f0c..1516142b2 100644 --- a/platforms/winit/src/lib.rs +++ b/platforms/winit/src/lib.rs @@ -11,6 +11,9 @@ use winit::{ mod platform_impl; +#[cfg(all(feature = "rwh_05", feature = "rwh_06"))] +compile_error!("Cannot enable both 'rwh_05' and 'rwh_06' features at the same time"); + #[derive(Debug)] pub struct ActionRequestEvent { pub window_id: WindowId, diff --git a/platforms/winit/src/platform_impl/macos.rs b/platforms/winit/src/platform_impl/macos.rs index 64452dbde..e258ff05f 100644 --- a/platforms/winit/src/platform_impl/macos.rs +++ b/platforms/winit/src/platform_impl/macos.rs @@ -23,7 +23,10 @@ impl Adapter { action_handler: ActionHandlerBox, ) -> Self { let view = match window.window_handle().unwrap().as_raw() { + #[cfg(feature = "rwh_06")] RawWindowHandle::AppKit(handle) => handle.ns_view.as_ptr(), + #[cfg(feature = "rwh_05")] + RawWindowHandle::AppKit(handle) => handle.ns_view, RawWindowHandle::UiKit(_) => unimplemented!(), _ => unreachable!(), }; diff --git a/platforms/winit/src/platform_impl/windows.rs b/platforms/winit/src/platform_impl/windows.rs index 58ec9743d..a4123eeb4 100644 --- a/platforms/winit/src/platform_impl/windows.rs +++ b/platforms/winit/src/platform_impl/windows.rs @@ -23,7 +23,10 @@ impl Adapter { action_handler: ActionHandlerBox, ) -> Self { let hwnd = match window.window_handle().unwrap().as_raw() { + #[cfg(feature = "rwh_06")] RawWindowHandle::Win32(handle) => HWND(handle.hwnd.get()), + #[cfg(feature = "rwh_05")] + RawWindowHandle::Win32(handle) => handle.hwnd as isize, RawWindowHandle::WinRt(_) => unimplemented!(), _ => unreachable!(), };