Skip to content

Commit

Permalink
Support WAYLAND_SOCKET in winit backend
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bbb651 committed Jan 12, 2025
1 parent 6e41220 commit 05abfa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

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

// Set the current desktop for xdg-desktop-portal.
env::set_var("XDG_CURRENT_DESKTOP", "niri");
Expand Down
5 changes: 3 additions & 2 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ impl State {

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

let has_display =
env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
let has_display = env::var_os("WAYLAND_DISPLAY").is_some()
|| env::var_os("WAYLAND_SOCKET").is_some()
|| env::var_os("DISPLAY").is_some();

let mut backend = if headless {
let headless = Headless::new();
Expand Down

0 comments on commit 05abfa8

Please sign in to comment.