add theme titlebar height and app-owned strip dragging

This commit is contained in:
2026-11-03 08:15:23 +07:00
parent 6d7b9fbf24
commit 1340dcf3e9
12 changed files with 114 additions and 26 deletions
+43 -9
View File
@@ -1,17 +1,17 @@
//! The window controls: minimize, maximize/restore, close — in the platform's
//! own dress and behavior. The titlebar strips drag the window themselves via
//! `WindowControlArea::Drag`; macOS draws its traffic lights in the shell's
//! reserved pad and needs no controls of ours.
//! own dress and behavior. Titlebar strips are app-owned: they move the
//! window themselves via [`titlebar_strip`], so a dragged tab or button press
//! never moves it; macOS draws its traffic lights in the shell's reserved pad
//! and needs no controls of ours.
use gpui::{App, ClickEvent, ElementId, IntoElement, RenderOnce, Window, div};
use gpui::WindowControlArea;
use gpui::{App, ClickEvent, Div, ElementId, IntoElement, RenderOnce, Stateful, Window, div};
use gpui::{InteractiveElement as _, MouseButton, StatefulInteractiveElement as _};
#[cfg(any(target_os = "windows", target_os = "linux"))]
use gpui::prelude::FluentBuilder as _;
#[cfg(any(target_os = "windows", target_os = "linux"))]
use gpui::{
AnyElement, InteractiveElement as _, ParentElement as _, StatefulInteractiveElement as _,
Styled as _,
};
use gpui::{AnyElement, ParentElement as _};
#[cfg(any(target_os = "windows", target_os = "linux"))]
use gpui_native_icons::{IconRole, icon};
#[cfg(any(target_os = "windows", target_os = "linux"))]
@@ -20,7 +20,7 @@ use gpui_native_theme::ActiveTheme as _;
#[cfg(target_os = "linux")]
use gpui::Decorations;
#[cfg(target_os = "windows")]
use gpui::{WindowControlArea, px, rgba};
use gpui::rgba;
/// macOS traffic-lights zone: the pad a leading titlebar strip reserves.
pub const TRAFFIC_LIGHT_PAD: f32 = 78.0;
@@ -164,6 +164,40 @@ pub fn maximize_on_double_click() -> impl Fn(&ClickEvent, &mut Window, &mut App)
}
}
/// Makes an element a titlebar strip: pressing and dragging it moves the
/// window, double-clicking maximizes, and Windows keeps its native caption
/// behavior through the `Drag` control area.
pub fn titlebar_strip(this: Stateful<Div>, window: &mut Window, cx: &mut App) -> Stateful<Div> {
let should_move = window.use_state(cx, |_, _| false);
this.window_control_area(WindowControlArea::Drag)
.on_mouse_down_out(window.listener_for(&should_move, |should_move, _, _, _| {
*should_move = false;
}))
.on_mouse_down(
MouseButton::Left,
window.listener_for(&should_move, |should_move, _, _, _| {
*should_move = true;
}),
)
.on_mouse_up(
MouseButton::Left,
window.listener_for(&should_move, |should_move, _, _, _| {
*should_move = false;
}),
)
.on_mouse_move(
window.listener_for(&should_move, |should_move, _, window, cx| {
if *should_move {
*should_move = false;
if !cx.has_active_drag() {
window.start_window_move();
}
}
}),
)
.on_click(maximize_on_double_click())
}
/// One Windows caption button.
#[cfg(target_os = "windows")]
fn caption_button(