From 630fb9423f513201ab59949463438e59ed872004 Mon Sep 17 00:00:00 2001 From: DataTriny Date: Fri, 27 Oct 2023 00:37:48 +0200 Subject: [PATCH] Fix accesskit_winit --- Cargo.lock | 304 +++++++++++++++++++ platforms/winit/Cargo.toml | 6 +- platforms/winit/examples/simple.rs | 2 +- platforms/winit/src/platform_impl/macos.rs | 16 +- platforms/winit/src/platform_impl/windows.rs | 19 +- 5 files changed, 320 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fffbbd41a..ce2c5b707 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,6 +78,7 @@ dependencies = [ "accesskit_macos", "accesskit_unix", "accesskit_windows", + "raw-window-handle 0.5.2", "winit", ] @@ -96,6 +97,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.20" @@ -132,6 +145,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "as-raw-xcb-connection" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5f312b0a56c5cdf967c0aeb67f6289603354951683bc97ddc595ab974ba9aa" + [[package]] name = "async-broadcast" version = "0.5.1" @@ -414,6 +433,12 @@ version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +[[package]] +name = "bytemuck" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" + [[package]] name = "byteorder" version = "1.4.3" @@ -440,6 +465,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "calloop-wayland-source" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" +dependencies = [ + "calloop", + "rustix 0.38.20", + "wayland-backend", + "wayland-client", +] + [[package]] name = "cc" version = "1.0.79" @@ -597,6 +634,12 @@ dependencies = [ "libloading", ] +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + [[package]] name = "dyn-clone" version = "1.0.11" @@ -789,6 +832,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "getrandom" version = "0.2.8" @@ -976,6 +1029,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memmap2" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deaba38d7abf1d4cca21cc89e932e542ba2b9258664d2a9ef0e61512039c9375" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.7.1" @@ -994,6 +1056,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -1059,6 +1127,16 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num_enum" version = "0.7.0" @@ -1200,6 +1278,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -1212,6 +1296,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + [[package]] name = "polling" version = "2.6.0" @@ -1327,6 +1417,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "quick-xml" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.26" @@ -1499,6 +1598,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.1.0" @@ -1603,6 +1708,31 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "smithay-client-toolkit" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e3d9941fa3bacf7c2bf4b065304faa14164151254cd16ce1b1bc8fc381600f" +dependencies = [ + "bitflags 2.4.1", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2", + "rustix 0.38.20", + "thiserror", + "wayland-backend", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkeysym", +] + [[package]] name = "smol_str" version = "0.2.0" @@ -1893,6 +2023,114 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wayland-backend" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19152ddd73f45f024ed4534d9ca2594e0ef252c1847695255dae47f34df9fbe4" +dependencies = [ + "cc", + "downcast-rs", + "nix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca7d52347346f5473bf2f56705f360e8440873052e575e55890c4fa57843ed3" +dependencies = [ + "bitflags 2.4.1", + "nix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags 2.4.1", + "cursor-icon", + "wayland-backend", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44aa20ae986659d6c77d64d808a046996a932aa763913864dc40c359ef7ad5b" +dependencies = [ + "nix", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c" +dependencies = [ + "bitflags 2.4.1", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-plasma" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" +dependencies = [ + "bitflags 2.4.1", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.4.1", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb8e28403665c9f9513202b7e1ed71ec56fde5c107816843fb14057910b2c09c" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + [[package]] name = "web-sys" version = "0.3.64" @@ -1938,6 +2176,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2130,9 +2377,11 @@ version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b829f75d02fe1e225b97c91a04c326900147a50234d1141a1cbe215ce8798c11" dependencies = [ + "ahash", "android-activity", "atomic-waker", "bitflags 2.4.1", + "bytemuck", "calloop", "cfg_aliases", "core-foundation", @@ -2142,22 +2391,31 @@ dependencies = [ "js-sys", "libc", "log", + "memmap2", "ndk", "ndk-sys", "objc2 0.4.1", "once_cell", "orbclient", + "percent-encoding", "raw-window-handle 0.5.2", "raw-window-handle 0.6.0", "redox_syscall 0.3.5", "rustix 0.38.20", + "smithay-client-toolkit", "smol_str", "unicode-segmentation", "wasm-bindgen", "wasm-bindgen-futures", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-plasma", "web-sys", "web-time", "windows-sys 0.48.0", + "x11-dl", + "x11rb", "xkbcommon-dl", ] @@ -2170,6 +2428,52 @@ dependencies = [ "memchr", ] +[[package]] +name = "x11-dl" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" +dependencies = [ + "libc", + "once_cell", + "pkg-config", +] + +[[package]] +name = "x11rb" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" +dependencies = [ + "as-raw-xcb-connection", + "gethostname", + "libc", + "libloading", + "nix", + "once_cell", + "winapi", + "winapi-wsapoll", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d6c3f9a0fb6701fab8f6cea9b0c0bd5d6876f1f89f7fada07e558077c344bc" +dependencies = [ + "nix", +] + +[[package]] +name = "xcursor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" +dependencies = [ + "nom", +] + [[package]] name = "xdg-home" version = "1.0.0" diff --git a/platforms/winit/Cargo.toml b/platforms/winit/Cargo.toml index c919f64c9..cea1bd841 100644 --- a/platforms/winit/Cargo.toml +++ b/platforms/winit/Cargo.toml @@ -19,9 +19,10 @@ async-io = ["accesskit_unix/async-io"] tokio = ["accesskit_unix/tokio"] [dependencies] -raw-window-handle = { version = "0.5" } accesskit = { version = "0.12.0", path = "../../common" } +raw-window-handle = "0.5" winit = { version = "0.29", default-features = false, features = ["rwh_05"] } + [target.'cfg(target_os = "windows")'.dependencies] accesskit_windows = { version = "0.15.0", path = "../windows" } @@ -33,3 +34,6 @@ accesskit_unix = { version = "0.6.0", path = "../unix", optional = true, default [dev-dependencies] winit = { version = "0.29", default-features = false, features = ["rwh_05"] } + +[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dev-dependencies] +winit = { version = "0.29", default-features = false, features = ["x11", "wayland"] } diff --git a/platforms/winit/examples/simple.rs b/platforms/winit/examples/simple.rs index 5e6d93140..65a29fdba 100644 --- a/platforms/winit/examples/simple.rs +++ b/platforms/winit/examples/simple.rs @@ -6,7 +6,7 @@ use accesskit_winit::{ActionRequestEvent, Adapter}; use std::sync::{Arc, Mutex}; use winit::{ event::{ElementState, Event, KeyEvent, WindowEvent}, - event_loop::{ControlFlow, EventLoopBuilder, EventLoopWindowTarget}, + event_loop::{ControlFlow, EventLoopBuilder}, keyboard::Key, window::WindowBuilder, }; diff --git a/platforms/winit/src/platform_impl/macos.rs b/platforms/winit/src/platform_impl/macos.rs index 282d47ecd..489453cf7 100644 --- a/platforms/winit/src/platform_impl/macos.rs +++ b/platforms/winit/src/platform_impl/macos.rs @@ -5,7 +5,7 @@ use crate::WindowEvent; use accesskit::{ActionHandler, TreeUpdate}; use accesskit_macos::SubclassingAdapter; -use raw_window_handle::HasRawWindowHandle; +use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use winit::window::Window; pub type ActionHandlerBox = Box; @@ -20,17 +20,11 @@ impl Adapter { source: impl 'static + FnOnce() -> TreeUpdate, action_handler: ActionHandlerBox, ) -> Self { - let view = window.raw_window_handle(); - // TODO(Vrixyz): I'm not too sure about that code. // LINK FOR REVIEWERS: https://github.com/rust-windowing/winit/blob/309e6aa85ae60104308d039763d28f42d6fe1595/src/platform_impl/macos/window.rs#L463 - let view = match view { - raw_window_handle::RawWindowHandle::AppKit(handle) => handle.ns_view, - // TODO(Vrixyz): that UIView seems interesting for iOS? - // winit::window::raw_window_handle::RawWindowHandle::UiKit(handle) => handle.ui_view, - unsupported_window_handle => panic!( - "macos should not have that raw window handle type: {:?}", - unsupported_window_handle - ), + let view = match window.raw_window_handle() { + RawWindowHandle::AppKit(handle) => handle.ns_view, + 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 73c621b9e..aa5dce070 100644 --- a/platforms/winit/src/platform_impl/windows.rs +++ b/platforms/winit/src/platform_impl/windows.rs @@ -4,11 +4,8 @@ use accesskit::{ActionHandler, TreeUpdate}; use accesskit_windows::{SubclassingAdapter, HWND}; -use winit::{ - event::WindowEvent, - platform::windows::WindowExtWindows, - window::{raw_window_handle::HasRawWindowHandle, Window}, -}; +use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; +use winit::{event::WindowEvent, window::Window}; pub type ActionHandlerBox = Box; @@ -23,15 +20,9 @@ impl Adapter { action_handler: ActionHandlerBox, ) -> Self { let hwnd = HWND(match window.raw_window_handle() { - winit::window::raw_window_handle::RawWindowHandle::Win32(handle) => { - handle.hwnd as isize - } - // TODO(Vrixyz): not sure if we can do something with that ? (also, duplicated code...) - // winit::window::raw_window_handle::RawWindowHandle::WinRt(handle) => handle.core_window, - unsupported_window_handle => panic!( - "macos should not have that raw window handle type: {:?}", - unsupported_window_handle - ), + RawWindowHandle::Win32(handle) => handle.hwnd as isize, + RawWindowHandle::WinRt(_) => unimplemented!(), + _ => unreachable!(), }); let adapter = SubclassingAdapter::new(hwnd, source, action_handler); Self { adapter }