Skip to content

Commit c46fb17

Browse files
authored
Merge pull request #3041 from wgqqqqq/wgq/fix-macos-titlebar-alignment
fix(desktop): align macOS window controls with toolbar
2 parents bedf3d8 + 0fecf99 commit c46fb17

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

‎src/apps/desktop/src/appearance.rs‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,36 @@ pub fn create_main_window(
546546

547547
#[cfg(not(debug_assertions))]
548548
let materialization_workbench = Arc::clone(&frontend_workbench);
549+
#[cfg(target_os = "macos")]
550+
let builder = {
551+
// Configure both Tao's native window and Wry's WebView. The builder's
552+
// traffic_light_position setter only configures Wry, so native window
553+
// lifecycle events otherwise restore the default button placement.
554+
let config = tauri::utils::config::WindowConfig {
555+
label: "main".into(),
556+
url: main_url,
557+
title_bar_style: tauri::TitleBarStyle::Overlay,
558+
hidden_title: true,
559+
// Native button center = inset + height / 2 - origin.y.
560+
// AppKit's 16pt button at y=6 needs 20.5 for the 45px toolbar.
561+
traffic_light_position: Some(tauri::utils::config::LogicalPosition {
562+
x: 12.0,
563+
y: 20.5,
564+
}),
565+
..Default::default()
566+
};
567+
match tauri::WebviewWindowBuilder::from_config(app_handle, &config) {
568+
Ok(builder) => builder,
569+
Err(error) => {
570+
error!("Failed to configure main window: {}", error);
571+
return;
572+
}
573+
}
574+
};
575+
#[cfg(not(target_os = "macos"))]
576+
let builder = tauri::WebviewWindowBuilder::new(app_handle, "main", main_url);
549577
#[allow(unused_mut)]
550-
let mut builder = tauri::WebviewWindowBuilder::new(app_handle, "main", main_url)
578+
let mut builder = builder
551579
.title("OpenBitFun")
552580
.inner_size(
553581
crate::MAIN_WINDOW_DEFAULT_WIDTH,
@@ -607,17 +635,6 @@ pub fn create_main_window(
607635
builder =
608636
builder.on_navigation(move |url| navigation_workbench.should_allow_main_navigation(url));
609637

610-
#[cfg(target_os = "macos")]
611-
{
612-
builder = builder
613-
.decorations(true)
614-
.title_bar_style(tauri::TitleBarStyle::Overlay)
615-
// Match the 45px toolbar row (layout.toolbar.mdHeight) used by
616-
// NavBar and SceneTopBar, including when the sidebar is collapsed.
617-
.traffic_light_position(tauri::LogicalPosition::new(12.0, 22.5))
618-
.hidden_title(true);
619-
}
620-
621638
#[cfg(target_os = "windows")]
622639
{
623640
builder = builder.decorations(false);

0 commit comments

Comments
 (0)