History

cocoa-cb: use EventHelper for event handling

der richter committed 2 years ago

Commit 5ab30601 parent 2a4bf7c3 files · +15 −26Browse files

Unified · Split

3 files
  1. osdep/mac/app_hub.swift +11 −15
  2. osdep/mac/application.m +0 −3
  3. video/out/cocoa_cb_common.swift +4 −8
osdep/mac/app_hub.swift+11−15
@@ -20,6 +20,7 @@ class AppHub: NSObject { · 19 unmodified lines
2020
2121 var mpv: OpaquePointer?
2222 @objc var input: InputHelper
23+ var event: EventHelper?
2324 #if HAVE_MACOS_MEDIA_PLAYER
2425 var remote: RemoteCommandCenter?
2526 #endif
@@ -31,21 +32,16 @@ class AppHub: NSObject { · 5 unmodified lines
3132 }
3233
3334 @objc func initMpv(_ mpv: OpaquePointer) {
34− if isApplication {
35− self.mpv = mpv
36− mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE)
37− mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE)
38− mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE)
39− mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG)
40− mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING)
41− mpv_observe_property(mpv, 0, "chapter-metadata/title", MPV_FORMAT_STRING)
42− mpv_observe_property(mpv, 0, "metadata/by-key/album", MPV_FORMAT_STRING)
43− mpv_observe_property(mpv, 0, "metadata/by-key/artist", MPV_FORMAT_STRING)
44− mpv_set_wakeup_callback(mpv, wakeup, TypeHelper.bridge(obj: self))
45− return
46− }
47−
48− mpv_destroy(mpv)
35+ self.mpv = mpv
36+ mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE)
37+ mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE)
38+ mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE)
39+ mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG)
40+ mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING)
41+ mpv_observe_property(mpv, 0, "chapter-metadata/title", MPV_FORMAT_STRING)
42+ mpv_observe_property(mpv, 0, "metadata/by-key/album", MPV_FORMAT_STRING)
43+ mpv_observe_property(mpv, 0, "metadata/by-key/artist", MPV_FORMAT_STRING)
44+ event = EventHelper(mpv)
4945 }
5046
5147 @objc func initInput(_ input: OpaquePointer?) {
osdep/mac/application.m+0−3
@@ -166,9 +166,6 @@ static const char mac_icon[] = · 165 unmodified lines
166166 #if HAVE_MACOS_TOUCHBAR
167167 [(TouchBar *)self.touchBar processEvent:event];
168168 #endif
169− if (_cocoa_cb) {
170− [_cocoa_cb processEvent:event];
171− }
172169 }
173170
174171 - (void)initCocoaCb:(struct mpv_handle *)ctx
video/out/cocoa_cb_common.swift+4−8
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717
1818 import Cocoa
1919
20−class CocoaCB: Common {
20+class CocoaCB: Common, EventSubscriber {
2121 var libmpv: LibmpvHelper
2222 var layer: GLLayer?
2323
@@ -37,6 +37,7 @@ class CocoaCB: Common { · 13 unmodified lines
3737 libmpv = LibmpvHelper(mpvHandle, newlog)
3838 super.init(option, newlog)
3939 layer = GLLayer(cocoaCB: self)
40+ AppHub.shared.event?.subscribe(self, event: .init(name: "MPV_EVENT_SHUTDOWN"))
4041 }
4142
4243 func preinit(_ vo: UnsafeMutablePointer<vo>) {
@@ -221,12 +222,7 @@ class CocoaCB: Common { · 178 unmodified lines
221222 }
222223 }
223224
224− @objc func processEvent(_ event: UnsafePointer<mpv_event>) {
225− switch event.pointee.event_id {
226− case MPV_EVENT_SHUTDOWN:
227− shutdown()
228− default:
229− break
230− }
225+ func handle(event: EventHelper.Event) {
226+ if event.name == String(describing: MPV_EVENT_SHUTDOWN) { shutdown() }
231227 }
232228 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t