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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user