backend selector: Prefer the winit backend over the default backend (… (#8402)

On Linux, if Qt is found, the qt backend is the default. This backend doesn't support selecting graphics APIs, thus
the OpenGL and WGPU examples don't run out of the box.
This patch fixes that by preferring winit.
This commit is contained in:
Simon Hausmann 2025-05-12 14:48:03 +02:00 committed by GitHub
parent 126955fd1e
commit 8e046a2553
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -211,7 +211,15 @@ impl BackendSelector {
}
}
let backend_name = self.backend.as_deref().unwrap_or(super::DEFAULT_BACKEND_NAME);
let backend_name = self.backend.as_deref().unwrap_or_else(|| {
// Only the winit backend supports graphics API requests right now, so prefer that over
// aborting.
#[cfg(feature = "i-slint-backend-winit")]
if self.requested_graphics_api.is_some() {
return "winit";
}
super::DEFAULT_BACKEND_NAME
});
let backend: Box<dyn i_slint_core::platform::Platform> = match backend_name {
#[cfg(all(feature = "i-slint-backend-linuxkms", target_os = "linux"))]