Skip to content

Commit

Permalink
fix: traffic light placement when non-fullscreen (#1680)
Browse files Browse the repository at this point in the history
* fix macos traffic lights (round 2)

* fix typo
  • Loading branch information
brxken128 committed Nov 3, 2023
1 parent 7dd164f commit 23e9cf0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
18 changes: 14 additions & 4 deletions apps/desktop/crates/macos/src-swift/window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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
}
2 changes: 1 addition & 1 deletion apps/desktop/crates/macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 9 additions & 3 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions interface/app/$libraryId/Layout/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand All @@ -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'
)}
/>
)}
Expand Down

0 comments on commit 23e9cf0

Please sign in to comment.