Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
68 stars 20 forks source link

X11 window manager is not detected when XDG_SESSION_TYPE is incorrect #165

Open Absolpega opened 1 year ago

Absolpega commented 1 year ago

I was just setting up a testing setup to try and fix #9. I am on hyprland. I have a Xephyr x session opened as display :3. I ran DISPLAY=:3 awesome to run the wm. Then I ran DISPLAY=:3 env -u WAYLAND_DISPLAY alacritty to get a terminal in the x session but when I ran my fetch no wm was detected.

In the libmacchina code when deciding if to check for X11 or Wayland the XDG_SESSION_TYPE env variable is used. This was still set to wayland so it ran detect_wayland_window_manager() which obviously failed on x11.

This could be prevented by doing detect_wayland_window_manager().or_else(|_| detect_xorg_window_manager()). But that sounds like a very lazy and incomplete solution.

I just tried to run a regular x session with startx but XDG_SESSION_TYPE was now set to tty creating the same problem.

I don't think we should be relying on XDG_SESSION_TYPE.

Absolpega commented 1 year ago

elkowar/eww uses this to detect wayland

fn detect_wayland() -> bool {
    let session_type = std::env::var("XDG_SESSION_TYPE").unwrap_or_default();
    let wayland_display = std::env::var("WAYLAND_DISPLAY").unwrap_or_default();
    session_type.contains("wayland") || (!wayland_display.is_empty() && !session_type.contains("x11"))
}
Absolpega commented 1 year ago

don't know how to work with github did not mean to do that