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.
This commit is contained in:
der richter 2020-11-07 14:26:14 +01:00
parent 19913921eb
commit d0a2661c5b
1 changed files with 32 additions and 0 deletions

View File

@ -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"