From 9a52b90f04597fb7ee3cbc806404ac0984ebd50d Mon Sep 17 00:00:00 2001 From: Akemi Date: Sat, 20 Oct 2018 21:19:16 +0200 Subject: cocoa-cb: fix double clicking the title bar since we draw our own title bar we lose the standard functionality of the system provided title bar. because of that we have to reimplement the functionality of double clicking the title bar. depending on the system preferences we want to minimize, zoom or do nothing. Fixes #6223 --- video/out/cocoa-cb/window.swift | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'video/out/cocoa-cb/window.swift') diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift index b3e691b3a2..34a73f88d1 100644 --- a/video/out/cocoa-cb/window.swift +++ b/video/out/cocoa-cb/window.swift @@ -17,6 +17,31 @@ import Cocoa +class CustomTtitleBar: NSVisualEffectView { + + // catch these events so they are not propagated to the underlying view + override func mouseDown(with event: NSEvent) { } + + override func mouseUp(with event: NSEvent) { + if event.clickCount > 1 { + let def = UserDefaults.standard + var action = def.string(forKey: "AppleActionOnDoubleClick") + + // macOS 10.10 and earlier + if action == nil { + action = def.bool(forKey: "AppleMiniaturizeOnDoubleClick") == true ? + "Minimize" : "Maximize" + } + + if action == "Minimize" { + window!.miniaturize(self) + } else if action == "Maximize" { + window!.zoom(self) + } + } + } +} + class Window: NSWindow, NSWindowDelegate { weak var cocoaCB: CocoaCB! = nil @@ -113,7 +138,7 @@ class Window: NSWindow, NSWindowDelegate { styleMask.insert(.fullSizeContentView) titleBar.alphaValue = 0 titlebarAppearsTransparent = true - titleBarEffect = NSVisualEffectView(frame: f) + titleBarEffect = CustomTtitleBar(frame: f) titleBarEffect!.alphaValue = 0 titleBarEffect!.blendingMode = .withinWindow titleBarEffect!.autoresizingMask = [.viewWidthSizable, .viewMinYMargin] @@ -179,6 +204,7 @@ class Window: NSWindow, NSWindowDelegate { titleBar.animator().alphaValue = 1 if !isInFullscreen && !isAnimating { titleBarEffect!.animator().alphaValue = 1 + titleBarEffect!.isHidden = false } }, completionHandler: nil ) @@ -193,6 +219,7 @@ class Window: NSWindow, NSWindowDelegate { if titleBarEffect == nil { return } if isInFullscreen && !isAnimating { titleBarEffect!.alphaValue = 0 + titleBarEffect!.isHidden = true return } NSAnimationContext.runAnimationGroup({ (context) -> Void in @@ -201,6 +228,7 @@ class Window: NSWindow, NSWindowDelegate { titleBarEffect!.animator().alphaValue = 0 }, completionHandler: { self.titleButtons.forEach { $0.isHidden = true } + self.titleBarEffect!.isHidden = true }) } -- cgit v1.2.3