summaryrefslogtreecommitdiffstats
path: root/DOCS
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-10-05 14:28:33 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2014-10-05 14:28:33 +0200
commitc8ed4736ef6ffd58d2cf8b10317ff26d7424dfa2 (patch)
tree7b4a964c9ead2e7403baba6639911f2b56e0bc38 /DOCS
parent3137b7ac5f98ac062c4a7df351f0836e52994b18 (diff)
downloadmpv-c8ed4736ef6ffd58d2cf8b10317ff26d7424dfa2.tar.bz2
mpv-c8ed4736ef6ffd58d2cf8b10317ff26d7424dfa2.tar.xz
cocoa/libmpv: allow to embed mpv GL view in another window
This is just temporary code but is a good base for future work (and baby steps are required for these changes). The 'final destination' is embedding the video view into any NSView but that requires some more work (the mechanism will be the same: pass the view's pointer casted to int64_t through -wid). For instance we will need to remove as much usage of the window instance as possible, and use nil guards where not possible. For this reason I will remove stuff like the mission control fullscreen feature (it's a cute feature but annoying to support and quite limited, go make your GUIs), and a way to lookup the current screen directly from the NSView absolute coordinates (this is needed for ICC detection mostly, and reporting back the screen to mpv's core). Moreover the current view.m will need to be separated into 2 views: the actual video view that will be embedded, and a parent view that will not be embedded and will be responsibile for tracking events.
Diffstat (limited to 'DOCS')
-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 {