From 23e9cf0553ca82bb5ea7a708c2dd998b203ee59c Mon Sep 17 00:00:00 2001 From: jake <77554505+brxken128@users.noreply.github.com> Date: Fri, 3 Nov 2023 08:43:38 +0000 Subject: [PATCH] fix: traffic light placement when non-fullscreen (#1680) * fix macos traffic lights (round 2) * fix typo --- .../crates/macos/src-swift/window.swift | 18 ++++++++++++++---- apps/desktop/crates/macos/src/lib.rs | 2 +- apps/desktop/src-tauri/src/main.rs | 12 +++++++++--- .../app/$libraryId/Layout/Sidebar/index.tsx | 6 +++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/desktop/crates/macos/src-swift/window.swift b/apps/desktop/crates/macos/src-swift/window.swift index 7fd0383f750f..3a8523ebbd18 100644 --- a/apps/desktop/crates/macos/src-swift/window.swift +++ b/apps/desktop/crates/macos/src-swift/window.swift @@ -45,7 +45,17 @@ public func blurWindowBackground(window: NSWindow) { } @_cdecl("set_titlebar_style") -public func setTitlebarStyle(window: NSWindow, transparent: Bool) { - window.titleVisibility = transparent ? .hidden : .visible - window.titlebarAppearsTransparent = transparent -} \ No newline at end of file +public func setTitlebarStyle(window: NSWindow, fullScreen: Bool) { + // this results in far less visual artifacts if we just manage it ourselves (the native taskbar re-appears when fullscreening/un-fullscreening) + window.titlebarAppearsTransparent = true + if fullScreen { // fullscreen, give control back to the native OS + window.toolbar = nil + } else { // non-fullscreen + // here we create a uniquely identifiable invisible toolbar in order to correctly pad out the traffic lights + // this MUST be hidden while fullscreen as macos has a unique dropdown bar for that, and it's far easier to just let it do its thing + let toolbar = NSToolbar(identifier: "window_invisible_toolbar") + toolbar.showsBaselineSeparator = false + window.toolbar = toolbar + } + window.titleVisibility = fullScreen ? .visible : .hidden +} diff --git a/apps/desktop/crates/macos/src/lib.rs b/apps/desktop/crates/macos/src/lib.rs index a90833b6d0e9..66d9be3ada18 100644 --- a/apps/desktop/crates/macos/src/lib.rs +++ b/apps/desktop/crates/macos/src/lib.rs @@ -12,7 +12,7 @@ pub enum AppThemeType { swift!(pub fn lock_app_theme(theme_type: Int)); swift!(pub fn blur_window_background(window: &NSObject)); -swift!(pub fn set_titlebar_style(window: &NSObject, transparent: Bool)); +swift!(pub fn set_titlebar_style(window: &NSObject, is_fullscreen: Bool)); // swift!(pub fn setup_disk_watcher(window: &NSObject, transparent: Bool, large: Bool)); // swift!(pub fn disk_event_callback(mounted: Bool, path: &SRString)); swift!(pub fn reload_webview(webview: &NSObject)); diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index f6f94707851d..23b097bce9a0 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -270,20 +270,26 @@ async fn main() -> tauri::Result<()> { .on_menu_event(menu::handle_menu_event) .on_window_event(|event| { if let WindowEvent::Resized(_) = event.event() { - let command = if event + let (state, command) = if event .window() .is_fullscreen() .expect("Can't get fullscreen state") { - "window_fullscreened" + (true, "window_fullscreened") } else { - "window_not_fullscreened" + (false, "window_not_fullscreened") }; event .window() .emit("keybind", command) .expect("Unable to emit window event"); + + #[cfg(target_os = "macos")] + { + let nswindow = event.window().ns_window().unwrap(); + unsafe { sd_desktop_macos::set_titlebar_style(&nswindow, state) }; + } } }) .menu(menu::get_menu()) diff --git a/interface/app/$libraryId/Layout/Sidebar/index.tsx b/interface/app/$libraryId/Layout/Sidebar/index.tsx index dae6faa6daff..e307d55539bb 100644 --- a/interface/app/$libraryId/Layout/Sidebar/index.tsx +++ b/interface/app/$libraryId/Layout/Sidebar/index.tsx @@ -30,8 +30,8 @@ export default () => { className={clsx( 'relative flex min-h-full w-44 shrink-0 grow-0 flex-col gap-2.5 border-r border-sidebar-divider bg-sidebar px-2.5 pb-2 transition-[padding-top] ease-linear motion-reduce:transition-none', os === 'macOS' && windowState.isFullScreen - ? '-mt-2 pt-[8.75px] duration-300' - : 'pt-2 duration-300', + ? '-mt-2 pt-[8.75px] duration-100' + : 'pt-1 duration-75', os === 'macOS' || showControls.transparentBg ? 'bg-opacity-[0.65]' @@ -45,7 +45,7 @@ export default () => { data-tauri-drag-region className={clsx( 'w-full transition-[height] ease-linear motion-reduce:transition-none', - windowState.isFullScreen ? 'h-0 duration-300' : 'h-5 duration-300' + windowState.isFullScreen ? 'h-0 duration-100' : 'h-5 duration-75' )} /> )}