diff options
| author | bnema <[email protected]> | 2026-02-16 06:24:28 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-16 13:24:28 +0800 |
| commit | 60807846a92be5ab75367d8ca14b6b1bc697aebe (patch) | |
| tree | d64f7aa9e7a91230a6deb14793d5bbb42ac211a3 /packages/desktop/src-tauri/src/main.rs | |
| parent | afd0716cbdca5191b6c45dbc8325c6f9e658715f (diff) | |
| download | opencode-60807846a92be5ab75367d8ca14b6b1bc697aebe.tar.gz opencode-60807846a92be5ab75367d8ca14b6b1bc697aebe.zip | |
fix(desktop): normalize Linux Wayland/X11 backend and decoration policy (#13143)
Co-authored-by: Brendan Allan <[email protected]>
Diffstat (limited to 'packages/desktop/src-tauri/src/main.rs')
| -rw-r--r-- | packages/desktop/src-tauri/src/main.rs | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/packages/desktop/src-tauri/src/main.rs b/packages/desktop/src-tauri/src/main.rs index 9eb86cdac..c0ce2a445 100644 --- a/packages/desktop/src-tauri/src/main.rs +++ b/packages/desktop/src-tauri/src/main.rs @@ -4,6 +4,7 @@ // borrowed from https://github.com/skyline69/balatro-mod-manager #[cfg(target_os = "linux")] fn configure_display_backend() -> Option<String> { + use opencode_lib::linux_windowing::{Backend, SessionEnv, select_backend}; use std::env; let set_env_if_absent = |key: &str, value: &str| { @@ -14,45 +15,28 @@ fn configure_display_backend() -> Option<String> { } }; - let on_wayland = env::var_os("WAYLAND_DISPLAY").is_some() - || matches!( - env::var("XDG_SESSION_TYPE"), - Ok(v) if v.eq_ignore_ascii_case("wayland") - ); - if !on_wayland { - return None; - } - + let session = SessionEnv::capture(); let prefer_wayland = opencode_lib::linux_display::read_wayland().unwrap_or(false); - let allow_wayland = prefer_wayland - || matches!( - env::var("OC_ALLOW_WAYLAND"), - Ok(v) if matches!(v.to_ascii_lowercase().as_str(), "1" | "true" | "yes") - ); - if allow_wayland { - if prefer_wayland { - return Some("Wayland session detected; using native Wayland from settings".into()); - } - return Some("Wayland session detected; respecting OC_ALLOW_WAYLAND=1".into()); - } + let decision = select_backend(&session, prefer_wayland)?; - // Prefer XWayland when available to avoid Wayland protocol errors seen during startup. - if env::var_os("DISPLAY").is_some() { - set_env_if_absent("WINIT_UNIX_BACKEND", "x11"); - set_env_if_absent("GDK_BACKEND", "x11"); - set_env_if_absent("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); - return Some( - "Wayland session detected; forcing X11 backend to avoid compositor protocol errors. \ - Set OC_ALLOW_WAYLAND=1 to keep native Wayland." - .into(), - ); + match decision.backend { + Backend::X11 => { + set_env_if_absent("WINIT_UNIX_BACKEND", "x11"); + set_env_if_absent("GDK_BACKEND", "x11"); + set_env_if_absent("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); + } + Backend::Wayland => { + set_env_if_absent("WINIT_UNIX_BACKEND", "wayland"); + set_env_if_absent("GDK_BACKEND", "wayland"); + set_env_if_absent("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); + } + Backend::Auto => { + set_env_if_absent("GDK_BACKEND", "wayland,x11"); + set_env_if_absent("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); + } } - set_env_if_absent("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); - Some( - "Wayland session detected without X11; leaving Wayland enabled (set WINIT_UNIX_BACKEND/GDK_BACKEND manually if needed)." - .into(), - ) + Some(decision.note) } fn main() { |
