Skip to content

Commit

Permalink
fix: Add a rwh_05 feature flag to accesskit_winit (#319)
Browse files Browse the repository at this point in the history
This allows choosing which version of raw-window-handle to depend on:

- Enabling the `rwh_06` feature will select raw-window-handle version `0.6.x` (this is the default).
- Enabling `rwh_05` will instead select raw-window-handle version `0.5.x`.
  • Loading branch information
nicopap authored Dec 14, 2023
1 parent 8fde634 commit f4d279c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions platforms/winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"]
10 changes: 10 additions & 0 deletions platforms/winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 13 additions & 5 deletions platforms/winit/src/platform_impl/macos.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file).
#[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};
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<dyn ActionHandler>;

Expand All @@ -22,11 +22,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 }
}
Expand Down
22 changes: 15 additions & 7 deletions platforms/winit/src/platform_impl/windows.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file).
#[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};
use accesskit_windows::{SubclassingAdapter, HWND};
use winit::{
event::WindowEvent,
raw_window_handle::{HasWindowHandle, RawWindowHandle},
window::Window,
};
use winit::{event::WindowEvent, window::Window};

pub type ActionHandlerBox = Box<dyn ActionHandler + Send>;

Expand All @@ -22,12 +22,20 @@ 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) => 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 }
}

Expand Down

0 comments on commit f4d279c

Please sign in to comment.