Skip to content

Commit

Permalink
Set GDK_BACKEND env var on wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Aug 21, 2024
1 parent 4d55e9a commit 696135a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/eww/src/display_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Window>;
}
Expand All @@ -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<Window> {
Some(Window::new(gtk::WindowType::Toplevel, x, y))
Expand All @@ -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<Window> {
let window = Window::new(gtk::WindowType::Toplevel, x, y);
Expand Down Expand Up @@ -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<Window> {
let window_type =
Expand Down
6 changes: 5 additions & 1 deletion crates/eww/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down
3 changes: 3 additions & 0 deletions crates/eww/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ pub fn initialize_server<B: DisplayBackend>(
}
});

if B::IS_WAYLAND {
std::env::set_var("GDK_BACKEND", "wayland")
}
gtk::init()?;

log::debug!("Initializing script var handler");
Expand Down

0 comments on commit 696135a

Please sign in to comment.