Skip to content

Commit c523c80

Browse files
bbb651YaLTeR
authored andcommitted
Support WAYLAND_SOCKET in winit backend
I know of a single compositor that supports `WAYLAND_SOCKET` but not `WAYLAND_DISPLAY`: https://gitlab.freedesktop.org/mstoeckl/windowtolayer This should also make niri more robust against accidentally setting `WAYLAND_SOCKET` when starting as a session, before programs could fail if they preffered `WAYLAND_SOCKET` over `WAYLAND_DISPLAY`
1 parent 0bd6df5 commit c523c80

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6969

7070
if cli.session {
7171
// If we're starting as a session, assume that the intention is to start on a TTY. Remove
72-
// DISPLAY or WAYLAND_DISPLAY from our environment if they are set, since they will cause
73-
// the winit backend to be selected instead.
72+
// DISPLAY, WAYLAND_DISPLAY or WAYLAND_SOCKET from our environment if they are set, since
73+
// they will cause the winit backend to be selected instead.
7474
if env::var_os("DISPLAY").is_some() {
7575
warn!("running as a session but DISPLAY is set, removing it");
7676
env::remove_var("DISPLAY");
@@ -79,6 +79,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7979
warn!("running as a session but WAYLAND_DISPLAY is set, removing it");
8080
env::remove_var("WAYLAND_DISPLAY");
8181
}
82+
if env::var_os("WAYLAND_SOCKET").is_some() {
83+
warn!("running as a session but WAYLAND_SOCKET is set, removing it");
84+
env::remove_var("WAYLAND_SOCKET");
85+
}
8286

8387
// Set the current desktop for xdg-desktop-portal.
8488
env::set_var("XDG_CURRENT_DESKTOP", "niri");

src/niri.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,9 @@ impl State {
547547

548548
let config = Rc::new(RefCell::new(config));
549549

550-
let has_display =
551-
env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
550+
let has_display = env::var_os("WAYLAND_DISPLAY").is_some()
551+
|| env::var_os("WAYLAND_SOCKET").is_some()
552+
|| env::var_os("DISPLAY").is_some();
552553

553554
let mut backend = if headless {
554555
let headless = Headless::new();

0 commit comments

Comments
 (0)