|
2 | 2 | #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] |
3 | 3 |
|
4 | 4 | fn main() { |
| 5 | + // Workaround for Wayland Error 71 (Protocol error) on KDE Plasma 6 |
| 6 | + // See: https://github.com/tauri-apps/tauri/issues/10702 |
| 7 | + // https://github.com/tauri-apps/tao/issues/977 |
| 8 | + // |
| 9 | + // WebKitGTK has compatibility issues with Wayland on KDE Plasma 6, causing |
| 10 | + // "Error 71 (Protocol error) dispatching to Wayland display" crashes. |
| 11 | + // This is an upstream issue blocked by tao/webkit2gtk compatibility. |
| 12 | + // |
| 13 | + // Solution: Automatically fallback to X11 via XWayland if: |
| 14 | + // 1. We're on Linux |
| 15 | + // 2. GDK_BACKEND is not already set (respect user preference) |
| 16 | + // 3. We're in a Wayland session |
| 17 | + // 4. We're on KDE Plasma 6 (or any Wayland compositor with issues) |
| 18 | + #[cfg(target_os = "linux")] |
| 19 | + { |
| 20 | + use std::env; |
| 21 | + |
| 22 | + // Only set GDK_BACKEND if not already configured by user |
| 23 | + if env::var("GDK_BACKEND").is_err() { |
| 24 | + // Check if we're in a Wayland session |
| 25 | + if let Ok(session_type) = env::var("XDG_SESSION_TYPE") { |
| 26 | + if session_type == "wayland" { |
| 27 | + // Check for KDE Plasma (common source of Error 71) |
| 28 | + let is_kde = env::var("KDE_SESSION_VERSION").is_ok() |
| 29 | + || env::var("KDE_FULL_SESSION").is_ok() |
| 30 | + || env::var("DESKTOP_SESSION") |
| 31 | + .map(|s| s.contains("plasma") || s.contains("kde")) |
| 32 | + .unwrap_or(false); |
| 33 | + |
| 34 | + if is_kde { |
| 35 | + eprintln!( |
| 36 | + "Detected KDE Plasma on Wayland - forcing X11 backend to avoid Error 71" |
| 37 | + ); |
| 38 | + eprintln!("See: https://github.com/tauri-apps/tauri/issues/10702"); |
| 39 | + // SAFETY: We're in main() before any threads are spawned, |
| 40 | + // so there's no risk of data races with other threads reading env vars |
| 41 | + unsafe { |
| 42 | + env::set_var("GDK_BACKEND", "x11"); |
| 43 | + } |
| 44 | + } else { |
| 45 | + // For other Wayland compositors, prefer Wayland but fallback to X11 |
| 46 | + // This allows GDK to try Wayland first, then X11 if issues occur |
| 47 | + // SAFETY: We're in main() before any threads are spawned, |
| 48 | + // so there's no risk of data races with other threads reading env vars |
| 49 | + unsafe { |
| 50 | + env::set_var("GDK_BACKEND", "wayland,x11"); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + // Workaround for GBM (Generic Buffer Management) errors |
| 58 | + // See: https://github.com/tauri-apps/tauri/issues/13493 |
| 59 | + // https://github.com/winfunc/opcode/issues/26 |
| 60 | + // |
| 61 | + // WebKitGTK's hardware-accelerated compositing can fail with: |
| 62 | + // "Failed to create GBM buffer of size WxH: Invalid argument" |
| 63 | + // |
| 64 | + // This occurs due to incompatibility between WebKitGTK, Mesa, and GPU drivers |
| 65 | + // (especially NVIDIA). Disabling compositing mode forces WebKit to use a |
| 66 | + // simpler, more compatible rendering path. |
| 67 | + if env::var("WEBKIT_DISABLE_COMPOSITING_MODE").is_err() { |
| 68 | + // SAFETY: We're in main() before any threads are spawned |
| 69 | + unsafe { |
| 70 | + env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1"); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
5 | 75 | wraith_recon_lib::run() |
6 | 76 | } |
0 commit comments