Place apps below the title bar, not behind it

A child webview is positioned against the window frame while the shell
measures the hole it left from inside the content view. Borderless, those
origins coincided and it never showed. With a title bar back they are a
title bar apart, so every app was drawn that much too high - painting
over the right-hand part of the bar, which read as the bar being tinted
by whichever site was open, and leaving a strip of the same height along
the bottom.

Tauri cannot report that height. Both inner_position/outer_position and
inner_size/outer_size come back identical on macOS - measured, both
differences were zero against a window whose content is plainly a title
bar shorter than its frame. NSWindow.contentLayoutRect knows, so it is
asked once and cached.

Also hides the window title, and centres the navigation row in its own
strip rather than letting it crowd the bar above it.
This commit is contained in:
2026-09-01 15:14:56 +02:00
parent 17d13d2505
commit 5eb9157b7e
7 changed files with 106 additions and 10 deletions
+12 -2
View File
@@ -17,6 +17,9 @@ pub struct AppState {
pub dir: PathBuf,
/// Corner radius the window's inner frame is currently drawn with.
pub radius: Mutex<f64>,
/// Title bar height: how far a child webview's origin sits above the
/// content the shell measures from.
pub chrome: Mutex<f64>,
pub config: Mutex<Config>,
pub active: Mutex<Option<String>>,
pub stage: Mutex<Stage>,
@@ -72,7 +75,8 @@ pub fn build_state(handle: &AppHandle) -> Result<AppState, String> {
let config = config::load(&dir)?;
Ok(AppState {
dir,
radius: Mutex::new(12.0),
radius: Mutex::new(0.0),
chrome: Mutex::new(0.0),
config: Mutex::new(config),
active: Mutex::new(None),
stage: Mutex::new((240.0, 38.0, 800.0, 600.0)),
@@ -524,9 +528,15 @@ pub fn notification_status(app: AppHandle) -> String {
let app_state = app.state::<AppState>();
let last = app_state.last_notification.lock().unwrap().clone();
let from_page = if last.is_empty() { "none yet".into() } else { last };
let stage = *app_state.stage.lock().unwrap();
let offset = webviews::chrome_offset(&app);
let shot = app_state.last_snapshot.lock().unwrap().clone();
let shot = if shot.is_empty() { "not taken".into() } else { shot };
format!("permission: {state} · direct: {raised} · from page: {from_page} · backdrop: {shot}")
format!(
"permission: {state} · direct: {raised} · from page: {from_page} · backdrop: {shot} \
· stage: {:.0},{:.0} {:.0}×{:.0} · chrome offset: {offset:.1}",
stage.0, stage.1, stage.2, stage.3
)
}
/// Asks macOS for notification permission, and claims this app's identity.
+7
View File
@@ -82,6 +82,13 @@ pub fn run() {
// the prompt does not arrive attached to someone else's message.
commands::ensure_notification_permission(&app.handle().clone());
// Measured once: every app is positioned against the window frame
// while the shell measures from inside the content view, and the
// two are a title bar apart.
let handle = app.handle().clone();
let chrome = webviews::measure_chrome(&handle);
*handle.state::<commands::AppState>().chrome.lock().unwrap() = chrome;
let theme = app.state::<commands::AppState>().cfg().settings.theme;
commands::apply_window_theme(&app.handle().clone(), &theme);
Ok(())
+65 -4
View File
@@ -587,7 +587,7 @@ pub fn create(
window
.add_child(
builder,
LogicalPosition::new(stage.0, stage.1),
LogicalPosition::new(stage.0, stage.1 + chrome_offset(handle)),
LogicalSize::new(stage.2, stage.3),
)
.map_err(|e| e.to_string())?;
@@ -601,6 +601,62 @@ pub fn create(
Ok(())
}
/// How far the window's frame sits above its content, in logical pixels.
///
/// A child webview is positioned against the window frame, but the shell
/// measures the hole it left from inside the content view — and with a title
/// bar those two origins are a title bar apart. Without this every app is drawn
/// a title bar too high: it paints over the right half of the bar, which is why
/// the bar looked like it was tinted by whichever site was open, and leaves an
/// empty strip of the same height along the bottom.
///
/// Asks AppKit how tall the title bar is, and remembers the answer.
///
/// Tauri cannot say. Both `inner_position`/`outer_position` and
/// `inner_size`/`outer_size` come back identical on macOS — measured, both
/// reported a difference of zero against a window whose content is plainly a
/// title bar shorter than its frame. `contentLayoutRect` is the one thing that
/// knows, so it is asked once and cached; the height does not change.
#[cfg(target_os = "macos")]
pub fn measure_chrome(handle: &AppHandle) -> f64 {
use objc2::runtime::AnyObject;
use objc2_foundation::NSRect;
let Some(wv) = handle.get_webview_window("main") else { return 0.0 };
let (tx, rx) = std::sync::mpsc::channel::<f64>();
let sent = wv.with_webview(move |platform| unsafe {
let view = platform.inner() as *mut AnyObject;
if view.is_null() {
let _ = tx.send(0.0);
return;
}
let window: *mut AnyObject = objc2::msg_send![view, window];
if window.is_null() {
let _ = tx.send(0.0);
return;
}
let frame: NSRect = objc2::msg_send![window, frame];
let content: NSRect = objc2::msg_send![window, contentLayoutRect];
let _ = tx.send((frame.size.height - content.size.height).max(0.0));
});
if sent.is_err() {
return 0.0;
}
rx.recv_timeout(std::time::Duration::from_millis(500)).unwrap_or(0.0)
}
#[cfg(not(target_os = "macos"))]
pub fn measure_chrome(_: &AppHandle) -> f64 {
0.0
}
/// How far the window's frame sits above its content, in logical pixels.
pub fn chrome_offset(handle: &AppHandle) -> f64 {
*handle.state::<crate::commands::AppState>().chrome.lock().unwrap()
}
fn radius(handle: &AppHandle) -> f64 {
*handle.state::<crate::commands::AppState>().radius.lock().unwrap()
}
@@ -623,9 +679,10 @@ pub fn show_only(
cfg: &Config,
stage: (f64, f64, f64, f64),
) {
let top = stage.1 + chrome_offset(handle);
for app in &cfg.apps {
let Some(wv) = handle.get_webview(&label_for(&app.id)) else { continue };
let _ = wv.set_position(LogicalPosition::new(stage.0, stage.1));
let _ = wv.set_position(LogicalPosition::new(stage.0, top));
let _ = wv.set_size(LogicalSize::new(stage.2, stage.3));
let _ = wv.set_zoom(app.zoom);
let _ = wv.show();
@@ -649,9 +706,10 @@ pub fn set_stage(
radius: f64,
) {
let cfg = handle.state::<crate::commands::AppState>().cfg();
let top = stage.1 + chrome_offset(handle);
for app in &cfg.apps {
let Some(wv) = handle.get_webview(&label_for(&app.id)) else { continue };
let _ = wv.set_position(LogicalPosition::new(stage.0, stage.1));
let _ = wv.set_position(LogicalPosition::new(stage.0, top));
let _ = wv.set_size(LogicalSize::new(stage.2, stage.3));
set_corner_radius(handle, &app.id, radius);
}
@@ -669,7 +727,10 @@ pub fn set_stage(
pub fn hide_all(handle: &AppHandle, cfg: &Config, stage: (f64, f64, f64, f64)) {
for app in &cfg.apps {
if let Some(wv) = handle.get_webview(&label_for(&app.id)) {
let _ = wv.set_position(LogicalPosition::new(stage.0, stage.1 + PARKED_OFFSET));
let _ = wv.set_position(LogicalPosition::new(
stage.0,
stage.1 + chrome_offset(handle) + PARKED_OFFSET,
));
}
// Nothing is on screen behind a dialog, so nothing should think it is.
set_page_visibility(handle, &app.id, false);