From 696135a6bba3d083d326eda1f81471c636987afb Mon Sep 17 00:00:00 2001 From: elkowar Date: Wed, 21 Aug 2024 18:33:26 +0200 Subject: [PATCH] Set GDK_BACKEND env var on wayland --- crates/eww/src/display_backend.rs | 4 ++++ crates/eww/src/main.rs | 6 +++++- crates/eww/src/server.rs | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/eww/src/display_backend.rs b/crates/eww/src/display_backend.rs index d416166b..16cd8662 100644 --- a/crates/eww/src/display_backend.rs +++ b/crates/eww/src/display_backend.rs @@ -8,6 +8,7 @@ pub use platform_x11::{set_xprops, X11Backend}; pub trait DisplayBackend: Send + Sync + 'static { const IS_X11: bool; + const IS_WAYLAND: bool; fn initialize_window(window_init: &WindowInitiator, monitor: gdk::Rectangle, x: i32, y: i32) -> Option; } @@ -16,6 +17,7 @@ pub struct NoBackend; impl DisplayBackend for NoBackend { const IS_X11: bool = false; + const IS_WAYLAND: bool = false; fn initialize_window(_window_init: &WindowInitiator, _monitor: gdk::Rectangle, x: i32, y: i32) -> Option { Some(Window::new(gtk::WindowType::Toplevel, x, y)) @@ -34,6 +36,7 @@ mod platform_wayland { impl DisplayBackend for WaylandBackend { const IS_X11: bool = false; + const IS_WAYLAND: bool = true; fn initialize_window(window_init: &WindowInitiator, monitor: gdk::Rectangle, x: i32, y: i32) -> Option { let window = Window::new(gtk::WindowType::Toplevel, x, y); @@ -134,6 +137,7 @@ mod platform_x11 { pub struct X11Backend; impl DisplayBackend for X11Backend { const IS_X11: bool = true; + const IS_WAYLAND: bool = false; fn initialize_window(window_init: &WindowInitiator, _monitor: gdk::Rectangle, x: i32, y: i32) -> Option { let window_type = diff --git a/crates/eww/src/main.rs b/crates/eww/src/main.rs index 0db2b975..ad46da99 100644 --- a/crates/eww/src/main.rs +++ b/crates/eww/src/main.rs @@ -54,11 +54,15 @@ fn main() { } #[allow(unused)] - let use_wayland = opts.force_wayland || detect_wayland(); + let detected_wayland = detect_wayland(); + #[allow(unused)] + let use_wayland = opts.force_wayland || detected_wayland; #[cfg(all(feature = "wayland", feature = "x11"))] let result = if use_wayland { + log::info!("Running on wayland. force_wayland={}, detected_wayland={}", opts.force_wayland, detected_wayland); run(opts, eww_binary_name, display_backend::WaylandBackend) } else { + log::info!("Running on X11. force_wayland={}, detected_wayland={}", opts.force_wayland, detected_wayland); run(opts, eww_binary_name, display_backend::X11Backend) }; diff --git a/crates/eww/src/server.rs b/crates/eww/src/server.rs index 50b24b2f..6c5a9d91 100644 --- a/crates/eww/src/server.rs +++ b/crates/eww/src/server.rs @@ -68,6 +68,9 @@ pub fn initialize_server( } }); + if B::IS_WAYLAND { + std::env::set_var("GDK_BACKEND", "wayland") + } gtk::init()?; log::debug!("Initializing script var handler");