summaryrefslogtreecommitdiffstats
path: root/DOCS/client_api_examples/cocoabasic.m
diff options
context:
space:
mode:
Diffstat (limited to 'DOCS/client_api_examples/cocoabasic.m')
-rw-r--r--DOCS/client_api_examples/cocoabasic.m44
1 files changed, 42 insertions, 2 deletions
diff --git a/DOCS/client_api_examples/cocoabasic.m b/DOCS/client_api_examples/cocoabasic.m
index 383d778f3e..66a9ff8f7e 100644
--- a/DOCS/client_api_examples/cocoabasic.m
+++ b/DOCS/client_api_examples/cocoabasic.m
@@ -8,17 +8,48 @@
#import <Cocoa/Cocoa.h>
+#define EMBED_VIEW 1
+
+#if EMBED_VIEW
+@interface CocoaWindow : NSWindow
+@end
+
+@implementation CocoaWindow
+- (BOOL)canBecomeMainWindow { return YES; }
+- (BOOL)canBecomeKeyWindow { return YES; }
+@end
+
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
mpv_handle *mpv;
dispatch_queue_t queue;
+ NSWindow *w;
}
@end
+#endif
static void wakeup(void *);
+#if EMBED_VIEW
@implementation AppDelegate
+- (void)createWindow {
+
+ int mask = NSTitledWindowMask|NSClosableWindowMask|
+ NSMiniaturizableWindowMask|NSResizableWindowMask;
+
+ self->w = [[CocoaWindow alloc]
+ initWithContentRect:NSMakeRect(0,0, 1280, 720)
+ styleMask:mask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+
+ [self->w setTitle:@"cocoabasic example"];
+ [self->w makeKeyAndOrderFront:nil];
+ [NSApp activateIgnoringOtherApps:YES];
+}
+#endif
+
- (void) applicationDidFinishLaunching:(NSNotification *)notification {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
atexit_b(^{
@@ -36,6 +67,10 @@ static void wakeup(void *);
}
NSString *filename = args[1];
+#if EMBED_VIEW
+ [self createWindow];
+#endif
+
// Deal with MPV in the background.
queue = dispatch_queue_create("mpv", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
@@ -46,6 +81,11 @@ static void wakeup(void *);
exit(1);
}
+#if EMBED_VIEW
+ uintptr_t wid = (uintptr_t)self->w;
+ check_error(mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid));
+#endif
+
// Maybe set some options here, like default key bindings.
// NOTE: Interaction with the window seems to be broken for now.
check_error(mpv_set_option_string(mpv, "input-default-bindings", "yes"));
@@ -99,6 +139,8 @@ static void wakeup(void *context) {
- (BOOL) windowShouldClose:(id)sender
{
[self shutdown];
+ if (self->w)
+ [self->w release];
return YES;
}
@@ -111,8 +153,6 @@ static void wakeup(void *context) {
}
@end
-
-
// Delete this if you already have a main.m.
int main(int argc, const char * argv[]) {
@autoreleasepool {