Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): use system-managed liquid glass on main window
Richie McIlroyde56fc9de9ae
diff --git a/apps/desktop/src-tauri/src/platform/macos/mod.rs b/apps/desktop/src-tauri/src/platform/macos/mod.rsindex 31d87787a..4f75dccf6 100644--- a/apps/desktop/src-tauri/src/platform/macos/mod.rs+++ b/apps/desktop/src-tauri/src/platform/macos/mod.rs@@ -71,6 +71,21 @@ pub fn apply_squircle_corners(window: &tauri::WebviewWindow, radius: f64) {const TAURI_VIBRANCY_VIEW_TAG: isize = 91376254;const LIQUID_GLASS_IDENTIFIER: &str = "so.cap.liquid-glass-background";+const NS_GLASS_EFFECT_VIEW_STYLE_REGULAR: isize = 0;++#[derive(Clone, Copy, PartialEq, Eq)]+enum LiquidGlassActivity {+ SystemManaged,+ AlwaysActive,+}++pub fn apply_main_window_liquid_glass_background(+ window: &tauri::Window,+ enabled: bool,+ radius: f64,+) -> Result<bool, String> {+ apply_liquid_glass_background_inner(window, enabled, radius, LiquidGlassActivity::SystemManaged)+}unsafe fn remove_tagged_subview(container: cocoa::base::id, tag: isize) {use objc::{msg_send, sel, sel_impl};@@ -145,6 +160,15 @@ pub fn apply_liquid_glass_background(window: &tauri::Window,enabled: bool,radius: f64,+) -> Result<bool, String> {+ apply_liquid_glass_background_inner(window, enabled, radius, LiquidGlassActivity::AlwaysActive)+}++fn apply_liquid_glass_background_inner(+ window: &tauri::Window,+ enabled: bool,+ radius: f64,+ activity: LiquidGlassActivity,) -> Result<bool, String> {use cocoa::{base::{id, nil},@@ -218,21 +242,27 @@ pub fn apply_liquid_glass_background(let _: () = msg_send![glass_view, setCornerRadius: radius];}+ if activity == LiquidGlassActivity::SystemManaged {+ let _: () = msg_send![glass_view, setStyle: NS_GLASS_EFFECT_VIEW_STYLE_REGULAR];+ }+// Pin the glass to its "always-active" representation so it keeps re-rendering// the live backdrop regardless of which window currently has key state. The// default for an NSVisualEffectView-derived view is FollowsWindowActiveState,// which dims the material whenever another Cap window (camera, settings, etc.)// becomes key and masks the backdrop reactivity that's the whole point of- // Liquid Glass. NSGlassEffectView is private SPI introduced in macOS 26, so we- // probe multiple state knobs (`setState:`, `setActive:`) instead of assuming a- // single inheritance path.+ // Liquid Glass. The always-active state is private SPI, so we probe multiple+ // state knobs (`setState:`, `setActive:`) instead of assuming one inheritance+ // path. The main window does not enter this branch and remains system-managed.//// macOS 26.3 shipped an NSGlassEffectView that responds to neither selector,// so the pin silently fails. In that state the material can't be relied on// (it dims whenever another window becomes key), so abandon the private SPI// entirely and let the caller fall back to NSVisualEffectView vibrancy// (Ok(false)).- if !force_glass_view_always_active(glass_view) {+ if activity == LiquidGlassActivity::AlwaysActive+ && !force_glass_view_always_active(glass_view)+ {// Never entered the view hierarchy; balance the alloc and bail. The// content-layer squircle clip applied above is kept (plain Core Animation,// not a WindowServer/occlusion mutation) so the vibrancy fallback still gets@@ -270,10 +300,12 @@ pub fn apply_liquid_glass_background(relativeTo: nil];- // Re-apply after the view enters the hierarchy: some private AppKit views- // reset state machine fields on `viewDidMoveToWindow:`, so the post-add pass- // is what actually sticks.- force_glass_view_always_active(glass_view);+ if activity == LiquidGlassActivity::AlwaysActive {+ // Re-apply after the view enters the hierarchy: some private AppKit views+ // reset state machine fields on `viewDidMoveToWindow:`, so the post-add pass+ // is what actually sticks.+ force_glass_view_always_active(glass_view);+ }crate::crash_sentinel::set_liquid_glass_outcome("applied");Ok(true)@@ -435,9 +467,8 @@ unsafe fn enable_webview_occlusion_detection(content_view: cocoa::base::id) {}/// Reverse every WindowServer-visible mutation `apply_liquid_glass_background` makes:-/// remove the private NSGlassEffectView (the load-bearing step — it synchronously-/// detaches the private compositor relationship), then restore window/WKWebView-/// occlusion detection and window opacity. MUST run on the AppKit main thread.+/// remove the NSGlassEffectView, then restore window/WKWebView occlusion detection and+/// window opacity. MUST run on the AppKit main thread.unsafe fn teardown_liquid_glass_ns(ns_window: cocoa::base::id) {use cocoa::{base::{id, nil},diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex ba7ce87e8..07a8ef083 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -3603,8 +3603,13 @@ pub async fn apply_macos_liquid_glass_background(_window.run_on_main_thread(move || {- let result =- crate::platform::apply_liquid_glass_background(&window, _enabled, _radius);+ let result = if window.label() == CapWindowId::Main.label() {+ crate::platform::apply_main_window_liquid_glass_background(+ &window, _enabled, _radius,+ )+ } else {+ crate::platform::apply_liquid_glass_background(&window, _enabled, _radius)+ };let _ = tx.send(result);}).map_err(|error| error.to_string())?;