From e26002d230ed7be816860a36bccbb39ea14b8ef2 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 25 Nov 2026 16:49:07 +0100 Subject: [PATCH 1/2] Open the window through Xwayland for a pen on Wayland winit 0.30 doesn't bind the Wayland tablet protocol, so on compositors that don't emulate a pointer for the pen (KWin) the pen did nothing in the window. With a pen attached on a Wayland desktop, and Xwayland able to run the window, the app now opens on X11, where the pen works as the pointer. TEXTURECRAFT_NATIVE_WAYLAND=1 keeps native Wayland. Adapted from PhotoCraft. Fixes #816. --- ATTRIBUTION.md | 1 + apps/texturecraft/Cargo.toml | 5 + apps/texturecraft/src/main.rs | 10 ++ apps/texturecraft/src/xwayland_pen.rs | 150 ++++++++++++++++++++++++++ docs/features.md | 3 + 5 files changed, 169 insertions(+) create mode 100644 apps/texturecraft/src/xwayland_pen.rs diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index a136498a..1cf696d9 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -26,6 +26,7 @@ licensed and keep their license file next to them. | `assets/hdr/studio_small_09_512.hdr` | Studio Small 09: a small photo studio with octaboxes on a white infinity cyc, equirect HDR reduced to 512×256 (2×2 box filter, Radiance RLE); lights the Properties panel's material orbs | Sergej Majboroda (Poly Haven) | [Poly Haven release](https://polyhaven.com/a/studio_small_09), [1K Radiance HDR](https://dl.polyhaven.org/file/ph-assets/HDRIs/hdr/1k/studio_small_09_1k.hdr) (MD5 `d5d7eb9d26d341d6aa4d11c1a54fd97c`) | [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/) | | `docs/brand/artcraft-*.svg`, `docs/brand/artcraft-*.png` | ArtCraft logo and mark | ArtCraft Team | storytold/craftrules `assets/brand/` | ArtCraft brand terms, not open source ([`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt)) | | `crates/formats/src/mesh_import/usd/fixtures/crafted-references.usdc` | Synthetic USDC class/reference/time-sample acceptance fixture | ArtCraft Team and craft-libs contributors | [Pinned generator and provenance](crates/formats/src/mesh_import/usd/fixtures/README.md) | MIT (`crates/formats/src/mesh_import/usd/fixtures/LICENSE-MIT`) | +| `apps/texturecraft/src/xwayland_pen.rs` | Pen on Wayland opens the window through Xwayland: pen detection, the Xwayland decision and the X11 library check (adapted, reduced to the pen decision) | PhotoCraft contributors | storytold/photocraft `830316b775f1f6734498ac6e39fd1298955ff93f`: [`apps/photocraft/src/tablet.rs`](https://github.com/storytold/photocraft/blob/830316b775f1f6734498ac6e39fd1298955ff93f/apps/photocraft/src/tablet.rs), [`apps/photocraft/src/linux_libs.rs`](https://github.com/storytold/photocraft/blob/830316b775f1f6734498ac6e39fd1298955ff93f/apps/photocraft/src/linux_libs.rs) | MIT OR Apache-2.0 | ## Third-party assets compiled into the binary diff --git a/apps/texturecraft/Cargo.toml b/apps/texturecraft/Cargo.toml index 7f5ee538..39fb3c7c 100644 --- a/apps/texturecraft/Cargo.toml +++ b/apps/texturecraft/Cargo.toml @@ -35,6 +35,11 @@ winsafe = { version = "0.0.29", default-features = false, features = ["user", "s # The update helper is a copy of this program (`main`). craft-update = { workspace = true } +# Opening the window through Xwayland for a pen on Wayland (src/xwayland_pen.rs): winit's +# `EventLoopBuilderExtX11`. Already in Cargo.lock through eframe. +[target.'cfg(target_os = "linux")'.dependencies] +winit = { version = "0.30", default-features = false, features = ["x11"] } + # Quit (Cmd+Q) asks about unsaved changes (src/main.rs); winit's own Quit does not. [target.'cfg(target_os = "macos")'.dependencies] craft-menu = { workspace = true } diff --git a/apps/texturecraft/src/main.rs b/apps/texturecraft/src/main.rs index 349b9275..e7bf7a7b 100644 --- a/apps/texturecraft/src/main.rs +++ b/apps/texturecraft/src/main.rs @@ -15,6 +15,8 @@ mod nightly_session; mod process_identity; mod profile_root; mod window_frame; +#[cfg(target_os = "linux")] +mod xwayland_pen; use std::ffi::OsString; @@ -398,6 +400,14 @@ fn main() { } let viewport = title_bar.viewport(viewport); let mut options = eframe::NativeOptions { viewport, renderer: eframe::Renderer::Wgpu, persistence_path, ..Default::default() }; + // winit picks Wayland whenever `WAYLAND_DISPLAY` is set; a pen works only through Xwayland there + #[cfg(target_os = "linux")] + if xwayland_pen::opens_through_xwayland() { + use winit::platform::x11::EventLoopBuilderExtX11 as _; + options.event_loop_builder = Some(Box::new(|builder| { + builder.with_x11(); + })); + } if let Err(e) = gpu::configure(&mut options, args.gpu, args.power_pref) { fatal(&e.to_string(), true); std::process::exit(2); diff --git a/apps/texturecraft/src/xwayland_pen.rs b/apps/texturecraft/src/xwayland_pen.rs new file mode 100644 index 00000000..6c3f7d3a --- /dev/null +++ b/apps/texturecraft/src/xwayland_pen.rs @@ -0,0 +1,150 @@ +//! A pen on a Wayland desktop opens the window through Xwayland (#816). +//! +//! Wayland compositors give a pen only to clients that bind the tablet protocol (`zwp_tablet_v2`), +//! which winit 0.30 doesn't (and binding it on winit's connection needs `unsafe`, which this app +//! forbids). Some compositors (KWin) then send the window nothing from the pen: no cursor, no +//! painting. Xwayland binds the protocol and serves the pen as an X11 pointer, so with a pen +//! attached the window opens there. `TEXTURECRAFT_NATIVE_WAYLAND=1` keeps native Wayland. +//! +//! Adapted from PhotoCraft (storytold/photocraft `830316b7`, MIT OR Apache-2.0): +//! `apps/photocraft/src/tablet.rs` (`display_session`, `pen_needs_xwayland`, `has_pen`, `bit_set`) +//! and `apps/photocraft/src/linux_libs.rs` (`session_from_env`, `ldconfig_has`, the library +//! search), reduced to the pen decision. Replace it with a shared craft-libs crate once one exists +//! (AGENTS.md rule 9). + +use std::path::{Path, PathBuf}; + +/// Set (and not `0`) to keep native Wayland with a pen attached +const NATIVE_WAYLAND_VARIABLE: &str = "TEXTURECRAFT_NATIVE_WAYLAND"; + +/// `BTN_TOOL_PEN` (linux/input-event-codes.h): the key a tablet's stylus, a pen display's or a +/// pen-enabled touchscreen's pen reports +const BTN_TOOL_PEN: u32 = 0x140; + +/// `ABS_X` and `ABS_Y` (linux/input-event-codes.h): the absolute axes every pen reports +const ABS_X: u32 = 0x00; +const ABS_Y: u32 = 0x01; + +/// What winit 0.30 loads at run time for an X11 window: Xlib, Xlib-xcb, xcb, Xcursor, XInput2 and +/// xkbcommon with its X11 part +const X11_LIBRARIES: &[&str] = + &["libX11.so.6", "libX11-xcb.so.1", "libxcb.so.1", "libXcursor.so.1", "libXi.so.6", "libxkbcommon.so.0", "libxkbcommon-x11.so.0"]; + +/// Whether the window opens through Xwayland: a pen is attached on a Wayland desktop and Xwayland +/// can run the window. Says so on stderr when it does. +pub fn opens_through_xwayland() -> bool { + let var = |name: &str| std::env::var(name).ok(); + let pen = || std::fs::read_to_string("/proc/bus/input/devices").is_ok_and(|devices| has_pen(&devices)); + if !pen_needs_xwayland(var, pen, x11_libraries_available) { + return false; + } + + eprintln!("texturecraft: opening the window through Xwayland for the pen ({NATIVE_WAYLAND_VARIABLE}=1 keeps Wayland)"); + true +} + +/// [`opens_through_xwayland`]'s decision. winit picks Wayland when `WAYLAND_DISPLAY` or +/// `WAYLAND_SOCKET` is set; Xwayland needs `DISPLAY`. The system probes run only on Wayland. +fn pen_needs_xwayland(var: impl Fn(&str) -> Option, pen: impl FnOnce() -> bool, x11_libraries: impl FnOnce() -> bool) -> bool { + let set = |name: &str| var(name).is_some_and(|value| !value.is_empty()); + let wayland = set("WAYLAND_DISPLAY") || set("WAYLAND_SOCKET"); + let keeps_wayland = var(NATIVE_WAYLAND_VARIABLE).is_some_and(|value| !value.is_empty() && value != "0"); + wayland && !keeps_wayland && set("DISPLAY") && pen() && x11_libraries() +} + +/// Is a pen among the input devices `/proc/bus/input/devices` lists? A pen's `B: KEY=` bitmap has +/// `BTN_TOOL_PEN` and its `B: ABS=` bitmap has `ABS_X` and `ABS_Y`, as libinput asks of a tablet +/// tool. The key alone isn't enough: a virtual keyboard made with uinput claims every key code. +fn has_pen(devices: &str) -> bool { + devices.split("\n\n").any(|device| { + let bitmap = |name: &str| device.lines().find_map(|line| line.strip_prefix(name)); + bitmap("B: KEY=").is_some_and(|keys| bit_set(keys, BTN_TOOL_PEN)) && bitmap("B: ABS=").is_some_and(|axes| bit_set(axes, ABS_X) && bit_set(axes, ABS_Y)) + }) +} + +/// Bit `bit` of a `/proc/bus/input/devices` bitmap: hex words of the kernel's `long`, most +/// significant first. Short or malformed bitmaps have no bits set. +fn bit_set(bitmap: &str, bit: u32) -> bool { + let word_bits = usize::BITS; + let word = usize::try_from(bit / word_bits).unwrap_or(usize::MAX); + bitmap.split_whitespace().rev().nth(word).and_then(|hex| u64::from_str_radix(hex, 16).ok()).is_some_and(|value| (value >> (bit % word_bits)) & 1 == 1) +} + +/// Are the libraries an X11 window needs installed? The linker cache (`ldconfig -p`) or the usual +/// library directories must list each; one that can't be found counts as missing. +fn x11_libraries_available() -> bool { + let cache = linker_cache(); + let dirs = library_dirs(std::env::var("LD_LIBRARY_PATH").ok().as_deref()); + X11_LIBRARIES.iter().all(|soname| cache.as_deref().is_some_and(|cache| ldconfig_has(cache, soname)) || dirs.iter().any(|dir| dir.join(soname).exists())) +} + +/// `ldconfig -p` in English (it is parsed), from where distributions put it +fn linker_cache() -> Option { + ["/sbin/ldconfig", "/usr/sbin/ldconfig", "ldconfig"].into_iter().find_map(|command| { + let output = std::process::Command::new(command).arg("-p").env("LC_ALL", "C").output().ok()?; + output.status.success().then(|| String::from_utf8_lossy(&output.stdout).into_owned()) + }) +} + +/// Does an `ldconfig -p` listing have `soname` for this build's architecture? Lines look like +/// `\tlibXi.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libXi.so.6`. +fn ldconfig_has(cache: &str, soname: &str) -> bool { + let architecture = if cfg!(target_arch = "x86_64") { + Some("x86-64") + } else if cfg!(target_arch = "aarch64") { + Some("AArch64") + } else { + None + }; + + cache.lines().any(|line| { + let Some((name, rest)) = line.trim_start().split_once(' ') else { return false }; + let flags = rest.split_once('(').and_then(|(_, after)| after.split_once(')')).map_or("", |(flags, _)| flags); + name == soname && architecture.is_none_or(|tag| flags.split(',').any(|flag| flag.trim() == tag)) + }) +} + +/// `LD_LIBRARY_PATH`, then the usual system and Flatpak library directories +fn library_dirs(ld_library_path: Option<&str>) -> Vec { + let triplet = if cfg!(target_arch = "aarch64") { "aarch64-linux-gnu" } else { "x86_64-linux-gnu" }; + let mut dirs: Vec = ld_library_path.into_iter().flat_map(|value| value.split(':')).filter(|dir| !dir.is_empty()).map(PathBuf::from).collect(); + dirs.extend(["/app/lib", "/usr/local/lib", "/usr/lib64", "/lib64", "/usr/lib", "/lib"].map(PathBuf::from)); + dirs.extend([Path::new("/usr/lib").join(triplet), Path::new("/lib").join(triplet)]); + dirs +} + +#[cfg(test)] +mod tests { + use super::*; + + /// A touchpad (`BTN_TOOL_FINGER`, no pen) and a Wacom pen, from `/proc/bus/input/devices` + const TOUCHPAD: &str = "N: Name=\"SYNA2B33:00 06CB:CE26 Touchpad\"\nB: KEY=e520 10000 0 0 0 0\nB: ABS=2e0800000000003\n"; + const PEN: &str = "N: Name=\"Wacom Intuos Pro M Pen\"\nB: KEY=1c03 0 0 0 0 0\nB: ABS=1000f000003\n"; + + /// A uinput keyboard (RustDesk's) claims every key, `BTN_TOOL_PEN` included, with no axes + const VIRTUAL_KEYBOARD: &str = "N: Name=\"RustDesk UInput Keyboard\"\nB: EV=20013\nB: KEY=ffffffffff 0 7ffffff000301ff 1000f7fffffff 7fe001fffff000f 7ffffffffffffff ffffffff0003fdff 7fff8fff00ff03ff 1ffffffffffff07 ffffffffffffffff ffffffffffefffff fffffffffffffffe\n"; + + #[test] + fn a_pen_is_a_device_with_the_pen_key_and_absolute_axes() { + assert!(has_pen(&format!("{TOUCHPAD}\n{PEN}"))); + assert!(!has_pen(TOUCHPAD), "a touchpad is no pen"); + assert!(!has_pen(&format!("{VIRTUAL_KEYBOARD}\n{TOUCHPAD}")), "a keyboard claiming the pen key has no pen axes"); + assert!(!has_pen("B: KEY=zz 0 0 0 0 0\nB: ABS=3\n"), "a malformed bitmap is no pen"); + } + + #[test] + fn a_pen_on_wayland_opens_the_window_through_xwayland() { + fn env(pairs: &'static [(&'static str, &'static str)]) -> impl Fn(&str) -> Option { + move |name: &str| pairs.iter().find(|(key, _)| *key == name).map(|(_, value)| value.to_string()) + } + const WAYLAND: &[(&str, &str)] = &[("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0")]; + + assert!(pen_needs_xwayland(env(WAYLAND), || true, || true)); + assert!(!pen_needs_xwayland(env(WAYLAND), || false, || true), "no pen"); + assert!(!pen_needs_xwayland(env(WAYLAND), || true, || false), "no X11 libraries"); + assert!(!pen_needs_xwayland(env(&[("WAYLAND_DISPLAY", "wayland-0")]), || true, || true), "no Xwayland"); + assert!(!pen_needs_xwayland(env(&[("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0"), (NATIVE_WAYLAND_VARIABLE, "1")]), || true, || true), "kept"); + assert!(pen_needs_xwayland(env(&[("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0"), (NATIVE_WAYLAND_VARIABLE, "0")]), || true, || true)); + assert!(!pen_needs_xwayland(env(&[("DISPLAY", ":0")]), || panic!("probed off Wayland"), || panic!("probed off Wayland")), "X11 already has the pen"); + } +} diff --git a/docs/features.md b/docs/features.md index 42ea07a6..e08582dc 100644 --- a/docs/features.md +++ b/docs/features.md @@ -255,6 +255,9 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA - **Its own title bar** with the app icon, menus and window buttons on Windows (and on Linux desktops that leave the frame to the app, such as GNOME), the macOS traffic lights over the same strip, and Settings › General › Appearance › System title bar for the system's frame instead. +- **A pen on a Linux Wayland desktop** opens the window through Xwayland, where the pen moves the + cursor and paints (some compositors send a pen nothing in a native Wayland window); + `TEXTURECRAFT_NATIVE_WAYLAND=1` keeps native Wayland. - **Dockable, tabbed and floating panels**, saved layouts, and panels that reopen where you closed them. The right bar's panels (Export, Log, Display Settings, Shader Settings, History) pop out beside it; *Undock* makes one a floating window, and its *Dock* button puts it back on the bar. From c54e1eb75eed104d6bb7c9db42e31705ee2c18c1 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 26 Nov 2026 21:58:59 +0100 Subject: [PATCH 2/2] Xwayland for the pen only when its X server answers; hand the chosen backend to the title bar and UI runtime A DISPLAY left over from another session could force X11 with no X server to connect to, and winit can't fall back to Wayland then. The title bar decision and the UI runtime read the backend from the environment and saw Wayland while the window opened on Xwayland. --- Cargo.lock | 1 + apps/texturecraft/Cargo.toml | 2 ++ apps/texturecraft/src/main.rs | 13 +++++++---- apps/texturecraft/src/xwayland_pen.rs | 31 ++++++++++++++++++++++----- crates/ui-egui/src/framework.rs | 6 +++--- crates/ui-egui/src/titlebar.rs | 6 +++--- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index acafef1d..a80cac9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5819,6 +5819,7 @@ dependencies = [ name = "texturecraft" version = "0.6.1" dependencies = [ + "craft-host", "craft-image-codecs", "craft-menu", "craft-update", diff --git a/apps/texturecraft/Cargo.toml b/apps/texturecraft/Cargo.toml index 39fb3c7c..52626627 100644 --- a/apps/texturecraft/Cargo.toml +++ b/apps/texturecraft/Cargo.toml @@ -23,6 +23,8 @@ serde_json = { workspace = true } log = { workspace = true } # The message box for errors that end the app (a Windows release build has no console). rfd = { workspace = true } +# The window's backend (Xwayland for a pen, src/xwayland_pen.rs) for the title bar and the UI runtime. +craft-host = { workspace = true } # Reads the saved System title bar setting before the window opens (eframe's settings format). ron = "0.12" diff --git a/apps/texturecraft/src/main.rs b/apps/texturecraft/src/main.rs index d0c26efc..04d3b23a 100644 --- a/apps/texturecraft/src/main.rs +++ b/apps/texturecraft/src/main.rs @@ -395,7 +395,13 @@ fn main() { prefs.apply_work_threads(); prefs.apply_resource_limits(); let session = initial_session(&args); - let frame_decision = TitleBar::decide(prefs.system_title_bar); + // winit picks Wayland whenever `WAYLAND_DISPLAY` is set; a pen works only through Xwayland there + #[cfg(target_os = "linux")] + let pen_needs_x11 = xwayland_pen::opens_through_xwayland(); + #[cfg(not(target_os = "linux"))] + let pen_needs_x11 = false; + let backend = if pen_needs_x11 { craft_host::target::Backend::X11 } else { craft_host::target::Backend::from_env() }; + let frame_decision = TitleBar::decide(prefs.system_title_bar, backend); let title_bar = TitleBar::of(&frame_decision.frame); let mut viewport = egui::ViewportBuilder::default() .with_app_id(os_window::app_id()) @@ -407,9 +413,8 @@ fn main() { } let viewport = texturecraft_ui_egui::titlebar::viewport(&frame_decision, viewport); let mut options = eframe::NativeOptions { viewport, renderer: eframe::Renderer::Wgpu, persistence_path, ..Default::default() }; - // winit picks Wayland whenever `WAYLAND_DISPLAY` is set; a pen works only through Xwayland there #[cfg(target_os = "linux")] - if xwayland_pen::opens_through_xwayland() { + if pen_needs_x11 { use winit::platform::x11::EventLoopBuilderExtX11 as _; options.event_loop_builder = Some(Box::new(|builder| { builder.with_x11(); @@ -460,7 +465,7 @@ fn main() { if let Err(e) = craft_menu::mac::install_app_menu(&cc.egui_ctx, window_name) { log::warn!("the app menu could not be installed: {e}"); } - texturecraft_ui_egui::framework::install(&cc.egui_ctx, frame_decision)?; + texturecraft_ui_egui::framework::install(&cc.egui_ctx, frame_decision, backend)?; let frame_guard = window_frame::service(cc, matches!(title_bar, TitleBar::App(_))); let mut app = TextureCraftApp::new(cc, session); app.title_bar = title_bar; diff --git a/apps/texturecraft/src/xwayland_pen.rs b/apps/texturecraft/src/xwayland_pen.rs index 6c3f7d3a..10d44314 100644 --- a/apps/texturecraft/src/xwayland_pen.rs +++ b/apps/texturecraft/src/xwayland_pen.rs @@ -31,11 +31,13 @@ const X11_LIBRARIES: &[&str] = &["libX11.so.6", "libX11-xcb.so.1", "libxcb.so.1", "libXcursor.so.1", "libXi.so.6", "libxkbcommon.so.0", "libxkbcommon-x11.so.0"]; /// Whether the window opens through Xwayland: a pen is attached on a Wayland desktop and Xwayland -/// can run the window. Says so on stderr when it does. +/// can run the window (the X11 libraries are installed and the X server answers). Says so on +/// stderr when it does. pub fn opens_through_xwayland() -> bool { let var = |name: &str| std::env::var(name).ok(); let pen = || std::fs::read_to_string("/proc/bus/input/devices").is_ok_and(|devices| has_pen(&devices)); - if !pen_needs_xwayland(var, pen, x11_libraries_available) { + let xwayland_ready = || x11_libraries_available() && var("DISPLAY").is_some_and(|display| x_server_answers(&display)); + if !pen_needs_xwayland(var, pen, xwayland_ready) { return false; } @@ -45,11 +47,29 @@ pub fn opens_through_xwayland() -> bool { /// [`opens_through_xwayland`]'s decision. winit picks Wayland when `WAYLAND_DISPLAY` or /// `WAYLAND_SOCKET` is set; Xwayland needs `DISPLAY`. The system probes run only on Wayland. -fn pen_needs_xwayland(var: impl Fn(&str) -> Option, pen: impl FnOnce() -> bool, x11_libraries: impl FnOnce() -> bool) -> bool { +fn pen_needs_xwayland(var: impl Fn(&str) -> Option, pen: impl FnOnce() -> bool, xwayland_ready: impl FnOnce() -> bool) -> bool { let set = |name: &str| var(name).is_some_and(|value| !value.is_empty()); let wayland = set("WAYLAND_DISPLAY") || set("WAYLAND_SOCKET"); let keeps_wayland = var(NATIVE_WAYLAND_VARIABLE).is_some_and(|value| !value.is_empty() && value != "0"); - wayland && !keeps_wayland && set("DISPLAY") && pen() && x11_libraries() + wayland && !keeps_wayland && set("DISPLAY") && pen() && xwayland_ready() +} + +/// Does the X server `display` names accept a connection? winit can't fall back to Wayland once +/// X11 is chosen, so a `DISPLAY` left over from another session must keep the window on Wayland. +/// Only a local display is tried, by its socket path or the abstract socket of the same name. +fn x_server_answers(display: &str) -> bool { + use std::os::linux::net::SocketAddrExt as _; + use std::os::unix::net::{SocketAddr, UnixStream}; + + let Some(socket) = local_x_socket(display) else { return false }; + UnixStream::connect(&socket).is_ok() || SocketAddr::from_abstract_name(socket.as_bytes()).and_then(|address| UnixStream::connect_addr(&address)).is_ok() +} + +/// The socket of a local X display (`:0`, `:0.0`, `unix:0`); `None` for a remote one +fn local_x_socket(display: &str) -> Option { + let number = display.strip_prefix(':').or_else(|| display.strip_prefix("unix:"))?; + let number: u32 = number.split('.').next()?.parse().ok()?; + Some(format!("/tmp/.X11-unix/X{number}")) } /// Is a pen among the input devices `/proc/bus/input/devices` lists? A pen's `B: KEY=` bitmap has @@ -141,10 +161,11 @@ mod tests { assert!(pen_needs_xwayland(env(WAYLAND), || true, || true)); assert!(!pen_needs_xwayland(env(WAYLAND), || false, || true), "no pen"); - assert!(!pen_needs_xwayland(env(WAYLAND), || true, || false), "no X11 libraries"); + assert!(!pen_needs_xwayland(env(WAYLAND), || true, || false), "Xwayland can't run the window"); assert!(!pen_needs_xwayland(env(&[("WAYLAND_DISPLAY", "wayland-0")]), || true, || true), "no Xwayland"); assert!(!pen_needs_xwayland(env(&[("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0"), (NATIVE_WAYLAND_VARIABLE, "1")]), || true, || true), "kept"); assert!(pen_needs_xwayland(env(&[("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0"), (NATIVE_WAYLAND_VARIABLE, "0")]), || true, || true)); assert!(!pen_needs_xwayland(env(&[("DISPLAY", ":0")]), || panic!("probed off Wayland"), || panic!("probed off Wayland")), "X11 already has the pen"); + assert_eq!([":1.0", "unix:0", "remote:0"].map(local_x_socket), [Some("/tmp/.X11-unix/X1".into()), Some("/tmp/.X11-unix/X0".into()), None]); } } diff --git a/crates/ui-egui/src/framework.rs b/crates/ui-egui/src/framework.rs index 187d0de6..f617d398 100644 --- a/crates/ui-egui/src/framework.rs +++ b/crates/ui-egui/src/framework.rs @@ -52,10 +52,10 @@ fn install_with(ctx: &egui::Context, shell: ShellInfo, windows: Arc Result<(), String> { - let shell = ShellInfo::default().backend(craft_host::target::Backend::from_env()); +pub fn install(ctx: &egui::Context, frame: Decision, backend: craft_host::target::Backend) -> Result<(), String> { + let shell = ShellInfo::default().backend(backend); install_with(ctx, shell, Arc::new(craft_window::system::SystemWindows), Some(frame)) } diff --git a/crates/ui-egui/src/titlebar.rs b/crates/ui-egui/src/titlebar.rs index 024675b1..5817e7a8 100644 --- a/crates/ui-egui/src/titlebar.rs +++ b/crates/ui-egui/src/titlebar.rs @@ -68,12 +68,12 @@ const NIGHTLY_ICONS: [(f32, &[u8]); 5] = [ impl TitleBar { /// Decide who draws the title bar; call once at startup, before the window is created, and /// hand the decision to the window ([`viewport`]) and the runtime (`framework::install`). - /// `system` is Settings › Interface › System title bar. - pub fn decide(system: bool) -> Decision { + /// `system` is Settings › Interface › System title bar; `backend` is the one the window opens on. + pub fn decide(system: bool, backend: craft_host::target::Backend) -> Decision { let choice = craft_window::Choice::probe(PREFIX); let wanted = Self::from_choice(choice.frame(), choice.overridden(), system); let pref = if wanted == TitleBar::System { TitleBarPref::System } else { TitleBarPref::Integrated }; - craft_window::policy::decide_for(PREFIX, craft_host::target::Backend::from_env(), pref) + craft_window::policy::decide_for(PREFIX, backend, pref) } /// The bar a decided `frame` gives.