diff options
author | der richter <der.richter@gmx.de> | 2020-11-07 14:26:14 +0100 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2020-11-07 21:38:35 +0100 |
commit | d0a2661c5b4adc4706b61a5cc86e73448fa936ea (patch) | |
tree | 901fd05c2e5adca7ea96a1e15cd0aea97010f173 /video/out/mac/common.swift | |
parent | 19913921eb9ee4c35de230c62c46d1591cf3326e (diff) | |
download | mpv-d0a2661c5b4adc4706b61a5cc86e73448fa936ea.tar.bz2 mpv-d0a2661c5b4adc4706b61a5cc86e73448fa936ea.tar.xz |
mac: make focus property observable
i missed the VO_EVENT_FOCUS event and the possibility to observe this
property and didn't include it in my initial focus commit for that
matter.
Diffstat (limited to 'video/out/mac/common.swift')
-rw-r--r-- | video/out/mac/common.swift | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 7b3c0fa10d..cb1b74b196 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -38,6 +38,8 @@ class Common: NSObject { var displaySleepAssertion: IOPMAssertionID = IOPMAssertionID(0) + var appNotificationObservers: [NSObjectProtocol] = [] + var cursorVisibilityWanted: Bool = true var title: String = "mpv" { @@ -57,6 +59,7 @@ class Common: NSObject { startDisplayLink(vo) initLightSensor() addDisplayReconfigureObserver() + addAppNotifications() mpv.setMacOptionCallback(macOptsWakeupCallback, context: self) } @@ -152,6 +155,7 @@ class Common: NSObject { stopDisplaylink() uninitLightSensor() removeDisplayReconfigureObserver() + removeAppNotifications() enableDisplaySleep() window?.orderOut(nil) @@ -347,6 +351,34 @@ class Common: NSObject { CGDisplayRemoveReconfigurationCallback(reconfigureCallback, MPVHelper.bridge(obj: self)) } + func addAppNotifications() { + appNotificationObservers.append(NotificationCenter.default.addObserver( + forName: NSApplication.didBecomeActiveNotification, + object: nil, + queue: .main, + using: { [weak self] (_) in self?.appDidBecomeActive() } + )) + appNotificationObservers.append(NotificationCenter.default.addObserver( + forName: NSApplication.didResignActiveNotification, + object: nil, + queue: .main, + using: { [weak self] (_) in self?.appDidResignActive() } + )) + } + + func removeAppNotifications() { + appNotificationObservers.forEach { NotificationCenter.default.removeObserver($0) } + appNotificationObservers.removeAll() + } + + func appDidBecomeActive() { + flagEvents(VO_EVENT_FOCUS) + } + + func appDidResignActive() { + flagEvents(VO_EVENT_FOCUS) + } + func setAppIcon() { if let app = NSApp as? Application, ProcessInfo.processInfo.environment["MPVBUNDLE"] != "true" |