Skip to content

Commit

Permalink
macos: move ownership of fullscreenNotification observers to Terminal…
Browse files Browse the repository at this point in the history
…Controller

When processing toggle_fullscreen actions, multiple FullscreenStyle
derived objects would register observers on the same window and
subsequently remove them when the old style was deinited.

This change passes ownership of the fullscreenNotification observers to
TerminalController while still allowing FullscreenStyles access to the
window for style specific actions.
  • Loading branch information
gigamonster256 committed Dec 29, 2024
1 parent 5293fc9 commit deda56f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
19 changes: 19 additions & 0 deletions macos/Sources/Features/Terminal/TerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ class TerminalController: BaseTerminalController {
selector: #selector(onFrameDidChange),
name: NSView.frameDidChangeNotification,
object: nil)

center.addObserver(
self,
selector: #selector(didEnterFullScreenNotification),
name: NSWindow.didEnterFullScreenNotification,
object: window)
center.addObserver(
self,
selector: #selector(didExitFullScreenNotification),
name: NSWindow.didExitFullScreenNotification,
object: window)
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -686,6 +697,14 @@ class TerminalController: BaseTerminalController {
targetWindow.makeKeyAndOrderFront(nil)
}

@objc private func didEnterFullScreenNotification(_ notification: Notification) {
fullscreenDidChange()
}

@objc private func didExitFullScreenNotification(_ notification: Notification) {
fullscreenDidChange()
}

@objc private func onToggleFullscreen(notification: SwiftUI.Notification) {
guard let target = notification.object as? Ghostty.SurfaceView else { return }
guard target == self.focusedSurface else { return }
Expand Down
27 changes: 0 additions & 27 deletions macos/Sources/Helpers/Fullscreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,6 @@ class FullscreenBase {

required init?(_ window: NSWindow) {
self.window = window

// We want to trigger delegate methods on window native fullscreen
// changes (didEnterFullScreenNotification, etc.) no matter what our
// fullscreen style is.
let center = NotificationCenter.default
center.addObserver(
self,
selector: #selector(didEnterFullScreenNotification),
name: NSWindow.didEnterFullScreenNotification,
object: window)
center.addObserver(
self,
selector: #selector(didExitFullScreenNotification),
name: NSWindow.didExitFullScreenNotification,
object: window)
}

deinit {
NotificationCenter.default.removeObserver(self)
}

@objc private func didEnterFullScreenNotification(_ notification: Notification) {
delegate?.fullscreenDidChange()
}

@objc private func didExitFullScreenNotification(_ notification: Notification) {
delegate?.fullscreenDidChange()
}
}

Expand Down

0 comments on commit deda56f

Please sign in to comment.