Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Linux: default to XWayland for file drag-and-drop on Wayland desktops

Dylan M. Taylor0ed5fcd9389f
diff --git a/Cargo.lock b/Cargo.lock
index 0ad4ab843..097330a6c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2989,6 +2989,7 @@ dependencies = [
"muda",
"rfd",
"serde_json",
+ "winit",
"winresource",
]
diff --git a/apps/lightcraft/Cargo.toml b/apps/lightcraft/Cargo.toml
index e4d7f2b3b..169aaf43c 100644
--- a/apps/lightcraft/Cargo.toml
+++ b/apps/lightcraft/Cargo.toml
@@ -32,6 +32,9 @@ log = { workspace = true }
# Icon + VERSIONINFO for lightcraft.exe; build.rs only uses it when targeting Windows.
winresource = "0.1"
+[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
+winit = { version = "0.30", default-features = false, features = ["x11"] }
+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rfd = { workspace = true }
diff --git a/apps/lightcraft/src/main.rs b/apps/lightcraft/src/main.rs
index 00665e87e..f7cabfa17 100644
--- a/apps/lightcraft/src/main.rs
+++ b/apps/lightcraft/src/main.rs
@@ -754,6 +754,18 @@ fn main() -> eframe::Result {
};
// the app's copy: `log_file` is still named in the message of a start that fails
let app_log_file = log_file.clone();
+ #[cfg(all(unix, not(target_os = "macos")))]
+ let mut options = options;
+ // 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; LIGHTCRAFT_WAYLAND=1
+ // keeps the native Wayland backend.
+ #[cfg(all(unix, not(target_os = "macos")))]
+ if std::env::var_os("DISPLAY").is_some() && std::env::var_os("LIGHTCRAFT_WAYLAND").is_none() {
+ options.event_loop_builder = Some(Box::new(|b| {
+ use winit::platform::x11::EventLoopBuilderExtX11;
+ b.with_x11();
+ }));
+ }
let started = eframe::run_native(
"LightCraft",
options,