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
20 20
21 var mpv: OpaquePointer?21 var mpv: OpaquePointer?
22 @objc var input: InputHelper22 @objc var input: InputHelper
23 var event: EventHelper?
23#if HAVE_MACOS_MEDIA_PLAYER24#if HAVE_MACOS_MEDIA_PLAYER
24 var remote: RemoteCommandCenter?25 var remote: RemoteCommandCenter?
25#endif26#endif
@@ -31,21 +32,16 @@ class AppHub: NSObject { · 5 unmodified lines
31 }32 }
32 33
33 @objc func initMpv(_ mpv: OpaquePointer) {34 @objc func initMpv(_ mpv: OpaquePointer) {
34 if isApplication {35 self.mpv = mpv
35 self.mpv = mpv36 mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE)
36 mpv_observe_property(mpv, 0, "duration", MPV_FORMAT_DOUBLE)37 mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE)
37 mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE)38 mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE)
38 mpv_observe_property(mpv, 0, "speed", MPV_FORMAT_DOUBLE)39 mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG)
39 mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG)40 mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING)
40 mpv_observe_property(mpv, 0, "media-title", MPV_FORMAT_STRING)41 mpv_observe_property(mpv, 0, "chapter-metadata/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)
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)
43 mpv_observe_property(mpv, 0, "metadata/by-key/artist", MPV_FORMAT_STRING)44 event = EventHelper(mpv)
44 mpv_set_wakeup_callback(mpv, wakeup, TypeHelper.bridge(obj: self))
45 return
46 }
47
48 mpv_destroy(mpv)
49 }45 }
50 46
51 @objc func initInput(_ input: OpaquePointer?) {47 @objc func initInput(_ input: OpaquePointer?) {
osdep/mac/application.m+0−3
@@ -166,9 +166,6 @@ static const char mac_icon[] = · 165 unmodified lines
166#if HAVE_MACOS_TOUCHBAR166#if HAVE_MACOS_TOUCHBAR
167 [(TouchBar *)self.touchBar processEvent:event];167 [(TouchBar *)self.touchBar processEvent:event];
168#endif168#endif
169 if (_cocoa_cb) {
170 [_cocoa_cb processEvent:event];
171 }
172}169}
173 170
174- (void)initCocoaCb:(struct mpv_handle *)ctx171- (void)initCocoaCb:(struct mpv_handle *)ctx
video/out/cocoa_cb_common.swift+4−8
@@ -17,7 +17,7 @@ · 16 unmodified lines
17 17
18import Cocoa18import Cocoa
19 19
20class CocoaCB: Common {20class CocoaCB: Common, EventSubscriber {
21 var libmpv: LibmpvHelper21 var libmpv: LibmpvHelper
22 var layer: GLLayer?22 var layer: GLLayer?
23 23
@@ -37,6 +37,7 @@ class CocoaCB: Common { · 13 unmodified lines
37 libmpv = LibmpvHelper(mpvHandle, newlog)37 libmpv = LibmpvHelper(mpvHandle, newlog)
38 super.init(option, newlog)38 super.init(option, newlog)
39 layer = GLLayer(cocoaCB: self)39 layer = GLLayer(cocoaCB: self)
40 AppHub.shared.event?.subscribe(self, event: .init(name: "MPV_EVENT_SHUTDOWN"))
40 }41 }
41 42
42 func preinit(_ vo: UnsafeMutablePointer<vo>) {43 func preinit(_ vo: UnsafeMutablePointer<vo>) {
@@ -221,12 +222,7 @@ class CocoaCB: Common { · 178 unmodified lines
221 }222 }
222 }223 }
223 224
224 @objc func processEvent(_ event: UnsafePointer<mpv_event>) {225 func handle(event: EventHelper.Event) {
225 switch event.pointee.event_id {226 if event.name == String(describing: MPV_EVENT_SHUTDOWN) { shutdown() }
226 case MPV_EVENT_SHUTDOWN:
227 shutdown()
228 default:
229 break
230 }
231 }227 }
232}228}

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