From 326d6953353c0044eca1227260ce326c924d2d06 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 12 Oct 2026 04:49:37 -0400 Subject: [PATCH] Linux: default to XWayland for file drag-and-drop on Wayland desktops (#220) Co-authored-by: Brandon Thomas Co-authored-by: Claude Opus 5.5 --- Cargo.lock | 1 + README.md | 12 +++++++++--- apps/wordcraft/Cargo.toml | 1 + apps/wordcraft/src/main.rs | 10 ++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36f1a7cec..69ccefe16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5014,6 +5014,7 @@ dependencies = [ "rfd", "serde_json", "windows", + "winit", "winresource", "wordcraft-control-key", "wordcraft-doc", diff --git a/README.md b/README.md index 3df7194f8..d7a4bf720 100644 --- a/README.md +++ b/README.md @@ -267,17 +267,23 @@ instead, without setting anything. The log file records the choice (lines starti RISC-V (riscv64): `wordcraft--linux-riscv64.tar.gz`, a tarball cross-compiled for glibc 2.39+ (Ubuntu 24.04, Debian 13 and newer). +**Wayland:** on a Wayland desktop the app runs through XWayland when it is available, because +winit (the windowing library) supports dragging files into the window only on X11. To use the +native Wayland backend instead (for example for sharper text with fractional scaling, at the cost +of file drag-and-drop), start it with `WORDCRAFT_WAYLAND=1`: + +```sh +WORDCRAFT_WAYLAND=1 wordcraft +``` + **Arch Linux (AUR).** Community members maintain three AUR packages; the project doesn't publish to the AUR itself. Install one of them: - | Package | What it installs | Choose it when | |---|---|---| | [`wordcraft-bin`](https://aur.archlinux.org/packages/wordcraft-bin) | The release tarball above, prebuilt (x86_64, aarch64) | You want the latest release without compiling (quickest) | | [`wordcraft`](https://aur.archlinux.org/packages/wordcraft) | The latest release, built from source with `cargo` | You prefer to build releases yourself | | [`wordcraft-git`](https://aur.archlinux.org/packages/wordcraft-git) | The current `main` branch, built from source | You want unreleased changes and accept an occasional broken build | - For example `yay -S wordcraft-bin` or `paru -S wordcraft-bin`. - ### FreeBSD | Build | File | diff --git a/apps/wordcraft/Cargo.toml b/apps/wordcraft/Cargo.toml index d41277f43..7e02415bd 100644 --- a/apps/wordcraft/Cargo.toml +++ b/apps/wordcraft/Cargo.toml @@ -43,6 +43,7 @@ objc2 = "0.6" dispatch2 = "0.3" [target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] +winit = { version = "0.30", default-features = false, features = ["x11"] } # The desktop's animation setting on Linux and the BSDs, read from the XDG settings portal over # D-Bus. Already in the build through AccessKit, at this version; this adds only its blocking API. zbus = { version = "5", default-features = false, features = ["async-io", "blocking-api"] } diff --git a/apps/wordcraft/src/main.rs b/apps/wordcraft/src/main.rs index a4c1a5d80..38ff25eaf 100644 --- a/apps/wordcraft/src/main.rs +++ b/apps/wordcraft/src/main.rs @@ -277,6 +277,16 @@ fn main() -> eframe::Result { if let Some(window) = restored { options.viewport = window.apply(options.viewport); } + #[cfg(all(unix, not(target_os = "macos")))] + // winit has no file drag-and-drop on Wayland (only on X11), so dropping files from the file + // manager showed a "no" cursor. Run through XWayland when it's there; WORDCRAFT_WAYLAND=1 + // keeps the native Wayland backend. + if std::env::var_os("DISPLAY").is_some() && std::env::var_os("WORDCRAFT_WAYLAND").is_none() { + options.event_loop_builder = Some(Box::new(|b| { + use winit::platform::x11::EventLoopBuilderExtX11; + b.with_x11(); + })); + } // Registered before the event loop starts, so it catches the Finder event that launched us as // well as later ones. Lives until the event loop returns; the app creator only borrows it. #[cfg(target_os = "macos")]