From 506d9beb666bae92a93b945594f4cb857e9a5ca5 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 7 Dec 2011 12:42:04 +0100 Subject: vo_gl: cocoa: add support for --ontop Make the cocoa backend change the non-fullscreen window level according to the value of the ontop property. --- libvo/cocoa_common.h | 1 + libvo/cocoa_common.m | 35 +++++++++++++++++++++++++++++++---- libvo/gl_common.c | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/libvo/cocoa_common.h b/libvo/cocoa_common.h index 4fbbb32dd9..dc3e01db0f 100644 --- a/libvo/cocoa_common.h +++ b/libvo/cocoa_common.h @@ -15,6 +15,7 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, void vo_cocoa_swap_buffers(void); int vo_cocoa_check_events(struct vo *vo); void vo_cocoa_fullscreen(struct vo *vo); +void vo_cocoa_ontop(struct vo *vo); // returns an int to conform to the gl extensions from other platforms int vo_cocoa_swap_interval(int enabled); diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m index 5658ecb7bf..ba7d0ebc7c 100644 --- a/libvo/cocoa_common.m +++ b/libvo/cocoa_common.m @@ -50,6 +50,9 @@ struct vo_cocoa_state { NSString *window_title; + NSInteger windowed_window_level; + NSInteger fullscreen_window_level; + int last_screensaver_update; bool did_resize; @@ -62,6 +65,7 @@ struct vo *l_vo; // local function definitions struct vo_cocoa_state *vo_cocoa_init_state(void); +void vo_set_level(int ontop); void update_screen_info(void); void resize_window(struct vo *vo); void create_menu(void); @@ -75,6 +79,7 @@ struct vo_cocoa_state *vo_cocoa_init_state(void) .previous_video_size = {0,0}, .windowed_mask = NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask, .fullscreen_mask = NSBorderlessWindowMask, + .fullscreen_window_level = NSNormalWindowLevel + 1, .windowed_frame = {{0,0},{0,0}}, .out_fs_resize = NO, }; @@ -141,9 +146,29 @@ void resize_window(struct vo *vo) [s->glContext update]; } +void vo_set_level(int ontop) +{ + if (ontop) { + s->windowed_window_level = NSNormalWindowLevel + 1; + } else { + s->windowed_window_level = NSNormalWindowLevel; + } + + if (!vo_fs) + [s->window setLevel:s->windowed_window_level]; +} + +void vo_cocoa_ontop(struct vo *vo) +{ + struct MPOpts *opts = vo->opts; + opts->vo_ontop = !opts->vo_ontop; + vo_set_level(opts->vo_ontop); +} + int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, uint32_t d_height, uint32_t flags) { + struct MPOpts *opts = vo->opts; if (s->current_video_size.width > 0 || s->current_video_size.height > 0) s->previous_video_size = s->current_video_size; s->current_video_size = NSMakeSize(d_width, d_height); @@ -187,6 +212,8 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, if (flags & VOFLAG_FULLSCREEN) vo_cocoa_fullscreen(vo); + + vo_set_level(opts->vo_ontop); } else { if (s->current_video_size.width != s->previous_video_size.width || s->current_video_size.height != s->previous_video_size.height) { @@ -307,7 +334,7 @@ void create_menu() [self setHasShadow:NO]; [self setStyleMask:s->fullscreen_mask]; [self setFrame:s->screen_frame display:YES animate:NO]; - [self setLevel:NSNormalWindowLevel + 1]; + [self setLevel:s->fullscreen_window_level]; CGDisplayHideCursor(kCGDirectMainDisplay); vo_fs = VO_TRUE; } else { @@ -321,7 +348,7 @@ void create_menu() s->out_fs_resize = NO; } [self setContentAspectRatio:s->current_video_size]; - [self setLevel:NSNormalWindowLevel]; + [self setLevel:s->windowed_window_level]; CGDisplayShowCursor(kCGDirectMainDisplay); vo_fs = VO_FALSE; } @@ -442,7 +469,7 @@ void create_menu() - (void) applicationWillBecomeActive:(NSNotification *)aNotification { if (vo_fs) { - [s->window setLevel:NSNormalWindowLevel + 1]; + [s->window setLevel:s->fullscreen_window_level]; [NSApp setPresentationOptions:NSApplicationPresentationHideDock|NSApplicationPresentationHideMenuBar]; [s->window makeKeyAndOrderFront:nil]; [NSApp activateIgnoringOtherApps: YES]; @@ -452,7 +479,7 @@ void create_menu() - (void) applicationWillResignActive:(NSNotification *)aNotification { if (vo_fs) { - [s->window setLevel:NSNormalWindowLevel]; + [s->window setLevel:s->windowed_window_level]; [NSApp setPresentationOptions:NSApplicationPresentationDefault]; } } diff --git a/libvo/gl_common.c b/libvo/gl_common.c index 7cca800d40..9245811911 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -2049,6 +2049,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) ctx->check_events = cocoa_check_events; ctx->update_xinerama_info = cocoa_update_xinerama_info; ctx->fullscreen = cocoa_fullscreen; + ctx->ontop = vo_cocoa_ontop; if (vo_cocoa_init(vo)) return ctx; break; -- cgit v1.2.3