From 0b4ec5f339bf759ea8d255af90012a8371e43f0b Mon Sep 17 00:00:00 2001 From: anonymous Date: Mon, 20 Jul 2026 12:29:30 -0500 Subject: [PATCH] fix(linux): avoid Wayland EGL startup failure --- README.md | 10 +++++ src-tauri/src/linux_webkit.rs | 78 +++++++++++++++++++++++++++++++++++ src-tauri/src/main.rs | 6 +++ 3 files changed, 94 insertions(+) create mode 100644 src-tauri/src/linux_webkit.rs diff --git a/README.md b/README.md index b07adac..f251ab5 100755 --- a/README.md +++ b/README.md @@ -57,6 +57,16 @@ sudo dpkg -i thinkutils_*.deb sudo rpm -i thinkutils-*.rpm ``` +### Wayland compatibility + +ThinkUtils automatically uses WebKitGTK's compatibility renderer on Wayland to +avoid startup failures from unsupported DMA-BUF/EGL configurations. To retain +WebKitGTK's default renderer for troubleshooting, launch with: + +```bash +THINKUTILS_SKIP_WAYLAND_WORKAROUND=1 thinkutils +``` + ## Features ### 🏠 Home Dashboard diff --git a/src-tauri/src/linux_webkit.rs b/src-tauri/src/linux_webkit.rs new file mode 100644 index 0000000..a95e99e --- /dev/null +++ b/src-tauri/src/linux_webkit.rs @@ -0,0 +1,78 @@ +use std::ffi::OsStr; + +const DMABUF_RENDERER_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER"; +const SKIP_WORKAROUND_ENV: &str = "THINKUTILS_SKIP_WAYLAND_WORKAROUND"; + +pub fn apply_wayland_renderer_workaround() { + if !should_apply_workaround( + std::env::var_os("XDG_SESSION_TYPE").as_deref(), + std::env::var_os("WAYLAND_DISPLAY").as_deref(), + std::env::var_os(DMABUF_RENDERER_ENV).as_deref(), + std::env::var_os(SKIP_WORKAROUND_ENV).as_deref(), + ) { + return; + } + + // This must run before Tauri initializes WebKitGTK. It selects WebKit's + // fallback renderer when the DMA-BUF/EGL path is unavailable on Wayland. + std::env::set_var(DMABUF_RENDERER_ENV, "1"); + eprintln!("[thinkutils] Wayland detected; enabled WebKitGTK EGL compatibility mode"); +} + +fn should_apply_workaround( + session_type: Option<&OsStr>, + wayland_display: Option<&OsStr>, + renderer_override: Option<&OsStr>, + skip_workaround: Option<&OsStr>, +) -> bool { + let is_wayland = session_type + .and_then(OsStr::to_str) + .is_some_and(|value| value.eq_ignore_ascii_case("wayland")) + || wayland_display.is_some(); + + is_wayland && renderer_override.is_none() && skip_workaround.is_none() +} + +#[cfg(test)] +mod tests { + use super::should_apply_workaround; + use std::ffi::OsStr; + + #[test] + fn applies_to_wayland_sessions_without_an_override() { + assert!(should_apply_workaround( + Some(OsStr::new("wayland")), + None, + None, + None, + )); + assert!(should_apply_workaround( + None, + Some(OsStr::new("wayland-0")), + None, + None, + )); + } + + #[test] + fn leaves_x11_and_user_choices_unchanged() { + assert!(!should_apply_workaround( + Some(OsStr::new("x11")), + None, + None, + None, + )); + assert!(!should_apply_workaround( + Some(OsStr::new("wayland")), + None, + Some(OsStr::new("0")), + None, + )); + assert!(!should_apply_workaround( + Some(OsStr::new("wayland")), + None, + None, + Some(OsStr::new("1")), + )); + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3813af1..5449b53 100755 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,12 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +#[cfg(target_os = "linux")] +mod linux_webkit; + fn main() { + #[cfg(target_os = "linux")] + linux_webkit::apply_wayland_renderer_workaround(); + thinkutils_lib::run() }