From 56035e1f13c607afa5435b79a359917b79a7fc5d Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 7 Feb 2024 06:41:23 +0400 Subject: [PATCH] Account for WAYLAND_SOCKET when detecting Wayland Fixes #3459. --- CHANGELOG.md | 1 + src/platform_impl/linux/mod.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db0cbab1d..824a5e7c9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Unreleased` header. - On Wayland, fix `Focused(false)` being send when other seats still have window focused. - On Wayland, fix `Window::set_{min,max}_inner_size` not always applied. - On Windows, fix inconsistent resizing behavior with multi-monitor setups when repositioning outside the event loop. +- On Wayland, fix `WAYLAND_SOCKET` not used when detecting platform. # 0.29.10 diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 4589eb4d67..c99c1c276c 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -750,8 +750,11 @@ impl EventLoop { let backend = match ( attributes.forced_backend, env::var("WAYLAND_DISPLAY") - .map(|var| !var.is_empty()) - .unwrap_or(false), + .ok() + .filter(|var| !var.is_empty()) + .or_else(|| env::var("WAYLAND_SOCKET").ok()) + .filter(|var| !var.is_empty()) + .is_some(), env::var("DISPLAY") .map(|var| !var.is_empty()) .unwrap_or(false), @@ -769,9 +772,9 @@ impl EventLoop { let msg = if wayland_display && !cfg!(wayland_platform) { "DISPLAY is not set; note: enable the `winit/wayland` feature to support Wayland" } else if x11_display && !cfg!(x11_platform) { - "WAYLAND_DISPLAY is not set; note: enable the `winit/x11` feature to support X11" + "neither WAYLAND_DISPLAY nor WAYLAND_SOCKET is set; note: enable the `winit/x11` feature to support X11" } else { - "neither WAYLAND_DISPLAY nor DISPLAY is set." + "neither WAYLAND_DISPLAY nor WAYLAND_SOCKET nor DISPLAY is set." }; return Err(EventLoopError::Os(os_error!(OsError::Misc(msg)))); }