cocoa-cb: use EventHelper for event handling

This commit is contained in:
der richter 2024-03-23 22:27:21 +01:00
parent 2a4bf7ca22
commit 5ab3060961
3 changed files with 15 additions and 26 deletions

View File

@ -20,6 +20,7 @@ class AppHub: NSObject {
var mpv: OpaquePointer?
@objc var input: InputHelper
var event: EventHelper?
#if HAVE_MACOS_MEDIA_PLAYER
var remote: RemoteCommandCenter?
#endif
@ -31,21 +32,16 @@ class AppHub: NSObject {
}
@objc func initMpv(_ mpv: OpaquePointer) {
if isApplication {
self.mpv = mpv
mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE)
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE)
mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE)
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG)
mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING)
mpv_observe_property(mpv, 0, "chapter-metadata/title", MPV_FORMAT_STRING)
mpv_observe_property(mpv, 0, "metadata/by-key/album", MPV_FORMAT_STRING)
mpv_observe_property(mpv, 0, "metadata/by-key/artist", MPV_FORMAT_STRING)
mpv_set_wakeup_callback(mpv, wakeup, TypeHelper.bridge(obj: self))
return
}
mpv_destroy(mpv)
self.mpv = mpv
mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE)
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE)
mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE)
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG)
mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING)
mpv_observe_property(mpv, 0, "chapter-metadata/title", MPV_FORMAT_STRING)
mpv_observe_property(mpv, 0, "metadata/by-key/album", MPV_FORMAT_STRING)
mpv_observe_property(mpv, 0, "metadata/by-key/artist", MPV_FORMAT_STRING)
event = EventHelper(mpv)
}
@objc func initInput(_ input: OpaquePointer?) {

View File

@ -166,9 +166,6 @@ static const char mac_icon[] =
#if HAVE_MACOS_TOUCHBAR
[(TouchBar *)self.touchBar processEvent:event];
#endif
if (_cocoa_cb) {
[_cocoa_cb processEvent:event];
}
}
- (void)initCocoaCb:(struct mpv_handle *)ctx

View File

@ -17,7 +17,7 @@
import Cocoa
class CocoaCB: Common {
class CocoaCB: Common, EventSubscriber {
var libmpv: LibmpvHelper
var layer: GLLayer?
@ -37,6 +37,7 @@ class CocoaCB: Common {
libmpv = LibmpvHelper(mpvHandle, newlog)
super.init(option, newlog)
layer = GLLayer(cocoaCB: self)
AppHub.shared.event?.subscribe(self, event: .init(name: "MPV_EVENT_SHUTDOWN"))
}
func preinit(_ vo: UnsafeMutablePointer<vo>) {
@ -221,12 +222,7 @@ class CocoaCB: Common {
}
}
@objc func processEvent(_ event: UnsafePointer<mpv_event>) {
switch event.pointee.event_id {
case MPV_EVENT_SHUTDOWN:
shutdown()
default:
break
}
func handle(event: EventHelper.Event) {
if event.name == String(describing: MPV_EVENT_SHUTDOWN) { shutdown() }
}
}