slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 568 forks source link

Slint demo can not work on WSL2 #3344

Closed zrz4066 closed 1 year ago

zrz4066 commented 1 year ago

Created by cargo generate --git https://github.com/slint-ui/slint-rust-template --name myguitest

it can't work well after cargo run, the following are the error message ice@DESKTOP-OH5PBNG:~/rust/myguitest$ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.21s Running target/debug/myguitest Error: Other("Winit backend failed to find a suitable renderer. Last failure was: Cannot create OpenGL context: [a1] GLXBadFBConfig")

ice@DESKTOP-OH5PBNG:~/rust/myguitest$ neofetch .-/+oossssoo+/-. ice@DESKTOP-OH5PBNG :+ssssssssssssssssss+: ------------------- -+ssssssssssssssssssyyssss+- OS: Ubuntu 20.04.6 LTS on Windows 10 x86_64 .ossssssssssssssssssdMMMNysssso. Kernel: 5.10.16.3-microsoft-standard-WSL2 /ssssssssssshdmmNNmmyNMMMMhssssss/ Uptime: 15 mins +ssssssssshmydMMMMMMMNddddyssssssss+ Packages: 1254 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Shell: bash 5.0.17 .ssssssssdMMMNhsssssssssshNMMMdssssssss. Resolution: 1904x1001 +sssshhhyNMMNyssssssssssssyNMMMysssssss+ WM: Xfwm4 ossyNMMMNyMMhsssssssssssssshmmmhssssssso WM Theme: Default ossyNMMMNyMMhsssssssssssssshmmmhssssssso Theme: Adwaita [GTK3] +sssshhhyNMMNyssssssssssssyNMMMysssssss+ Icons: Adwaita [GTK3] .ssssssssdMMMNhsssssssssshNMMMdssssssss. Terminal: /dev/pts/1 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ CPU: Intel i5-8265U (8) @ 1.800GHz +sssssssssdmydMMMMMMMMddddyssssssss+ GPU: Microsoft Corporation Device 008e /ssssssssssshdmNNNNmyNMMMMhssssss/ Memory: 242MiB / 12542MiB .ossssssssssssssssssdMMMNysssso. -+sssssssssssssssssyyyssss+-
:+ssssssssssssssssss+: .-/+oossssoo+/-.

tronical commented 1 year ago

You're running Xfwm4 under WSL. As far as I can tell, Xfwm4 only acts as X11 window manager (and compositor), but not as wayland compositor. That means Slint will try to connect via GLX, which also doesn't work (I suppose that part is WSL related).

At the moment WSL only works with software rendering or Wayland, but not GLX.

However, Slint should fall back to software rendering if the GLX setup fails. That seems like a bug to me.

Meanwhile, does it work if you set the SLINT_BACKEND environment variable to the value winit-software?

tronical commented 1 year ago

2907 should have fixed this, but apparently this isn't working under WSL.

ogoffart commented 1 year ago

the renderer-winit-software feature wasn't enabled by default in the last release (1.1.1). But it will be in the next release (1.2).

tronical commented 1 year ago

Thanks, that explains it. @zrz4066 then your workaround is to edit Cargo.toml and change the line that says

slint = "1.0"

to read

slint = { version = "1.0", features = ["renderer-winit-software"] }

and this will not be needed anymore in the next release.