Skip to content

Commit 256bbe9

Browse files
authored
Move X11 backend to winit-x11 (#4253)
1 parent 1126e9e commit 256bbe9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+232
-227
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
/winit-wayland @kchibisov
1616

1717
# X11
18-
/src/platform/x11.rs @kchibisov @notgull
19-
/src/platform_impl/linux/x11 @kchibisov @notgull
18+
/winit-x11 @kchibisov @notgull
2019

2120
# Web
2221
/src/platform/web.rs @daxpedda

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ jobs:
210210
if: contains(matrix.platform.target, 'windows')
211211
run: cargo $CMD test -p winit-win32 --target=${{ matrix.platform.target }}
212212

213+
- name: Test winit X11
214+
if: contains(matrix.platform.target, 'linux-gnu')
215+
run: cargo $CMD test -p winit-x11 --target=${{ matrix.platform.target }}
216+
213217
- name: Test winit Wayland
214218
if: contains(matrix.platform.target, 'linux-gnu')
215219
run: cargo $CMD test -p winit-wayland --target=${{ matrix.platform.target }}

Cargo.toml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ winit-orbital = { version = "0.0.0", path = "winit-orbital" }
1919
winit-uikit = { version = "0.0.0", path = "winit-uikit" }
2020
winit-wayland = { version = "0.0.0", path = "winit-wayland", default-features = false }
2121
winit-win32 = { version = "0.0.0", path = "winit-win32" }
22+
winit-x11 = { version = "0.0.0", path = "winit-x11" }
2223

2324
# Core dependencies.
2425
bitflags = "2"
@@ -173,7 +174,7 @@ wayland-csd-adwaita = ["winit-wayland/csd-adwaita"]
173174
wayland-csd-adwaita-crossfont = ["winit-wayland/csd-adwaita-crossfont"]
174175
wayland-csd-adwaita-notitle = ["winit-wayland/csd-adwaita-notitle"]
175176
wayland-dlopen = ["winit-wayland/dlopen"]
176-
x11 = ["x11-dl", "bytemuck", "percent-encoding", "xkbcommon-dl/x11", "x11rb", "winit-common/x11"]
177+
x11 = ["dep:winit-x11"]
177178

178179
[build-dependencies]
179180
cfg_aliases.workspace = true
@@ -298,25 +299,11 @@ winit-win32.workspace = true
298299

299300
# Linux
300301
[target.'cfg(all(unix, not(any(target_os = "redox", target_family = "wasm", target_os = "android", target_vendor = "apple"))))'.dependencies]
301-
bytemuck = { workspace = true, optional = true }
302-
calloop.workspace = true
303302
libc.workspace = true
304-
percent-encoding = { workspace = true, optional = true }
305-
rustix = { workspace = true, features = ["std", "system", "thread", "process"] }
303+
rustix = { workspace = true, features = ["std", "thread"] }
306304
winit-common = { workspace = true, features = ["xkb"] }
307305
winit-wayland = { workspace = true, optional = true, default-features = false }
308-
x11-dl = { workspace = true, optional = true }
309-
x11rb = { workspace = true, optional = true, features = [
310-
"allow-unsafe-code",
311-
"cursor",
312-
"dl-libxcb",
313-
"randr",
314-
"resource_manager",
315-
"sync",
316-
"xinput",
317-
"xkb",
318-
] }
319-
xkbcommon-dl.workspace = true
306+
winit-x11 = { workspace = true, optional = true }
320307

321308
[target.'cfg(target_os = "redox")'.dependencies]
322309
winit-orbital.workspace = true

src/event_loop.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,29 @@ impl winit_win32::EventLoopBuilderExtWindows for EventLoopBuilder {
395395
}
396396
}
397397

398+
#[cfg(x11_platform)]
399+
impl winit_x11::EventLoopExtX11 for EventLoop {
400+
#[inline]
401+
fn is_x11(&self) -> bool {
402+
!self.event_loop.is_wayland()
403+
}
404+
}
405+
406+
#[cfg(x11_platform)]
407+
impl winit_x11::EventLoopBuilderExtX11 for EventLoopBuilder {
408+
#[inline]
409+
fn with_x11(&mut self) -> &mut Self {
410+
self.platform_specific.forced_backend = Some(crate::platform_impl::Backend::X);
411+
self
412+
}
413+
414+
#[inline]
415+
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
416+
self.platform_specific.any_thread = any_thread;
417+
self
418+
}
419+
}
420+
398421
/// ```compile_error
399422
/// use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand;
400423
/// use winit::event_loop::EventLoop;

src/platform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub mod web;
1919
#[cfg(windows_platform)]
2020
pub use winit_win32 as windows;
2121
#[cfg(x11_platform)]
22-
pub mod x11;
22+
pub use winit_x11 as x11;
2323

2424
#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, docsrs))]
2525
pub mod scancode;

src/platform/startup_notify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl WindowExtStartupNotify for dyn Window + '_ {
8080
}
8181

8282
#[cfg(x11_platform)]
83-
if let Some(window) = self.cast_ref::<crate::platform_impl::x11::window::Window>() {
83+
if let Some(window) = self.cast_ref::<crate::platform_impl::x11::Window>() {
8484
return window.request_activation_token();
8585
}
8686

src/platform_impl/linux/mod.rs

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@ use std::env;
77
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
88
use std::time::Duration;
99

10-
#[cfg(x11_platform)]
11-
use dpi::Size;
1210
pub(crate) use winit_common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey};
1311
use winit_core::application::ApplicationHandler;
1412
use winit_core::error::{EventLoopError, NotSupportedError};
1513
use winit_core::event_loop::pump_events::PumpStatus;
1614
use winit_core::event_loop::ActiveEventLoop;
17-
use winit_core::window::ActivationToken;
1815
#[cfg(wayland_platform)]
1916
pub(crate) use winit_wayland as wayland;
20-
21-
#[cfg(x11_platform)]
22-
use crate::platform::x11::WindowType as XWindowType;
2317
#[cfg(x11_platform)]
24-
pub(crate) mod x11;
18+
pub(crate) use winit_x11 as x11;
2519

2620
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2721
pub(crate) enum Backend {
@@ -37,59 +31,6 @@ pub(crate) struct PlatformSpecificEventLoopAttributes {
3731
pub(crate) any_thread: bool,
3832
}
3933

40-
#[derive(Debug, Clone, PartialEq, Eq)]
41-
pub struct ApplicationName {
42-
pub general: String,
43-
pub instance: String,
44-
}
45-
46-
impl ApplicationName {
47-
#[allow(dead_code)]
48-
pub fn new(general: String, instance: String) -> Self {
49-
Self { general, instance }
50-
}
51-
}
52-
53-
#[derive(Clone, Debug, PartialEq)]
54-
pub struct PlatformSpecificWindowAttributes {
55-
pub name: Option<ApplicationName>,
56-
pub activation_token: Option<ActivationToken>,
57-
#[cfg(x11_platform)]
58-
pub x11: X11WindowAttributes,
59-
}
60-
61-
#[derive(Clone, Debug, PartialEq)]
62-
#[cfg(x11_platform)]
63-
pub struct X11WindowAttributes {
64-
pub visual_id: Option<x11rb::protocol::xproto::Visualid>,
65-
pub screen_id: Option<i32>,
66-
pub base_size: Option<Size>,
67-
pub override_redirect: bool,
68-
pub x11_window_types: Vec<XWindowType>,
69-
70-
/// The parent window to embed this window into.
71-
pub embed_window: Option<x11rb::protocol::xproto::Window>,
72-
}
73-
74-
#[cfg_attr(not(x11_platform), allow(clippy::derivable_impls))]
75-
impl Default for PlatformSpecificWindowAttributes {
76-
fn default() -> Self {
77-
Self {
78-
name: None,
79-
activation_token: None,
80-
#[cfg(x11_platform)]
81-
x11: X11WindowAttributes {
82-
visual_id: None,
83-
screen_id: None,
84-
base_size: None,
85-
override_redirect: false,
86-
x11_window_types: vec![XWindowType::Normal],
87-
embed_window: None,
88-
},
89-
}
90-
}
91-
}
92-
9334
/// `x11_or_wayland!(match expr; Enum(foo) => foo.something())`
9435
/// expands to the equivalent of
9536
/// ```ignore
@@ -242,14 +183,6 @@ impl AsRawFd for EventLoop {
242183
}
243184
}
244185

245-
/// Returns the minimum `Option<Duration>`, taking into account that `None`
246-
/// equates to an infinite timeout, not a zero timeout (so can't just use
247-
/// `Option::min`)
248-
#[allow(dead_code)]
249-
fn min_timeout(a: Option<Duration>, b: Option<Duration>) -> Option<Duration> {
250-
a.map_or(b, |a_timeout| b.map_or(Some(a_timeout), |b_timeout| Some(a_timeout.min(b_timeout))))
251-
}
252-
253186
#[cfg(target_os = "linux")]
254187
fn is_main_thread() -> bool {
255188
rustix::thread::gettid() == rustix::process::getpid()

winit-x11/Cargo.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[package]
2+
description = "Winit's X11 backend"
3+
documentation = "https://docs.rs/winit-x11"
4+
edition.workspace = true
5+
license.workspace = true
6+
name = "winit-x11"
7+
repository.workspace = true
8+
rust-version.workspace = true
9+
version = "0.0.0"
10+
11+
[features]
12+
serde = ["dep:serde", "bitflags/serde", "smol_str/serde", "dpi/serde"]
13+
14+
[dependencies]
15+
bitflags.workspace = true
16+
cursor-icon.workspace = true
17+
dpi.workspace = true
18+
rwh_06.workspace = true
19+
serde = { workspace = true, optional = true }
20+
smol_str.workspace = true
21+
tracing.workspace = true
22+
winit-core.workspace = true
23+
24+
# Platform-specific
25+
bytemuck.workspace = true
26+
calloop.workspace = true
27+
libc.workspace = true
28+
percent-encoding.workspace = true
29+
rustix = { workspace = true, features = ["std", "system", "thread", "process"] }
30+
winit-common = { workspace = true, features = ["xkb", "x11"] }
31+
x11-dl.workspace = true
32+
x11rb = { workspace = true, features = [
33+
"allow-unsafe-code",
34+
"cursor",
35+
"dl-libxcb",
36+
"randr",
37+
"resource_manager",
38+
"sync",
39+
"xinput",
40+
"xkb",
41+
] }
42+
xkbcommon-dl = { workspace = true, features = ["x11"] }
43+
44+
[dev-dependencies]
45+
winit.workspace = true
46+
47+
[package.metadata.docs.rs]
48+
all-features = true

winit-x11/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use std::fmt::Write;
1010

1111
use x11rb::protocol::xproto::{self, ConnectionExt as _};
1212

13-
use super::atoms::*;
14-
use super::{VoidCookie, X11Error, XConnection};
13+
use crate::atoms::*;
14+
use crate::event_loop::{VoidCookie, X11Error};
15+
use crate::xdisplay::XConnection;
1516

1617
impl XConnection {
1718
/// "Request" a new activation token from the server.

0 commit comments

Comments
 (0)