mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: clarify comments, clean up notifications for fullscreen
This commit is contained in:
@ -141,43 +141,25 @@ class NonNativeFullscreen: FullscreenStyle {
|
|||||||
// We hide the dock if the window is on a screen with the dock.
|
// We hide the dock if the window is on a screen with the dock.
|
||||||
if (savedState.dock) {
|
if (savedState.dock) {
|
||||||
hideDock()
|
hideDock()
|
||||||
|
|
||||||
// Hide the dock whenever this window becomes focused.
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(hideDock),
|
|
||||||
name: NSWindow.didBecomeMainNotification,
|
|
||||||
object: window)
|
|
||||||
|
|
||||||
// Unhide the dock whenever this window becomes unfocused.
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(unhideDock),
|
|
||||||
name: NSWindow.didResignMainNotification,
|
|
||||||
object: window)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide the menu if requested
|
// Hide the menu if requested
|
||||||
if (properties.hideMenu) {
|
if (properties.hideMenu) {
|
||||||
self.hideMenu()
|
hideMenu()
|
||||||
|
|
||||||
// Ensure that we always hide the menu bar for this window, but not for non fullscreen ones
|
|
||||||
// This is not the best way to do this, not least because it causes the menu to stay visible
|
|
||||||
// for a brief moment before being hidden in some cases (e.g. when switching spaces).
|
|
||||||
// If we end up adding a NSWindowDelegate to PrimaryWindow, then we may be better off
|
|
||||||
// handling this there.
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(Self.hideMenu),
|
|
||||||
name: NSWindow.didBecomeMainNotification,
|
|
||||||
object: window)
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self,
|
|
||||||
selector: #selector(windowDidResignMain),
|
|
||||||
name: NSWindow.didResignMainNotification,
|
|
||||||
object: window)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When this window becomes or resigns main we need to run some logic.
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
self,
|
||||||
|
selector: #selector(windowDidBecomeMain),
|
||||||
|
name: NSWindow.didBecomeMainNotification,
|
||||||
|
object: window)
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
self,
|
||||||
|
selector: #selector(windowDidResignMain),
|
||||||
|
name: NSWindow.didResignMainNotification,
|
||||||
|
object: window)
|
||||||
|
|
||||||
// When we change screens we need to redo everything.
|
// When we change screens we need to redo everything.
|
||||||
NotificationCenter.default.addObserver(
|
NotificationCenter.default.addObserver(
|
||||||
self,
|
self,
|
||||||
@ -297,19 +279,55 @@ class NonNativeFullscreen: FullscreenStyle {
|
|||||||
exit()
|
exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func windowDidBecomeMain(_ notification: Notification) {
|
||||||
|
guard let savedState else { return }
|
||||||
|
|
||||||
|
// This should always be true due to how we register but just be sure
|
||||||
|
guard let object = notification.object as? NSWindow,
|
||||||
|
object == window else { return }
|
||||||
|
|
||||||
|
// This is crazy but at least on macOS 15.0, you must hide the dock
|
||||||
|
// FIRST then hide the menu. If you do the opposite, it does not
|
||||||
|
// work.
|
||||||
|
|
||||||
|
if savedState.dock {
|
||||||
|
hideDock()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (properties.hideMenu) {
|
||||||
|
hideMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func windowDidResignMain(_ notification: Notification) {
|
||||||
|
guard let savedState else { return }
|
||||||
|
|
||||||
|
// This should always be true due to how we register but just be sure
|
||||||
|
guard let object = notification.object as? NSWindow,
|
||||||
|
object == window else { return }
|
||||||
|
|
||||||
|
if (properties.hideMenu) {
|
||||||
|
unhideMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
if savedState.dock {
|
||||||
|
unhideDock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Dock
|
// MARK: Dock
|
||||||
|
|
||||||
@objc private func hideDock() {
|
private func hideDock() {
|
||||||
NSApp.presentationOptions.insert(.autoHideDock)
|
NSApp.presentationOptions.insert(.autoHideDock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func unhideDock() {
|
private func unhideDock() {
|
||||||
NSApp.presentationOptions.remove(.autoHideDock)
|
NSApp.presentationOptions.remove(.autoHideDock)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Menu
|
// MARK: Menu
|
||||||
|
|
||||||
@objc func hideMenu() {
|
func hideMenu() {
|
||||||
NSApp.presentationOptions.insert(.autoHideMenuBar)
|
NSApp.presentationOptions.insert(.autoHideMenuBar)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,10 +335,6 @@ class NonNativeFullscreen: FullscreenStyle {
|
|||||||
NSApp.presentationOptions.remove(.autoHideMenuBar)
|
NSApp.presentationOptions.remove(.autoHideMenuBar)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func windowDidResignMain(_ notification: Notification) {
|
|
||||||
unhideMenu()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The state that must be saved for non-native fullscreen to exit fullscreen.
|
/// The state that must be saved for non-native fullscreen to exit fullscreen.
|
||||||
class SavedState {
|
class SavedState {
|
||||||
weak var screen: NSScreen?
|
weak var screen: NSScreen?
|
||||||
|
@ -1375,8 +1375,15 @@ keybind: Keybinds = .{},
|
|||||||
/// using a new space. It's faster than the native fullscreen mode since it
|
/// using a new space. It's faster than the native fullscreen mode since it
|
||||||
/// doesn't use animations.
|
/// doesn't use animations.
|
||||||
///
|
///
|
||||||
/// Warning: tabs do not work with a non-native fullscreen window. This
|
/// Important: tabs DO NOT WORK in this mode. Non-native fullscreen removes
|
||||||
/// can be fixed but is looking for contributors to help. See issue #392.
|
/// the titlebar and macOS native tabs require the titlebar. If you use tabs,
|
||||||
|
/// you should not use this mode.
|
||||||
|
///
|
||||||
|
/// If you fullscreen a window with tabs, the currently focused tab will
|
||||||
|
/// become fullscreen while the others will remain in a separate window in
|
||||||
|
/// the background. You can switch to that window using normal window-switching
|
||||||
|
/// keybindings such as command+tilde. When you exit fullscreen, the window
|
||||||
|
/// will return to the tabbed state it was in before.
|
||||||
///
|
///
|
||||||
/// Allowable values are:
|
/// Allowable values are:
|
||||||
///
|
///
|
||||||
|
Reference in New Issue
Block a user