Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/desktop-gpui/src/app_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ pub const CONTROLS_HEIGHT: f32 = 150.;
const CONTROLS_BOTTOM_OFFSET: f64 = 120.;
const TARGET_CONTROLS_OFFSET_Y: f64 = 48.;

fn controls_height() -> f32 {
if crate::controls_window::FIT_WINDOW_TO_CONTENT {
crate::controls_window::CONTROLS_BAR_HEIGHT + crate::controls_window::CONTROLS_PADDING * 2.
} else {
CONTROLS_HEIGHT
}
}

#[cfg(any(target_os = "macos", test))]
mod editor_placement;

Expand Down Expand Up @@ -6666,7 +6674,7 @@ fn controls_origin(config: &StartConfig) -> (f64, f64) {
use cap_recording::sources::screen_capture::ScreenCaptureTarget;

let width = CONTROLS_WIDTH as f64;
let height = CONTROLS_HEIGHT as f64;
let height = controls_height() as f64;

if let ScreenCaptureTarget::Window { id } = &config.target
&& let Some(window) = scap_targets::Window::from_id(id)
Expand Down Expand Up @@ -6705,7 +6713,7 @@ fn open_controls(
let (x, y) = controls_origin(config);
let bounds = Bounds {
origin: point(px(x as f32), px(y as f32)),
size: size(px(CONTROLS_WIDTH), px(CONTROLS_HEIGHT)),
size: size(px(CONTROLS_WIDTH), px(controls_height())),
};
let display = config
.target
Expand Down
37 changes: 30 additions & 7 deletions apps/desktop-gpui/src/controls_window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The in-progress recording bar -- `in-progress-recording.tsx`, natively.
//!
//! A 320x150 transparent panel whose visible content is a 40px card hugging the
//! A transparent panel whose visible content is a 40px card hugging the
//! bottom: stop button with the elapsed timer on the left, mic indicator and
//! action buttons on the right, a drag handle on the trailing edge. The window
//! itself is a non-activating panel at the maximum window level (see
Expand All @@ -12,7 +12,7 @@ use std::time::Duration;
use gpui::{
AppContext as _, Context, Entity, FontWeight, InteractiveElement as _, IntoElement,
MouseButton, ParentElement as _, Render, SharedString, StatefulInteractiveElement as _, Styled,
Window, div, prelude::FluentBuilder as _, px, svg,
Window, div, prelude::FluentBuilder as _, px, size, svg,
};

use crate::i18n::tr;
Expand All @@ -25,6 +25,11 @@ use crate::{
ui,
};

pub const CONTROLS_PADDING: f32 = 12.;
pub const CONTROLS_BAR_HEIGHT: f32 = 40.;

pub const FIT_WINDOW_TO_CONTENT: bool = cfg!(target_os = "macos");

pub struct ControlsWindow {
session: Entity<RecordingSession>,
theme: Theme,
Expand Down Expand Up @@ -391,7 +396,7 @@ impl ControlsWindow {
};

div()
.h(px(40.))
.h(px(CONTROLS_BAR_HEIGHT))
.flex_shrink_0()
.w_full()
.flex()
Expand Down Expand Up @@ -518,12 +523,11 @@ impl Render for ControlsWindow {
.then(|| tr::controls::low_storage().to_owned())
});

div()
.size_full()
let content = div()
.flex()
.flex_col()
.justify_end()
.p(px(12.))
.p(px(CONTROLS_PADDING))
.font_family(crate::theme::UI_FONT)
.locale_font()
// `body { font-weight: 500 }` (`ui-solid/src/main.css:189-192`).
Expand Down Expand Up @@ -554,7 +558,26 @@ impl Render for ControlsWindow {
.child(recording_issue_text(issue)),
)
})
.child(self.render_bar(cx))
.child(self.render_bar(cx));

if !FIT_WINDOW_TO_CONTENT {
return content.size_full();
}

// Transparent areas still take clicks on macOS, so the window hugs its content (#3357).
div()
.size_full()
.relative()
.child(content.absolute().left_0().right_0().bottom_0())
.on_children_prepainted(|bounds, window, _| {
let Some(content) = bounds.first() else {
return;
};
let height = content.size.height.ceil();
if (window.viewport_size().height - height).abs() >= px(1.) {
window.resize(size(px(crate::app_windows::CONTROLS_WIDTH), height));
}
})
}
}

Expand Down