Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop-gpui): choose what happens after a screenshot or Studio recording

Richie McIlroyb6bdf2c60f77
diff --git a/apps/desktop-gpui/src/app_windows.rs b/apps/desktop-gpui/src/app_windows.rs
index d36d08c22..79ac7abca 100644
--- a/apps/desktop-gpui/src/app_windows.rs
+++ b/apps/desktop-gpui/src/app_windows.rs
@@ -246,6 +246,10 @@ pub struct AppWindows {
/// tray path): the Tauri effect does the same, which is why cancelling a
/// tray-opened picker reveals the main window.
pub main_hidden_for_picker: bool,
+ /// Whether the main window was on screen when the picker hid it. Only the
+ /// copy/save screenshot finish reads it; the cancel reveal keeps the
+ /// Tauri behaviour above.
+ pub main_visible_before_picker: bool,
/// `hiddenForPicker` in the editor's record modal
/// (`ClipsSidebar.tsx:311-341, 413-426`): the editor window that hid
/// itself for an editor-owned target picker ("Record a new clip"). A
@@ -518,6 +522,7 @@ pub fn init(main: WindowHandle<MainWindow>, session: Entity<RecordingSession>, c
preparing_cleanup: crate::editor_preparing::PreparingCleanupRegistry::default(),
screenshot_editors: Vec::new(),
main_hidden_for_picker: false,
+ main_visible_before_picker: false,
editor_hidden_for_picker: None,
camera_park: CameraPark::default(),
#[cfg(target_os = "linux")]
@@ -606,15 +611,20 @@ pub fn init(main: WindowHandle<MainWindow>, session: Entity<RecordingSession>, c
// default): a cleanly-stopped studio recording goes straight
// to the editor, main window staying hidden --
// `editor_closed` brings it back once the last editor goes
- // away. Every other path (instant, failures, `showOverlay`
+ // away. `doNothing` leaves it in the library with Cap out of
+ // the way. Every other path (instant, failures, `showOverlay`
// until an overlay exists) reshows the main window as before.
- let editor_project = finished_studio.filter(|_| {
- crate::store::GeneralSettings::load().post_studio_recording_behaviour
- == crate::store::PostStudioBehaviour::OpenEditor
- });
- match editor_project {
- Some(project_dir) => open_editor(project_dir, cx),
- None => show_main_window(cx),
+ let behaviour =
+ crate::store::GeneralSettings::load().post_studio_recording_behaviour;
+ match (finished_studio, behaviour) {
+ (Some(project_dir), crate::store::PostStudioBehaviour::OpenEditor) => {
+ open_editor(project_dir, cx)
+ }
+ (Some(_), crate::store::PostStudioBehaviour::DoNothing) => {
+ park_idle_camera_preview(cx);
+ crate::menus::schedule_dock_sync(cx);
+ }
+ _ => show_main_window(cx),
}
}
// `NewStudioRecordingAdded` -> `add_new_item_to_cache` +
@@ -1870,7 +1880,15 @@ pub fn open_target_overlays(request: OverlayRequest, cx: &mut App) {
// (`new-main/index.tsx:2024-2028`): the picker owns the screen; the main
// window would otherwise float above the overlays at level 100.
if RecordingSession::global(cx).read(cx).phase == Phase::Idle {
- cx.global_mut::<AppWindows>().main_hidden_for_picker = true;
+ let main = cx.global::<AppWindows>().main;
+ // No visibility probe on Linux; keep revealing there as before.
+ let visible = cfg!(target_os = "linux")
+ || main
+ .update(cx, |_, window, _| platform::window_is_visible(window))
+ .unwrap_or(true);
+ let windows = cx.global_mut::<AppWindows>();
+ windows.main_hidden_for_picker = true;
+ windows.main_visible_before_picker = visible;
hide_main_window(cx);
}
}
@@ -2693,6 +2711,7 @@ fn own_windows(cx: &mut App) -> Vec<OwnWindowHandle> {
preparing_cleanup: _,
screenshot_editors,
main_hidden_for_picker: _,
+ main_visible_before_picker: _,
editor_hidden_for_picker: _,
camera_park: _,
#[cfg(target_os = "linux")]
@@ -6485,11 +6504,31 @@ pub fn screenshot_finished(captured: Option<PathBuf>, cx: &mut App) {
main.update(cx, |view, window, cx| view.refresh_open_library(window, cx))
.ok();
- // The editor owns the foreground now, the way a stopped studio recording
- // hands off to the video editor; `screenshot_editor_closed` brings the
- // main window back.
- cx.global_mut::<AppWindows>().main_hidden_for_picker = false;
- open_screenshot_editor(png, cx);
+ let behaviour = crate::store::GeneralSettings::load().post_screenshot_behaviour;
+ if behaviour.copies()
+ && let Err(error) = platform::copy_image_to_clipboard(&png, cx)
+ {
+ tracing::error!("copying the screenshot to the clipboard failed: {error}");
+ }
+
+ if behaviour.opens_editor() {
+ // The editor owns the foreground now, the way a stopped studio
+ // recording hands off to the video editor; `screenshot_editor_closed`
+ // brings the main window back.
+ cx.global_mut::<AppWindows>().main_hidden_for_picker = false;
+ open_screenshot_editor(png, cx);
+ return;
+ }
+
+ // Copy or save only: put the main window back only if it was actually on
+ // screen before the picker hid it, so a shortcut pressed from another app
+ // leaves that app in front.
+ let windows = cx.global_mut::<AppWindows>();
+ let hidden = std::mem::take(&mut windows.main_hidden_for_picker);
+ let was_visible = std::mem::take(&mut windows.main_visible_before_picker);
+ if hidden && was_visible && RecordingSession::global(cx).read(cx).phase == Phase::Idle {
+ show_main_window(cx);
+ }
}
/// Open (or focus) the screenshot editor for a bundle -- the
diff --git a/apps/desktop-gpui/src/settings_window.rs b/apps/desktop-gpui/src/settings_window.rs
index 178fec4fa..d61a57349 100644
--- a/apps/desktop-gpui/src/settings_window.rs
+++ b/apps/desktop-gpui/src/settings_window.rs
@@ -3472,16 +3472,11 @@ impl SettingsWindow {
)
.into_any_element(),
),
- // Deviation: general.tsx puts an "After a Studio
- // recording" select here (Open editor / Show in overlay).
- // The post-capture recordings overlay does not exist in
- // this app -- a product decision, not a gap -- so a
- // one-option select would be noise and the row is omitted.
- // The stored `postStudioRecordingBehaviour` is left
- // exactly as the Tauri app wrote it (this page never
- // writes the key), and the stop flow treats a stored
- // `showOverlay` as "reshow the main window"
- // (`app_windows.rs`).
+ // "After a Studio recording" lives on the Shortcuts page,
+ // next to the shortcuts it shapes. There is no
+ // post-capture overlay in this app, so a stored
+ // `showOverlay` means "reshow the main window"
+ // (`app_windows.rs`) and is labelled "Show Cap".
self.setting_row(
"After deleting a recording",
Some("Whether the recording window should reopen."),
diff --git a/apps/desktop-gpui/src/store.rs b/apps/desktop-gpui/src/store.rs
index 18ba80f3a..52dc02a8b 100644
--- a/apps/desktop-gpui/src/store.rs
+++ b/apps/desktop-gpui/src/store.rs
@@ -658,11 +658,34 @@ settings_enum! {
/// `PostStudioRecordingBehaviour`.
PostStudioBehaviour {
OpenEditor = "openEditor", "Open editor";
- ShowOverlay = "showOverlay", "Show in overlay";
+ ShowOverlay = "showOverlay", "Show Cap";
+ DoNothing = "doNothing", "Do nothing";
+ }
+ default = OpenEditor
+}
+
+settings_enum! {
+ /// What a finished screenshot does next. GPUI-only: the Tauri app always
+ /// opened the editor and never reads this key.
+ PostScreenshotBehaviour {
+ OpenEditor = "openEditor", "Open editor";
+ Copy = "copy", "Copy to clipboard";
+ CopyAndOpenEditor = "copyAndOpenEditor", "Copy and open editor";
+ Save = "save", "Do nothing";
}
default = OpenEditor
}
+impl PostScreenshotBehaviour {
+ pub fn copies(self) -> bool {
+ matches!(self, Self::Copy | Self::CopyAndOpenEditor)
+ }
+
+ pub fn opens_editor(self) -> bool {
+ matches!(self, Self::OpenEditor | Self::CopyAndOpenEditor)
+ }
+}
+
settings_enum! {
/// `PostDeletionBehaviour`.
PostDeletionBehaviour {
@@ -845,6 +868,7 @@ pub struct GeneralSettings {
pub recording_countdown: Option<u32>,
pub main_window_recording_start_behaviour: MainWindowStartBehaviour,
pub post_studio_recording_behaviour: PostStudioBehaviour,
+ pub post_screenshot_behaviour: PostScreenshotBehaviour,
pub post_deletion_behaviour: PostDeletionBehaviour,
pub delete_instant_recordings_after_upload: bool,
pub crash_recovery_recording: bool,
@@ -1176,6 +1200,7 @@ impl GeneralSettings {
"mainWindowRecordingStartBehaviour",
),
post_studio_recording_behaviour: enum_at(general, "postStudioRecordingBehaviour"),
+ post_screenshot_behaviour: enum_at(general, "postScreenshotBehaviour"),
post_deletion_behaviour: enum_at(general, "postDeletionBehaviour"),
delete_instant_recordings_after_upload: bool_at(
general,