diff --git a/Changelog.md b/Changelog.md index 355b8940a..9d8fbee24 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ - 修复 Linux 关闭 TUN 不立即生效 - 修复系统代理关闭序列逻辑(防止快速退出时系统代理关闭状态没有保存) - 修复 Linux 快捷键映射错误 +- 修复 Linux Wayland 兼容性导致渲染错误 ### ✨ 新增功能 diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f6e9229a9..44a785234 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -216,6 +216,8 @@ pub fn run() { #[cfg(target_os = "linux")] utils::linux::workarounds::apply_nvidia_dmabuf_renderer_workaround(); + #[cfg(target_os = "linux")] + utils::linux::workarounds::apply_wayland_webkit_fix(); let _ = utils::dirs::init_portable_flag(); diff --git a/src-tauri/src/utils/linux/workarounds.rs b/src-tauri/src/utils/linux/workarounds.rs index ff5e589d0..323375ebf 100644 --- a/src-tauri/src/utils/linux/workarounds.rs +++ b/src-tauri/src/utils/linux/workarounds.rs @@ -4,7 +4,7 @@ //! These helpers are not fixes and may stop working as environments change. use clash_verge_logging::{Type, logging}; -use std::{fs, path::Path}; +use std::{env, fs, path::Path, process::Command}; pub fn apply_nvidia_dmabuf_renderer_workaround() { if std::env::var_os("WEBKIT_DISABLE_DMABUF_RENDERER").is_some() { @@ -23,6 +23,29 @@ pub fn apply_nvidia_dmabuf_renderer_workaround() { } } +/// !Might cause more memory footpoint +pub fn apply_wayland_webkit_fix() { + let is_wayland = env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland"; + + if !is_wayland { + return; + } + + let version = Command::new("pkg-config") + .args(["--modversion", "wayland-client"]) + .output() + .ok() + .and_then(|output| String::from_utf8(output.stdout).ok()); + + if let Some(v) = version + && v.trim() <= "1.23.0" + { + unsafe { + env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); + } + } +} + fn has_nvidia_gpu() -> bool { if Path::new("/proc/driver/nvidia/version").exists() || Path::new("/sys/module/nvidia").exists()