Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

fix Tab Bar disappearing in Fullscreen Split View #1168

Merged
merged 7 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions DuckDuckGo/Main/View/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import Cocoa
import Combine
import Common

@MainActor
final class MainWindowController: NSWindowController {

private static let windowFrameSaveName = "MainWindow"
private var fireViewModel: FireViewModel
private static var knownFullScreenMouseDetectionWindows = Set<NSValue>()

var mainViewController: MainViewController {
// swiftlint:disable force_cast
Expand Down Expand Up @@ -207,6 +209,49 @@ extension MainWindowController: NSWindowDelegate {
mainViewController.tabBarViewController.draggingSpace.isHidden = true
}

func windowDidEnterFullScreen(_ notification: Notification) {
// fix NSToolbarFullScreenWindow occurring beneath the MainWindow
// https://app.asana.com/0/1177771139624306/1203853030672990/f
// NSApp should be active at the moment of window ordering otherwise toolbar would disappear on activation
for window in NSApp.windows {
let windowValue = NSValue(nonretainedObject: window)

guard window.className.contains("NSFullScreenMouseDetectionWindow"),
!Self.knownFullScreenMouseDetectionWindows.contains(windowValue),
window.screen == self.window!.screen else { continue }

// keep record of NSFullScreenMouseDetectionWindow to avoid adding other‘s windows
Self.knownFullScreenMouseDetectionWindows.insert(windowValue)
window.onDeinit {
Self.knownFullScreenMouseDetectionWindows.remove(windowValue)
}

// add NSFullScreenMouseDetectionWindow as a child window to activate the app without revealing all of its windows
let activeApp = NSWorkspace.shared.frontmostApplication
if activeApp != .current {
self.window!.addChildWindow(window, ordered: .above)
}

// remove the child window and reactivate initially active app as soon as current app becomes active
// otherwise the fullscreen will reactivate its Space when switching to window in another Space
var cancellable: AnyCancellable!
cancellable = NSApp.isActivePublisher().dropFirst().sink { [weak self, weak window] _ in
withExtendedLifetime(cancellable) {
if let activeApp, activeApp != .current {
activeApp.activate()
}

if let self, let window, self.window?.childWindows?.contains(window) == true {
self.window?.removeChildWindow(window)
}
cancellable = nil
}
}

break
}
}

func windowWillExitFullScreen(_ notification: Notification) {
mainViewController.tabBarViewController.draggingSpace.isHidden = false
}
Expand Down