diff --git a/CHANGELOG.md b/CHANGELOG.md index ca8bd4a1..dd2cabb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Web, remove any fullscreen requests from the queue when an external fullscreen activation was detected. - On Wayland, fix `TouchPhase::Canceled` being sent for moved events. - Mark `startup_notify` unsafe functions as safe. +- Fix a bug where Wayland would be chosen on Linux even if the user specified `with_x11`. (#3058) # 0.29.1-beta diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 9eb15c8f..4590d5c4 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -716,21 +716,34 @@ impl EventLoop { } // NOTE: Wayland first because of X11 could be present under wayland as well. - #[cfg(wayland_platform)] - if attributes.forced_backend == Some(Backend::Wayland) - || env::var("WAYLAND_DISPLAY").is_ok() - { - return EventLoop::new_wayland_any_thread().map_err(Into::into); - } + let backend = match ( + attributes.forced_backend, + env::var("WAYLAND_DISPLAY").is_ok(), + env::var("DISPLAY").is_ok(), + ) { + // User is forcing a backend. + (Some(backend), _, _) => backend, + // Wayland is present. + #[cfg(wayland_platform)] + (None, true, _) => Backend::Wayland, + // X11 is present. + #[cfg(x11_platform)] + (None, _, true) => Backend::X, + // No backend is present. + _ => { + return Err(EventLoopError::Os(os_error!(OsError::Misc( + "neither WAYLAND_DISPLAY nor DISPLAY is set." + )))); + } + }; - #[cfg(x11_platform)] - if attributes.forced_backend == Some(Backend::X) || env::var("DISPLAY").is_ok() { - return Ok(EventLoop::new_x11_any_thread().unwrap()); + // Create the display based on the backend. + match backend { + #[cfg(wayland_platform)] + Backend::Wayland => EventLoop::new_wayland_any_thread().map_err(Into::into), + #[cfg(x11_platform)] + Backend::X => Ok(EventLoop::new_x11_any_thread().unwrap()), } - - Err(EventLoopError::Os(os_error!(OsError::Misc( - "neither WAYLAND_DISPLAY nor DISPLAY is set." - )))) } #[cfg(wayland_platform)]