Skip to content

Commit be95807

Browse files
authored
feat: Feature-gate the Unix adapter in accesskit_winit (#214)
1 parent 4b1012f commit be95807

File tree

4 files changed

+125
-70
lines changed

4 files changed

+125
-70
lines changed

platforms/winit/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ repository = "https://github.com/AccessKit/accesskit"
1010
readme = "README.md"
1111
edition = "2021"
1212

13+
[features]
14+
default = ["accesskit_unix"]
15+
1316
[dependencies]
1417
accesskit = { version = "0.10.0", path = "../../common" }
1518
winit = { version = "0.28", default-features = false }
@@ -21,7 +24,7 @@ accesskit_windows = { version = "0.13.0", path = "../windows" }
2124
accesskit_macos = { version = "0.6.0", path = "../macos" }
2225

2326
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
24-
accesskit_unix = { version = "0.3.0", path = "../unix" }
27+
accesskit_unix = { version = "0.3.0", path = "../unix", optional = true }
2528

2629
[dev-dependencies]
2730
winit = "0.28"

platforms/winit/examples/simple.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,15 @@ fn main() {
143143
println!("- [Space] 'presses' the button, adding static text in a live region announcing that it was pressed.");
144144
#[cfg(target_os = "windows")]
145145
println!("Enable Narrator with [Win]+[Ctrl]+[Enter] (or [Win]+[Enter] on older versions of Windows).");
146-
#[cfg(any(
147-
target_os = "linux",
148-
target_os = "dragonfly",
149-
target_os = "freebsd",
150-
target_os = "netbsd",
151-
target_os = "openbsd"
146+
#[cfg(all(
147+
feature = "accesskit_unix",
148+
any(
149+
target_os = "linux",
150+
target_os = "dragonfly",
151+
target_os = "freebsd",
152+
target_os = "netbsd",
153+
target_os = "openbsd"
154+
)
152155
))]
153156
println!("Enable Orca with [Super]+[Alt]+[S].");
154157

platforms/winit/src/lib.rs

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
use accesskit::{ActionHandler, ActionRequest, TreeUpdate};
66
#[cfg(any(
7-
target_os = "linux",
8-
target_os = "dragonfly",
9-
target_os = "freebsd",
10-
target_os = "netbsd",
11-
target_os = "openbsd",
7+
all(
8+
feature = "accesskit_unix",
9+
any(
10+
target_os = "linux",
11+
target_os = "dragonfly",
12+
target_os = "freebsd",
13+
target_os = "netbsd",
14+
target_os = "openbsd"
15+
)
16+
),
1217
target_os = "windows"
1318
))]
1419
use std::sync::{Mutex, MutexGuard};
@@ -29,32 +34,47 @@ pub struct ActionRequestEvent {
2934
struct WinitActionHandler<T: From<ActionRequestEvent> + Send + 'static> {
3035
window_id: WindowId,
3136
#[cfg(any(
32-
target_os = "linux",
33-
target_os = "dragonfly",
34-
target_os = "freebsd",
35-
target_os = "netbsd",
36-
target_os = "openbsd",
37+
all(
38+
feature = "accesskit_unix",
39+
any(
40+
target_os = "linux",
41+
target_os = "dragonfly",
42+
target_os = "freebsd",
43+
target_os = "netbsd",
44+
target_os = "openbsd"
45+
)
46+
),
3747
target_os = "windows"
3848
))]
3949
proxy: Mutex<EventLoopProxy<T>>,
4050
#[cfg(not(any(
41-
target_os = "linux",
42-
target_os = "dragonfly",
43-
target_os = "freebsd",
44-
target_os = "netbsd",
45-
target_os = "openbsd",
51+
all(
52+
feature = "accesskit_unix",
53+
any(
54+
target_os = "linux",
55+
target_os = "dragonfly",
56+
target_os = "freebsd",
57+
target_os = "netbsd",
58+
target_os = "openbsd"
59+
)
60+
),
4661
target_os = "windows"
4762
)))]
4863
proxy: EventLoopProxy<T>,
4964
}
5065

5166
impl<T: From<ActionRequestEvent> + Send + 'static> WinitActionHandler<T> {
5267
#[cfg(any(
53-
target_os = "linux",
54-
target_os = "dragonfly",
55-
target_os = "freebsd",
56-
target_os = "netbsd",
57-
target_os = "openbsd",
68+
all(
69+
feature = "accesskit_unix",
70+
any(
71+
target_os = "linux",
72+
target_os = "dragonfly",
73+
target_os = "freebsd",
74+
target_os = "netbsd",
75+
target_os = "openbsd"
76+
)
77+
),
5878
target_os = "windows"
5979
))]
6080
fn new(window_id: WindowId, proxy: EventLoopProxy<T>) -> Self {
@@ -64,34 +84,49 @@ impl<T: From<ActionRequestEvent> + Send + 'static> WinitActionHandler<T> {
6484
}
6585
}
6686
#[cfg(not(any(
67-
target_os = "linux",
68-
target_os = "dragonfly",
69-
target_os = "freebsd",
70-
target_os = "netbsd",
71-
target_os = "openbsd",
87+
all(
88+
feature = "accesskit_unix",
89+
any(
90+
target_os = "linux",
91+
target_os = "dragonfly",
92+
target_os = "freebsd",
93+
target_os = "netbsd",
94+
target_os = "openbsd"
95+
)
96+
),
7297
target_os = "windows"
7398
)))]
7499
fn new(window_id: WindowId, proxy: EventLoopProxy<T>) -> Self {
75100
Self { window_id, proxy }
76101
}
77102

78103
#[cfg(any(
79-
target_os = "linux",
80-
target_os = "dragonfly",
81-
target_os = "freebsd",
82-
target_os = "netbsd",
83-
target_os = "openbsd",
104+
all(
105+
feature = "accesskit_unix",
106+
any(
107+
target_os = "linux",
108+
target_os = "dragonfly",
109+
target_os = "freebsd",
110+
target_os = "netbsd",
111+
target_os = "openbsd"
112+
)
113+
),
84114
target_os = "windows"
85115
))]
86116
fn proxy(&self) -> MutexGuard<'_, EventLoopProxy<T>> {
87117
self.proxy.lock().unwrap()
88118
}
89119
#[cfg(not(any(
90-
target_os = "linux",
91-
target_os = "dragonfly",
92-
target_os = "freebsd",
93-
target_os = "netbsd",
94-
target_os = "openbsd",
120+
all(
121+
feature = "accesskit_unix",
122+
any(
123+
target_os = "linux",
124+
target_os = "dragonfly",
125+
target_os = "freebsd",
126+
target_os = "netbsd",
127+
target_os = "openbsd"
128+
)
129+
),
95130
target_os = "windows"
96131
)))]
97132
fn proxy(&self) -> &EventLoopProxy<T> {
@@ -136,23 +171,29 @@ impl Adapter {
136171
Self { adapter }
137172
}
138173

139-
#[cfg(all(
140-
not(target_os = "linux"),
141-
not(target_os = "dragonfly"),
142-
not(target_os = "freebsd"),
143-
not(target_os = "netbsd"),
144-
not(target_os = "openbsd")
145-
))]
174+
#[cfg(not(all(
175+
feature = "accesskit_unix",
176+
any(
177+
target_os = "linux",
178+
target_os = "dragonfly",
179+
target_os = "freebsd",
180+
target_os = "netbsd",
181+
target_os = "openbsd"
182+
)
183+
)))]
146184
#[must_use]
147185
pub fn on_event(&self, _window: &Window, _event: &WindowEvent) -> bool {
148186
true
149187
}
150-
#[cfg(any(
151-
target_os = "linux",
152-
target_os = "dragonfly",
153-
target_os = "freebsd",
154-
target_os = "netbsd",
155-
target_os = "openbsd"
188+
#[cfg(all(
189+
feature = "accesskit_unix",
190+
any(
191+
target_os = "linux",
192+
target_os = "dragonfly",
193+
target_os = "freebsd",
194+
target_os = "netbsd",
195+
target_os = "openbsd"
196+
)
156197
))]
157198
#[must_use]
158199
pub fn on_event(&self, window: &Window, event: &WindowEvent) -> bool {

platforms/winit/src/platform_impl/mod.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,32 @@ mod platform;
1414
#[path = "macos.rs"]
1515
mod platform;
1616

17-
#[cfg(any(
18-
target_os = "linux",
19-
target_os = "dragonfly",
20-
target_os = "freebsd",
21-
target_os = "netbsd",
22-
target_os = "openbsd"
17+
#[cfg(all(
18+
feature = "accesskit_unix",
19+
any(
20+
target_os = "linux",
21+
target_os = "dragonfly",
22+
target_os = "freebsd",
23+
target_os = "netbsd",
24+
target_os = "openbsd"
25+
)
2326
))]
2427
#[path = "unix.rs"]
2528
mod platform;
2629

27-
#[cfg(all(
28-
not(target_os = "windows"),
29-
not(target_os = "macos"),
30-
not(target_os = "linux"),
31-
not(target_os = "dragonfly"),
32-
not(target_os = "freebsd"),
33-
not(target_os = "netbsd"),
34-
not(target_os = "openbsd")
35-
))]
30+
#[cfg(not(any(
31+
target_os = "windows",
32+
target_os = "macos",
33+
all(
34+
feature = "accesskit_unix",
35+
any(
36+
target_os = "linux",
37+
target_os = "dragonfly",
38+
target_os = "freebsd",
39+
target_os = "netbsd",
40+
target_os = "openbsd"
41+
)
42+
)
43+
)))]
3644
#[path = "null.rs"]
3745
mod platform;

0 commit comments

Comments
 (0)