fix: restore comfortable tab height with native control alignment
Verify Tessera GUI / verify (push) Failing after 1m39s
Verify Tessera GUI / verify (push) Failing after 1m39s
This commit is contained in:
@@ -1071,6 +1071,8 @@ impl TesseraApp {
|
||||
.with_fullsize_content_view(true)
|
||||
};
|
||||
let window = Arc::new(event_loop.create_window(attributes)?);
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::native_chrome::align_controls(&window);
|
||||
let context = Context::new(window.clone()).map_err(|error| anyhow::anyhow!("{error}"))?;
|
||||
let surface =
|
||||
Surface::new(&context, window.clone()).map_err(|error| anyhow::anyhow!("{error}"))?;
|
||||
@@ -1111,6 +1113,10 @@ impl TesseraApp {
|
||||
}
|
||||
|
||||
fn redraw(&mut self) {
|
||||
#[cfg(target_os = "macos")]
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
crate::native_chrome::align_controls(window);
|
||||
}
|
||||
match self.try_redraw() {
|
||||
Ok(()) => {
|
||||
if self.window.is_some() && self.surface.is_some() {
|
||||
|
||||
@@ -15,6 +15,8 @@ mod geometry;
|
||||
mod io_tasks;
|
||||
mod layout;
|
||||
mod mount;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod native_chrome;
|
||||
mod native_visual;
|
||||
mod object_list;
|
||||
mod presentation;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//! Keep AppKit's real window buttons aligned with the custom tab strip.
|
||||
use objc2_app_kit::{NSView, NSWindowButton, NSWindowStyleMask};
|
||||
use objc2_foundation::NSPoint;
|
||||
use winit::{
|
||||
raw_window_handle::{HasWindowHandle, RawWindowHandle},
|
||||
window::Window,
|
||||
};
|
||||
|
||||
/// Called only on winit's main thread, after native creation and before drawing.
|
||||
/// AppKit can restore its default button positions when laying out the title bar.
|
||||
pub fn align_controls(window: &Window) {
|
||||
let Ok(handle) = window.window_handle() else {
|
||||
return;
|
||||
};
|
||||
let RawWindowHandle::AppKit(handle) = handle.as_raw() else {
|
||||
return;
|
||||
};
|
||||
// SAFETY: winit owns this NSView for the lifetime of the borrowed Window.
|
||||
// All AppKit access is on the event-loop thread; no native pointers escape.
|
||||
unsafe {
|
||||
let view = &*handle.ns_view.as_ptr().cast::<NSView>();
|
||||
let Some(native) = view.window() else {
|
||||
return;
|
||||
};
|
||||
// Fullscreen traffic lights belong to AppKit's separate floating toolbar.
|
||||
if native.styleMask().contains(NSWindowStyleMask::FullScreen) {
|
||||
return;
|
||||
}
|
||||
let bounds = view.bounds();
|
||||
let center = f64::from(crate::tabs::HEIGHT) / 2.0;
|
||||
let content_y = if view.isFlipped() {
|
||||
bounds.origin.y + center
|
||||
} else {
|
||||
bounds.origin.y + bounds.size.height - center
|
||||
};
|
||||
for kind in [
|
||||
NSWindowButton::NSWindowCloseButton,
|
||||
NSWindowButton::NSWindowMiniaturizeButton,
|
||||
NSWindowButton::NSWindowZoomButton,
|
||||
] {
|
||||
let Some(button) = native.standardWindowButton(kind) else {
|
||||
continue;
|
||||
};
|
||||
let Some(parent) = button.superview() else {
|
||||
continue;
|
||||
};
|
||||
let target = parent.convertPoint_fromView(NSPoint::new(0.0, content_y), Some(view));
|
||||
let frame = button.frame();
|
||||
let y = target.y - frame.size.height / 2.0;
|
||||
// Preserve native button size, horizontal spacing and behavior.
|
||||
if (frame.origin.y - y).abs() > 0.01 {
|
||||
button.setFrameOrigin(NSPoint::new(frame.origin.x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,10 +203,13 @@ fn rounded_rect_contains(rect: Rect, radius: f32, x: f32, y: f32) -> bool {
|
||||
return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
let closest_x = x.clamp(rect.x + radius, rect.x + rect.width - radius);
|
||||
let closest_y = y.clamp(rect.y + radius, rect.y + rect.height - radius);
|
||||
let dx = x - closest_x;
|
||||
let dy = y - closest_y;
|
||||
// Clamp in local coordinates: adding a large origin to a shrinking tab's
|
||||
// half-width can otherwise round the lower bound above the upper bound.
|
||||
let radius = radius.min(rect.width / 2.0).min(rect.height / 2.0);
|
||||
let local_x = x - rect.x;
|
||||
let local_y = y - rect.y;
|
||||
let dx = local_x - local_x.clamp(radius, rect.width - radius);
|
||||
let dy = local_y - local_y.clamp(radius, rect.height - radius);
|
||||
dx * dx + dy * dy <= radius * radius
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -9,8 +9,8 @@ use serde::{Deserialize, Serialize};
|
||||
mod motion;
|
||||
pub use motion::{Motion, Visual};
|
||||
|
||||
// AppKit traffic lights are centered 14 logical pixels below the top edge.
|
||||
pub const HEIGHT: f32 = 28.0;
|
||||
// Native traffic lights and all tab controls share this row's center line.
|
||||
pub const HEIGHT: f32 = 40.0;
|
||||
pub const INSET: f32 = 8.0;
|
||||
const NEW_TAB_SPACE: f32 = 44.0;
|
||||
const MIN_WIDTH: f32 = 88.0;
|
||||
@@ -129,7 +129,7 @@ fn items(start: Option<f32>, tabs: &[Tab], width: f32) -> Vec<Item<'_>> {
|
||||
.collect()
|
||||
}
|
||||
fn pill_rect(rect: Rect) -> Rect {
|
||||
Rect::new(rect.x + 2.0, 2.0, (rect.width - 4.0).max(0.0), HEIGHT - 4.0)
|
||||
Rect::new(rect.x + 2.0, 4.0, (rect.width - 4.0).max(0.0), HEIGHT - 8.0)
|
||||
}
|
||||
fn close_rect(rect: Rect) -> Rect {
|
||||
Rect::new(
|
||||
@@ -236,13 +236,18 @@ pub fn draw_insertion(
|
||||
|
||||
pub fn plus_rect(start: Option<f32>, tabs: &[Tab], width: f32) -> Rect {
|
||||
if tabs.len() as f32 * tab_width(tabs, width) > viewport(width).width {
|
||||
return Rect::new(width - 34.0, 2.0, 24.0, HEIGHT - 4.0);
|
||||
return Rect::new(width - 34.0, (HEIGHT - 28.0) / 2.0, 24.0, 28.0);
|
||||
}
|
||||
let end = items(start, tabs, width)
|
||||
.iter()
|
||||
.map(|item| item.rect.x + item.rect.width)
|
||||
.fold(LEADING, f32::max);
|
||||
Rect::new((end + 4.0).min(width - 34.0), 2.0, 24.0, HEIGHT - 4.0)
|
||||
Rect::new(
|
||||
(end + 4.0).min(width - 34.0),
|
||||
(HEIGHT - 28.0) / 2.0,
|
||||
24.0,
|
||||
28.0,
|
||||
)
|
||||
}
|
||||
|
||||
fn tab_style() -> TextStyle {
|
||||
|
||||
Reference in New Issue
Block a user