Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 78d78ea78b Merge remote-tracking branch 'origin/main' into fix/linux-wslg-x11
# Conflicts:
#	src-tauri/src/linux_webkit.rs
2026-11-25 18:54:28 +08:00
l0ng-ai 7c5e8eac2b fix(linux): use X11 under WSLg
Started from a WSL shell, GTK picks WSLg's Wayland display, where Mesa
has no usable driver for WebKitGTK and the window stays blank. WSL now
uses WSLg's X server unless GDK_BACKEND is set.
2026-11-25 10:10:18 +08:00
+24
Переглянути файл
@@ -13,6 +13,10 @@
//! inside the window, so with several monitors its candidate window opens on the wrong
//! one. Through the compositor (Mutter hands text-input to Fcitx's IBus frontend) it
//! follows the caret, so GNOME Wayland sessions drop `GTK_IM_MODULE=fcitx`.
//!
//! WSLg's Wayland compositor has no usable GPU path for WebKitGTK (Mesa reports an
//! incompatible driver and the window stays blank); its X server works, so WSL uses X11
//! unless `GDK_BACKEND` is set.
const DISABLE_DMABUF: &str = "WEBKIT_DISABLE_DMABUF_RENDERER";
const DISABLE_EXPLICIT_SYNC: &str = "__NV_DISABLE_EXPLICIT_SYNC";
@@ -21,6 +25,10 @@ const IM_MODULE: &str = "GTK_IM_MODULE";
/// Run before other threads start (`set_var`).
#[cfg(target_os = "linux")]
pub fn configure() {
if use_x11_on_wsl(|k| std::env::var(k).ok()) {
tracing::info!("WSLg: GDK_BACKEND=x11");
unsafe { std::env::set_var("GDK_BACKEND", "x11") };
}
let nvidia = ["/proc/driver/nvidia/version", "/sys/module/nvidia"].iter().any(|p| std::path::Path::new(p).exists());
if disable_explicit_sync(|k| std::env::var(k).ok(), nvidia) {
tracing::info!("Wayland with the NVIDIA driver: {DISABLE_EXPLICIT_SYNC}=1");
@@ -43,6 +51,12 @@ fn drop_fcitx_module(var: impl Fn(&str) -> Option<String>) -> bool {
gnome && var(IM_MODULE).is_some_and(|m| matches!(m.trim(), "fcitx" | "fcitx5")) && gdk_wayland(&var)
}
/// Under WSL with WSLg's X server available, unless the user chose a GDK backend.
fn use_x11_on_wsl(var: impl Fn(&str) -> Option<String>) -> bool {
let set = |k: &str| var(k).is_some_and(|v| !v.is_empty());
(set("WSL_DISTRO_NAME") || set("WSL_INTEROP")) && set("DISPLAY") && !set("GDK_BACKEND")
}
/// GTK 3's IBus input method module (`ibus-gtk3`), wherever the distribution keeps it.
#[cfg(target_os = "linux")]
fn gtk_ibus_module_installed() -> bool {
@@ -163,6 +177,16 @@ mod tests {
assert!(!drop_fcitx_module(env(&[gnome[0], gnome[1], (IM_MODULE, "ibus")])));
}
#[test]
fn wsl_uses_x11_unless_a_backend_is_chosen() {
let wslg = [("WSL_DISTRO_NAME", "Ubuntu-24.04"), ("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0")];
assert!(use_x11_on_wsl(env(&wslg)));
assert!(use_x11_on_wsl(env(&[("WSL_INTEROP", "/run/WSL/1_interop"), ("DISPLAY", ":0")])));
assert!(!use_x11_on_wsl(env(&[wslg[0], wslg[1], wslg[2], ("GDK_BACKEND", "wayland")])));
assert!(!use_x11_on_wsl(env(&[wslg[0], wslg[1]])), "no X server");
assert!(!use_x11_on_wsl(env(&[wslg[1], wslg[2]])), "not WSL");
}
#[test]
fn keeps_the_users_input_method_module() {
let vars = [("WAYLAND_DISPLAY", "wayland-0"), ("XMODIFIERS", "@im=ibus"), (IM_MODULE, "wayland")];