Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): add macOS main window panel with squircle corners
Richie McIlroy928304ebbcb0
diff --git a/apps/desktop/src-tauri/src/platform/macos/mod.rs b/apps/desktop/src-tauri/src/platform/macos/mod.rsindex 14a315858..0fb753850 100644--- a/apps/desktop/src-tauri/src/platform/macos/mod.rs+++ b/apps/desktop/src-tauri/src/platform/macos/mod.rs@@ -26,6 +26,34 @@ pub fn set_window_level(window: tauri::Window, level: objc2_app_kit::NSWindowLev});}+pub fn apply_squircle_corners(window: &tauri::WebviewWindow, radius: f64) {+ use cocoa::base::{id, nil};+ use cocoa::foundation::NSString;+ use objc::{msg_send, sel, sel_impl};++ let Ok(ns_win) = window.ns_window() else {+ return;+ };++ unsafe {+ let ns_win = ns_win as id;+ let content_view: id = msg_send![ns_win, contentView];++ if content_view != nil {+ let _: () = msg_send![content_view, setWantsLayer: true];++ let layer: id = msg_send![content_view, layer];+ if layer != nil {+ let _: () = msg_send![layer, setCornerRadius: radius];+ let _: () = msg_send![layer, setMasksToBounds: true];++ let continuous = NSString::alloc(nil).init_str("continuous");+ let _: () = msg_send![layer, setCornerCurve: continuous];+ }+ }+ }+}+// pub fn get_ns_window_number(ns_window: *mut c_void) -> isize {// let ns_window = ns_window as *const objc2_app_kit::NSWindow;diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex 5a04018ae..7954acf2e 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -262,6 +262,7 @@ impl CapWindowId {}Self::RecordingControls => Some(Some(LogicalPosition::new(-100.0, -100.0))),Self::Camera+ | Self::Main| Self::WindowCaptureOccluder { .. }| Self::CaptureArea| Self::RecordingsOverlay@@ -480,6 +481,10 @@ impl ShowCapWindow {let title = CapWindowId::Main.title();let should_protect = should_protect_window(app, &title);+ #[cfg(target_os = "macos")]+ app.set_activation_policy(tauri::ActivationPolicy::Accessory)+ .ok();+let window = self.window_builder(app, "/").resizable(false)@@ -489,6 +494,8 @@ impl ShowCapWindow {.always_on_top(true).visible_on_all_workspaces(true).content_protected(should_protect)+ .transparent(true)+ .visible(false).initialization_script(format!("window.__CAP__ = window.__CAP__ ?? {{}};@@ -502,11 +509,47 @@ impl ShowCapWindow {let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 395.0);let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));- #[cfg(target_os = "macos")]- crate::platform::set_window_level(window.as_ref().window(), 50);-#[cfg(target_os = "macos")]{+ app.run_on_main_thread({+ let window = window.clone();+ let app = app.clone();+ move || {+ use tauri::ActivationPolicy;+ use tauri_nspanel::cocoa::appkit::NSWindowCollectionBehavior;+ use tauri_nspanel::panel_delegate;+ use tauri_nspanel::WebviewWindowExt as NSPanelWebviewWindowExt;++ const MAIN_PANEL_LEVEL: i32 = 100;++ let delegate = panel_delegate!(MainPanelDelegate {+ window_did_become_key,+ window_did_resign_key+ });++ delegate.set_listener(Box::new(|_delegate_name: String| {}));++ let panel = window.to_panel().unwrap();++ panel.set_collection_behaviour(+ NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces+ | NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenPrimary,+ );++ panel.set_delegate(delegate);++ panel.set_level(MAIN_PANEL_LEVEL);++ panel.order_front_regardless();+ panel.show();++ crate::platform::apply_squircle_corners(&window, 16.0);++ app.set_activation_policy(ActivationPolicy::Regular).ok();+ }+ })+ .ok();+let app_handle = app.clone();tauri::async_runtime::spawn(async move {let prewarmer =@@ -519,6 +562,11 @@ impl ShowCapWindow {}}+ #[cfg(not(target_os = "macos"))]+ {+ window.show().ok();+ }+window}Self::TargetSelectOverlay {