From daa6c6c2429da9f70f3585b488e9fb99fcadb4e8 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Thu, 14 Dec 2023 12:02:56 +0100 Subject: [PATCH 1/3] 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 | 14 ++++++++++++-- platforms/winit/Cargo.toml | 10 +++++++--- platforms/winit/src/lib.rs | 10 ++++++++++ platforms/winit/src/platform_impl/macos.rs | 15 ++++++++++----- platforms/winit/src/platform_impl/windows.rs | 19 ++++++++++++------- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1e9788ad..2aee8a428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,8 @@ dependencies = [ "accesskit_macos", "accesskit_unix", "accesskit_windows", + "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "winit", ] @@ -1122,7 +1124,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 +1504,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 +2488,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..94619e7b6 100644 --- a/platforms/winit/Cargo.toml +++ b/platforms/winit/Cargo.toml @@ -14,13 +14,17 @@ edition = "2021" features = ["winit/rwh_06", "winit/x11", "winit/wayland"] [features] -default = ["accesskit_unix", "async-io"] +default = ["accesskit_unix", "async-io", "rwh_06"] +rwh_05 = ["winit/rwh_05", "dep:rwh_05"] +rwh_06 = ["winit/rwh_06", "dep:rwh_06"] 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 } +rwh_05 = { package = "raw-window-handle", version = "0.5", features = ["std"], optional = true } +rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"], optional = true } [target.'cfg(target_os = "windows")'.dependencies] accesskit_windows = { version = "0.15.1", path = "../windows" } @@ -34,4 +38,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..94eef7cc7 100644 --- a/platforms/winit/src/lib.rs +++ b/platforms/winit/src/lib.rs @@ -9,8 +9,18 @@ use winit::{ window::{Window, WindowId}, }; +#[cfg(feature = "rwh_05")] +#[allow(unused)] +use rwh_05 as raw_window_handle; +#[cfg(feature = "rwh_06")] +#[allow(unused)] +use rwh_06 as raw_window_handle; + 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..1efc1f84d 100644 --- a/platforms/winit/src/platform_impl/macos.rs +++ b/platforms/winit/src/platform_impl/macos.rs @@ -1,14 +1,11 @@ // Copyright 2022 The AccessKit Authors. All rights reserved. // Licensed under the Apache License, Version 2.0 (found in // the LICENSE-APACHE file). +use crate::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use accesskit::{ActionHandler, TreeUpdate}; use accesskit_macos::SubclassingAdapter; -use winit::{ - event::WindowEvent, - raw_window_handle::{HasWindowHandle, RawWindowHandle}, - window::Window, -}; +use winit::{event::WindowEvent, window::Window}; pub type ActionHandlerBox = Box; @@ -22,11 +19,19 @@ impl Adapter { source: impl 'static + FnOnce() -> TreeUpdate, action_handler: ActionHandlerBox, ) -> Self { + #[cfg(feature = "rwh_05")] + let view = match window.raw_window_handle() { + RawWindowHandle::AppKit(handle) => handle.ns_view, + RawWindowHandle::UiKit(_) => unimplemented!(), + _ => unreachable!(), + }; + #[cfg(feature = "rwh_06")] let view = match window.window_handle().unwrap().as_raw() { RawWindowHandle::AppKit(handle) => handle.ns_view.as_ptr(), RawWindowHandle::UiKit(_) => unimplemented!(), _ => unreachable!(), }; + let adapter = unsafe { SubclassingAdapter::new(view, source, action_handler) }; Self { adapter } } diff --git a/platforms/winit/src/platform_impl/windows.rs b/platforms/winit/src/platform_impl/windows.rs index 58ec9743d..5a16af79e 100644 --- a/platforms/winit/src/platform_impl/windows.rs +++ b/platforms/winit/src/platform_impl/windows.rs @@ -1,14 +1,11 @@ // Copyright 2022 The AccessKit Authors. All rights reserved. // Licensed under the Apache License, Version 2.0 (found in // the LICENSE-APACHE file). +use crate::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use accesskit::{ActionHandler, TreeUpdate}; -use accesskit_windows::{SubclassingAdapter, HWND}; -use winit::{ - event::WindowEvent, - raw_window_handle::{HasWindowHandle, RawWindowHandle}, - window::Window, -}; +use accesskit_windows::SubclassingAdapter; +use winit::{event::WindowEvent, window::Window}; pub type ActionHandlerBox = Box; @@ -22,11 +19,19 @@ impl Adapter { source: impl 'static + FnOnce() -> TreeUpdate, action_handler: ActionHandlerBox, ) -> Self { + #[cfg(feature = "rwh_05")] + let hwnd = match window.raw_window_handle() { + RawWindowHandle::Win32(handle) => handle.hwnd as isize, + RawWindowHandle::WinRt(_) => unimplemented!(), + _ => unreachable!(), + }; + #[cfg(feature = "rwh_06")] let hwnd = match window.window_handle().unwrap().as_raw() { - RawWindowHandle::Win32(handle) => HWND(handle.hwnd.get()), + RawWindowHandle::Win32(handle) => accesskit_windows::HWND(handle.hwnd.get()), RawWindowHandle::WinRt(_) => unimplemented!(), _ => unreachable!(), }; + let adapter = SubclassingAdapter::new(hwnd, source, action_handler); Self { adapter } } From d72cc3637647b17f3e2de6311f08aa7b294755c2 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Thu, 14 Dec 2023 14:34:34 +0100 Subject: [PATCH 2/3] Fix windows plateform compilation --- platforms/winit/src/platform_impl/macos.rs | 1 + platforms/winit/src/platform_impl/windows.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platforms/winit/src/platform_impl/macos.rs b/platforms/winit/src/platform_impl/macos.rs index 1efc1f84d..1cd50945c 100644 --- a/platforms/winit/src/platform_impl/macos.rs +++ b/platforms/winit/src/platform_impl/macos.rs @@ -1,6 +1,7 @@ // Copyright 2022 The AccessKit Authors. All rights reserved. // Licensed under the Apache License, Version 2.0 (found in // the LICENSE-APACHE file). +#[allow(unused)] use crate::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use accesskit::{ActionHandler, TreeUpdate}; diff --git a/platforms/winit/src/platform_impl/windows.rs b/platforms/winit/src/platform_impl/windows.rs index 5a16af79e..8cba24b81 100644 --- a/platforms/winit/src/platform_impl/windows.rs +++ b/platforms/winit/src/platform_impl/windows.rs @@ -1,10 +1,11 @@ // Copyright 2022 The AccessKit Authors. All rights reserved. // Licensed under the Apache License, Version 2.0 (found in // the LICENSE-APACHE file). +#[allow(unused)] use crate::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use accesskit::{ActionHandler, TreeUpdate}; -use accesskit_windows::SubclassingAdapter; +use accesskit_windows::{SubclassingAdapter, HWND}; use winit::{event::WindowEvent, window::Window}; pub type ActionHandlerBox = Box; @@ -27,12 +28,12 @@ impl Adapter { }; #[cfg(feature = "rwh_06")] let hwnd = match window.window_handle().unwrap().as_raw() { - RawWindowHandle::Win32(handle) => accesskit_windows::HWND(handle.hwnd.get()), + RawWindowHandle::Win32(handle) => handle.hwnd.get(), RawWindowHandle::WinRt(_) => unimplemented!(), _ => unreachable!(), }; - let adapter = SubclassingAdapter::new(hwnd, source, action_handler); + let adapter = SubclassingAdapter::new(HWND(hwnd), source, action_handler); Self { adapter } } From f72985947d5f1a367e8910a3974b3099492db58e Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Thu, 14 Dec 2023 14:45:11 +0100 Subject: [PATCH 3/3] Use proper trait from rwh --- platforms/winit/src/platform_impl/macos.rs | 4 +++- platforms/winit/src/platform_impl/windows.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platforms/winit/src/platform_impl/macos.rs b/platforms/winit/src/platform_impl/macos.rs index 1cd50945c..4c9e5356f 100644 --- a/platforms/winit/src/platform_impl/macos.rs +++ b/platforms/winit/src/platform_impl/macos.rs @@ -1,7 +1,9 @@ // Copyright 2022 The AccessKit Authors. All rights reserved. // Licensed under the Apache License, Version 2.0 (found in // the LICENSE-APACHE file). -#[allow(unused)] +#[cfg(feature = "rwh_05")] +use crate::raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; +#[cfg(feature = "rwh_06")] use crate::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use accesskit::{ActionHandler, TreeUpdate}; diff --git a/platforms/winit/src/platform_impl/windows.rs b/platforms/winit/src/platform_impl/windows.rs index 8cba24b81..d49574641 100644 --- a/platforms/winit/src/platform_impl/windows.rs +++ b/platforms/winit/src/platform_impl/windows.rs @@ -1,7 +1,9 @@ // Copyright 2022 The AccessKit Authors. All rights reserved. // Licensed under the Apache License, Version 2.0 (found in // the LICENSE-APACHE file). -#[allow(unused)] +#[cfg(feature = "rwh_05")] +use crate::raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; +#[cfg(feature = "rwh_06")] use crate::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use accesskit::{ActionHandler, TreeUpdate};