0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

cocoa: allow to embed into an arbitrary NSView

Basically add if guards on all the problematic features. I'm still thinking
about a better way to handle this, but for the time being, this will do.
This commit is contained in:
Stefano Pigozzi 2014-10-08 19:23:47 +02:00
parent 06ecf54fdf
commit 69fa956f50
6 changed files with 34 additions and 19 deletions

View File

@ -82,7 +82,7 @@ static void wakeup(void *);
}
#if EMBED_VIEW
int64_t wid = (intptr_t) self->w;
int64_t wid = (intptr_t) [self->w contentView];
check_error(mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid));
#endif

View File

@ -21,6 +21,5 @@
@interface MpvEventsView : NSView <NSDraggingDestination>
@property(nonatomic, retain) MpvCocoaAdapter *adapter;
- (void)setFullScreen:(BOOL)willBeFullscreen;
- (NSRect)frameInPixels;
- (BOOL)canHideCursor;
@end

View File

@ -130,11 +130,6 @@
- (BOOL)becomeFirstResponder { return YES; }
- (BOOL)resignFirstResponder { return YES; }
- (NSRect)frameInPixels
{
return [self convertRectToBacking:[self frame]];
}
- (BOOL)canHideCursor
{
return !self.hasMouseDown && [self containsMouseLocation];

View File

@ -20,4 +20,5 @@
@interface MpvVideoView : NSView
@property(nonatomic, retain) MpvCocoaAdapter *adapter;
- (NSRect)frameInPixels;
@end

View File

@ -35,4 +35,9 @@
[super setFrameSize:size];
[self.adapter setNeedsResize];
}
- (NSRect)frameInPixels
{
return [self convertRectToBacking:[self frame]];
}
@end

View File

@ -58,7 +58,7 @@ static void cocoa_rm_fs_screen_profile_observer(struct vo *vo);
struct vo_cocoa_state {
NSWindow *window;
MpvEventsView *view;
NSView *view;
MpvVideoView *video;
NSOpenGLContext *gl_ctx;
@ -155,17 +155,24 @@ int vo_cocoa_init(struct vo *vo)
return 1;
}
static void vo_cocoa_set_cursor_visibility(struct vo *vo, bool *visible)
static int vo_cocoa_set_cursor_visibility(struct vo *vo, bool *visible)
{
struct vo_cocoa_state *s = vo->cocoa;
if (s->embedded)
return VO_NOTIMPL;
MpvEventsView *v = (MpvEventsView *) s->view;
if (*visible) {
CGDisplayShowCursor(kCGDirectMainDisplay);
} else if ([s->view canHideCursor]) {
} else if ([v canHideCursor]) {
CGDisplayHideCursor(kCGDirectMainDisplay);
} else {
*visible = true;
}
return VO_TRUE;
}
void vo_cocoa_uninit(struct vo *vo)
@ -225,6 +232,9 @@ static void vo_cocoa_update_screen_info(struct vo *vo, struct mp_rect *out_rc)
{
struct vo_cocoa_state *s = vo->cocoa;
if (s->embedded)
return;
vo_cocoa_update_screens_pointers(vo);
if (out_rc) {
@ -236,7 +246,7 @@ static void vo_cocoa_update_screen_info(struct vo *vo, struct mp_rect *out_rc)
static void resize_window(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
NSRect frame = [s->view frameInPixels];
NSRect frame = [s->video frameInPixels];
vo->dwidth = frame.size.width;
vo->dheight = frame.size.height;
[s->gl_ctx update];
@ -301,14 +311,19 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
MpvCocoaAdapter *adapter = [[[MpvCocoaAdapter alloc] init] autorelease];
const NSRect contentRect =
NSMakeRect(win->x0, win->y0, win->x1 - win->x0, win->y1 - win->y0);
adapter.vout = vo;
if (s->embedded) {
s->window = (NSWindow *) (intptr_t) opts->WinID;
s->view = (NSView *) (intptr_t) opts->WinID;
} else {
s->window = create_window(contentRect, s->current_screen,
opts->border, adapter);
MpvEventsView *view = [[MpvEventsView alloc] initWithFrame:contentRect];
[view autorelease];
view.adapter = adapter;
s->view = view;
}
s->view = [[[MpvEventsView alloc] initWithFrame:contentRect] autorelease];
#if HAVE_COCOA_APPLICATION
cocoa_register_menu_item_action(MPM_H_SIZE, @selector(halfSize));
@ -326,8 +341,6 @@ static void create_ui(struct vo *vo, struct mp_rect *win, int geo_flags)
[s->window setContentView:s->view];
[s->gl_ctx setView:s->video];
adapter.vout = vo;
s->view.adapter = adapter;
s->video.adapter = adapter;
if (!s->embedded) {
@ -414,7 +427,7 @@ int vo_cocoa_config_window(struct vo *vo, uint32_t flags, void *gl_ctx)
s->old_dwidth = width;
s->old_dheight = height;
if (!(flags & VOFLAG_HIDDEN) && !s->window) {
if (!(flags & VOFLAG_HIDDEN) && !s->view) {
create_ui(vo, &geo.win, geo.flags);
}
@ -499,10 +512,13 @@ static void vo_cocoa_fullscreen(struct vo *vo)
struct vo_cocoa_state *s = vo->cocoa;
struct mp_vo_opts *opts = vo->opts;
if (s->embedded)
return;
vo_cocoa_update_screen_info(vo, NULL);
draw_changes_after_next_frame(vo);
[s->view setFullScreen:opts->fullscreen];
[(MpvEventsView *)s->view setFullScreen:opts->fullscreen];
if (s->icc_fs_profile_path != s->icc_wnd_profile_path)
s->pending_events = VO_EVENT_ICC_PROFILE_PATH_CHANGED;
@ -646,8 +662,7 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
return VO_TRUE;
}
case VOCTRL_SET_CURSOR_VISIBILITY:
vo_cocoa_set_cursor_visibility(vo, arg);
return VO_TRUE;
return vo_cocoa_set_cursor_visibility(vo, arg);
case VOCTRL_UPDATE_WINDOW_TITLE:
return cocoa_set_window_title(vo, (const char *) arg);
case VOCTRL_RESTORE_SCREENSAVER: