Skip to content

Automatic backend selection fails under Ubunty on XOrg #4316

@radoye

Description

@radoye

Automatic selection fails when logged in using "Ubuntu on XOrg"; moving to "Wayland" makes this work. Forcing x11 backend in code works, but not through an envvar.

cargo build && WINIT_UNIX_BACKEND=x11 cargo run
warning: unused import: `EventLoopBuilder`
 --> src/main.rs:2:42
  |
2 |     event_loop::{ControlFlow, EventLoop, EventLoopBuilder},
  |                                          ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `winit_repro` (bin "winit_repro") generated 1 warning (run `cargo fix --bin "winit_repro"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
warning: unused import: `EventLoopBuilder`
 --> src/main.rs:2:42
  |
2 |     event_loop::{ControlFlow, EventLoop, EventLoopBuilder},
  |                                          ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `winit_repro` (bin "winit_repro") generated 1 warning (run `cargo fix --bin "winit_repro"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/winit_repro`
WINIT_UNIX_BACKEND = Ok("x11")

thread 'main' panicked at src/main.rs:11:39:
called `Result::unwrap()` on an `Err` value: Os(OsError { line: 89, file: "/home/rrs/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winit-0.30.12/src/platform_impl/linux/wayland/event_loop/mod.rs", error: WaylandError(Connection(NoCompositor)) })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
rrs@cypress:~/docks/dev/winit_repro$ 

Here's the code:

use winit::{
    event_loop::{ControlFlow, EventLoop, EventLoopBuilder}, platform::x11::EventLoopBuilderExtX11,
};

fn main() {
    println!(
        "WINIT_UNIX_BACKEND = {:?}",
        std::env::var("WINIT_UNIX_BACKEND")
    );

    //let event_loop = EventLoop::new().unwrap();
    let event_loop = EventLoopBuilder::new()
        .with_x11()
        .build()
        .expect("Failed to build event loop");
    event_loop.set_control_flow(ControlFlow::Poll);

}

And the deps

[package]
name = "winit_repro"
version = "0.1.0"
edition = "2024"

[dependencies]
winit = "0.30.12"
uname -a
Linux cypress 6.14.0-24-generic #24~24.04.3-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul  7 16:39:17 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
rrs@cypress:~/docks/dev/winit_repro$ 
apt list libwayland*
Listing... Done
libwayland-bin-dbgsym/noble 1.22.0-2.1build1 amd64
libwayland-bin/noble,now 1.22.0-2.1build1 amd64 [installed,automatic]
libwayland-client++1-dbgsym/noble 1.0.0-5ubuntu2 amd64
libwayland-client++1/noble 1.0.0-5ubuntu2 amd64
libwayland-client-extra++1-dbgsym/noble 1.0.0-5ubuntu2 amd64
libwayland-client-extra++1/noble 1.0.0-5ubuntu2 amd64
libwayland-client0-dbgsym/noble,now 1.22.0-2.1build1 amd64 [installed]
libwayland-client0/noble,now 1.22.0-2.1build1 amd64 [installed]
libwayland-cursor++1-dbgsym/noble 1.0.0-5ubuntu2 amd64
libwayland-cursor++1/noble 1.0.0-5ubuntu2 amd64
libwayland-cursor0-dbgsym/noble 1.22.0-2.1build1 amd64
libwayland-cursor0/noble,now 1.22.0-2.1build1 amd64 [installed,automatic]
libwayland-dev/noble,now 1.22.0-2.1build1 amd64 [installed]
libwayland-doc/noble 1.22.0-2.1build1 all
libwayland-egl++1-dbgsym/noble 1.0.0-5ubuntu2 amd64
libwayland-egl++1/noble 1.0.0-5ubuntu2 amd64
libwayland-egl-backend-dev/noble 1.22.0-2.1build1 amd64
libwayland-egl1-dbgsym/noble 1.22.0-2.1build1 amd64
libwayland-egl1/noble,now 1.22.0-2.1build1 amd64 [installed,automatic]
libwayland-server++1-dbgsym/noble 1.0.0-5ubuntu2 amd64
libwayland-server++1/noble 1.0.0-5ubuntu2 amd64
libwayland-server0-dbgsym/noble 1.22.0-2.1build1 amd64
libwayland-server0/noble,now 1.22.0-2.1build1 amd64 [installed,automatic]
rrs@cypress:~/docks/dev/winit_repro$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions