diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2014-10-12 00:17:48 +0200 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2014-10-12 00:19:44 +0200 |
commit | c2eca2e4b7320324c1c1d78d432dc6358fa860c2 (patch) | |
tree | ddcc54737c78deb9275ee6650759d326e4177e11 /DOCS | |
parent | 8b6b84f36b00f06e6879db9c3bc9d171afa57cd7 (diff) | |
download | mpv-c2eca2e4b7320324c1c1d78d432dc6358fa860c2.tar.bz2 mpv-c2eca2e4b7320324c1c1d78d432dc6358fa860c2.tar.xz |
libmpv/cocoa: allow clients to use mpv event system
This allows mpv's view to take key and send events to mpv's core.
To set key status correctly, clients must call -[NSWindow selectNextKeyView:]
during reconfig on the main thread. All is 'documented' in the cocoabasic
example.
If someone knows a better way to handle giving key to the embedded view,
let me know!
Diffstat (limited to 'DOCS')
-rw-r--r-- | DOCS/client_api_examples/cocoabasic.m | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/DOCS/client_api_examples/cocoabasic.m b/DOCS/client_api_examples/cocoabasic.m index 35637f0a9f..8235f4b323 100644 --- a/DOCS/client_api_examples/cocoabasic.m +++ b/DOCS/client_api_examples/cocoabasic.m @@ -45,6 +45,7 @@ static void wakeup(void *); defer:NO]; [self->w setTitle:@"cocoabasic example"]; + [self->w makeMainWindow]; [self->w makeKeyAndOrderFront:nil]; [NSApp activateIgnoringOtherApps:YES]; } @@ -92,6 +93,10 @@ static void wakeup(void *); // for testing! check_error(mpv_set_option_string(mpv, "input-media-keys", "yes")); + check_error(mpv_set_option_string(mpv, "input-vo-keyboard", "yes")); + + // request important errors + check_error(mpv_request_log_messages(mpv, "warn")); check_error(mpv_initialize(mpv)); @@ -107,17 +112,27 @@ static void wakeup(void *); - (void) handleEvent:(mpv_event *)event { switch (event->event_id) { - case MPV_EVENT_SHUTDOWN: - // Clean up and shut down. - mpv_terminate_destroy(mpv); - mpv = NULL; - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSApplication sharedApplication] terminate:nil]; - }); - break; - - default: - printf("event: %s\n", mpv_event_name(event->event_id)); + case MPV_EVENT_SHUTDOWN: + // Clean up and shut down. + mpv_terminate_destroy(mpv); + mpv = NULL; + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSApplication sharedApplication] terminate:nil]; + }); + break; + + case MPV_EVENT_LOG_MESSAGE: { + struct mpv_event_log_message *msg = (struct mpv_event_log_message *)event->data; + printf("[%s] %s: %s", msg->prefix, msg->level, msg->text); + } + + case MPV_EVENT_VIDEO_RECONFIG: + dispatch_async(dispatch_get_main_queue(), ^{ + [self->w selectNextKeyView:nil]; + }); + + default: + printf("event: %s\n", mpv_event_name(event->event_id)); } } |