From dae22574a6d5cf4710c42002a4d772bcafd74065 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sun, 3 May 2026 14:50:04 -0600 Subject: [PATCH] feat(window-settings): add available_titlebar_modes and is_sandboxed helpers Detection of KDE+Wayland for Plasma-mode availability. The is_sandboxed helper drives the frontend caveat hint about Flatpak/Snap. cc --- src-tauri/src/config/window_settings.rs | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src-tauri/src/config/window_settings.rs b/src-tauri/src/config/window_settings.rs index 403c1548d..e60d7e88b 100644 --- a/src-tauri/src/config/window_settings.rs +++ b/src-tauri/src/config/window_settings.rs @@ -430,3 +430,43 @@ pub fn set_match_system_window_chrome( ); state.set_match_system_window_chrome(value) } + +/// Returns the titlebar modes valid for the current platform/session. +/// `Plasma` is only included on KDE Plasma + Wayland — on other environments +/// the Xwayland trick is unnecessary or non-applicable. +pub fn available_titlebar_modes() -> Vec { + let mut modes = vec![ + TitlebarMode::Qbz, + TitlebarMode::System, + TitlebarMode::Hidden, + ]; + + #[cfg(target_os = "linux")] + { + let kde = std::env::var("XDG_CURRENT_DESKTOP") + .map(|d| d.split(':').any(|s| s.eq_ignore_ascii_case("KDE"))) + .unwrap_or(false); + let wayland = std::env::var_os("WAYLAND_DISPLAY").is_some() + || std::env::var("XDG_SESSION_TYPE").as_deref() == Ok("wayland"); + if kde && wayland { + modes.push(TitlebarMode::Plasma); + } + } + + modes +} + +/// Whether the current process is running inside a Linux sandbox +/// (Flatpak or Snap). Used by the frontend to display a sandbox-caveat +/// hint when the user selects Plasma mode in those builds. +pub fn is_sandboxed() -> bool { + #[cfg(target_os = "linux")] + { + std::path::Path::new("/.flatpak-info").exists() + || std::env::var_os("SNAP").is_some() + } + #[cfg(not(target_os = "linux"))] + { + false + } +}