mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 22:33:42 +00:00
revert: remove macOS traffic light adjustments
This commit is contained in:
1 parent
1589d4cbe7
commit
0d08004c49
1 file changed
-79
@@ -4,12 +4,6 @@ import desktop_multi_window
|
|||||||
import window_manager
|
import window_manager
|
||||||
|
|
||||||
class MainFlutterWindow: NSWindow {
|
class MainFlutterWindow: NSWindow {
|
||||||
// Keep this in sync with AppDesignTokens.railWidth in Flutter.
|
|
||||||
private static let navigationRailWidth: CGFloat = 68
|
|
||||||
private static let trafficLightGap: CGFloat = 6
|
|
||||||
private var trafficLightLayoutScheduled = false
|
|
||||||
private var fullScreenTransitionInProgress = false
|
|
||||||
|
|
||||||
override func awakeFromNib() {
|
override func awakeFromNib() {
|
||||||
let flutterViewController = FlutterViewController()
|
let flutterViewController = FlutterViewController()
|
||||||
let windowFrame = self.frame
|
let windowFrame = self.frame
|
||||||
@@ -22,83 +16,10 @@ class MainFlutterWindow: NSWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.awakeFromNib()
|
super.awakeFromNib()
|
||||||
|
|
||||||
for name in [NSWindow.didResizeNotification, NSWindow.didBecomeKeyNotification,
|
|
||||||
NSWindow.didChangeBackingPropertiesNotification] {
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self, selector: #selector(refreshTrafficLightLayout(_:)), name: name, object: self)
|
|
||||||
}
|
|
||||||
for name in [NSWindow.willEnterFullScreenNotification, NSWindow.willExitFullScreenNotification] {
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self, selector: #selector(beginFullScreenTransition(_:)), name: name, object: self)
|
|
||||||
}
|
|
||||||
for name in [NSWindow.didEnterFullScreenNotification, NSWindow.didExitFullScreenNotification] {
|
|
||||||
NotificationCenter.default.addObserver(
|
|
||||||
self, selector: #selector(endFullScreenTransition(_:)), name: name, object: self)
|
|
||||||
}
|
|
||||||
scheduleTrafficLightLayout()
|
|
||||||
}
|
|
||||||
|
|
||||||
private func positionTrafficLights() {
|
|
||||||
// Let AppKit position controls in its own full-screen title bar.
|
|
||||||
guard !styleMask.contains(.fullScreen) else { return }
|
|
||||||
|
|
||||||
let buttons = [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton]
|
|
||||||
.compactMap { standardWindowButton($0) }
|
|
||||||
guard buttons.count == 3 else { return }
|
|
||||||
|
|
||||||
let width = buttons.reduce(CGFloat.zero) { $0 + $1.frame.width }
|
|
||||||
+ Self.trafficLightGap * CGFloat(buttons.count - 1)
|
|
||||||
var x = (Self.navigationRailWidth - width) / 2
|
|
||||||
guard x >= 0 else { return }
|
|
||||||
|
|
||||||
// Keep native sizes, vertical positions and button behavior intact.
|
|
||||||
for button in buttons {
|
|
||||||
var origin = button.frame.origin
|
|
||||||
origin.x = x
|
|
||||||
if button.frame.origin != origin {
|
|
||||||
button.setFrameOrigin(origin)
|
|
||||||
}
|
|
||||||
x += button.frame.width + Self.trafficLightGap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func refreshTrafficLightLayout(_ notification: Notification) {
|
|
||||||
scheduleTrafficLightLayout()
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func beginFullScreenTransition(_ notification: Notification) {
|
|
||||||
fullScreenTransitionInProgress = true
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func endFullScreenTransition(_ notification: Notification) {
|
|
||||||
fullScreenTransitionInProgress = false
|
|
||||||
scheduleTrafficLightLayout()
|
|
||||||
}
|
|
||||||
|
|
||||||
private func scheduleTrafficLightLayout() {
|
|
||||||
guard !trafficLightLayoutScheduled else { return }
|
|
||||||
trafficLightLayoutScheduled = true
|
|
||||||
// AppKit can reset button frames while finishing a resize or style change.
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.trafficLightLayoutScheduled = false
|
|
||||||
guard !self.fullScreenTransitionInProgress, !self.styleMask.contains(.fullScreen) else { return }
|
|
||||||
// Calling this is supported; overriding AppKit's layout entry point is not.
|
|
||||||
self.layoutIfNeeded()
|
|
||||||
self.positionTrafficLights()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
NotificationCenter.default.removeObserver(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) {
|
override public func order(_ place: NSWindow.OrderingMode, relativeTo otherWin: Int) {
|
||||||
super.order(place, relativeTo: otherWin)
|
super.order(place, relativeTo: otherWin)
|
||||||
hiddenWindowAtLaunch()
|
hiddenWindowAtLaunch()
|
||||||
if place == .above {
|
|
||||||
scheduleTrafficLightLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user