Set GDK_BACKEND env var on wayland

This commit is contained in:
elkowar 2024-08-21 18:33:26 +02:00
parent 4d55e9ad63
commit 696135a6bb
No known key found for this signature in database
GPG key ID: 862BA3D7D7760F13
3 changed files with 12 additions and 1 deletions

View file

@ -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>;
}
@ -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))
@ -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);
@ -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 =

View file

@ -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)
};

View file

@ -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");