forge
Explore
Log in

Don't you dare go Hollow

Remove {WAYLAND_,}DISPLAY from environment if running as a service

Browse files at this commit

c95e4a738f998eedec7da10fec18be40f2d38d4aIvan MolodetskikhParent: d6b8310
Notably, running the GNOME Xorg session followed by niri results in a
leftover DISPLAY.
src/main.rsmodified+14 -0
@@ -79,6 +79,20 @@ fn main() {
7979 git_version!(fallback = "unknown commit"),
8080 );
8181
82+ if is_systemd_service {
83+ // If we're starting as a systemd service, assume that the intention is to start on a TTY.
84+ // Remove DISPLAY or WAYLAND_DISPLAY from our environment if they are set, since they will
85+ // cause the winit backend to be selected instead.
86+ if env::var_os("DISPLAY").is_some() {
87+ debug!("we're running as a systemd service but DISPLAY is set, removing it");
88+ env::remove_var("DISPLAY");
89+ }
90+ if env::var_os("WAYLAND_DISPLAY").is_some() {
91+ debug!("we're running as a systemd service but WAYLAND_DISPLAY is set, removing it");
92+ env::remove_var("WAYLAND_DISPLAY");
93+ }
94+ }
95+
8296 let cli = Cli::parse();
8397
8498 let _client = tracy_client::Client::start();