summaryrefslogtreecommitdiffstats
path: root/libvo/cocoa_common.m
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-04-01 22:52:33 +0200
committerwm4 <wm4@mplayer2.org>2012-04-01 22:52:33 +0200
commit1aa2e36122e6e664e42170f47d6db82873bef5aa (patch)
tree39e13f93bcb606da9e365c7cd379132bdf53c20b /libvo/cocoa_common.m
parentfea8c85c8595b797fc839b113c1db252fc55c798 (diff)
parent8cd71527ade21ea27ea24cdcc66dc71dca460f85 (diff)
downloadmpv-1aa2e36122e6e664e42170f47d6db82873bef5aa.tar.bz2
mpv-1aa2e36122e6e664e42170f47d6db82873bef5aa.tar.xz
Merge remote-tracking branch 'origin/master'
Conflicts: bstr.c bstr.h etc/input.conf input/input.c input/input.h libao2/ao_pulse.c libmpcodecs/vf_ass.c libmpcodecs/vf_vo.c libvo/gl_common.c libvo/x11_common.c mixer.c mixer.h mplayer.c
Diffstat (limited to 'libvo/cocoa_common.m')
-rw-r--r--libvo/cocoa_common.m128
1 files changed, 110 insertions, 18 deletions
diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m
index 4eccf1a320..e8ef278b1e 100644
--- a/libvo/cocoa_common.m
+++ b/libvo/cocoa_common.m
@@ -1,3 +1,22 @@
+/*
+ * Cocoa OpenGL Backend
+ *
+ * This file is part of mplayer2.
+ *
+ * mplayer2 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mplayer2 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
@@ -62,8 +81,15 @@ struct vo_cocoa_state {
NSString *window_title;
+ NSInteger windowed_window_level;
+ NSInteger fullscreen_window_level;
+
int last_screensaver_update;
+ int display_cursor;
+ int cursor_timer;
+ int cursor_autohide_delay;
+
bool did_resize;
bool out_fs_resize;
};
@@ -74,8 +100,10 @@ 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 vo_cocoa_display_cursor(int requested_state);
void create_menu(void);
bool is_lion_or_better(void);
@@ -89,8 +117,10 @@ 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,
+ .display_cursor = 1,
};
return s;
}
@@ -99,6 +129,7 @@ int vo_cocoa_init(struct vo *vo)
{
s = vo_cocoa_init_state();
s->pool = [[NSAutoreleasePool alloc] init];
+ s->cursor_autohide_delay = vo->opts->cursor_autohide_delay;
NSApplicationLoad();
NSApp = [NSApplication sharedApplication];
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
@@ -155,10 +186,30 @@ 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,
int gl3profile)
{
+ 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);
@@ -207,6 +258,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) {
@@ -238,18 +291,42 @@ void vo_cocoa_swap_buffers()
[s->glContext flushBuffer];
}
+void vo_cocoa_display_cursor(int requested_state)
+{
+ if (requested_state) {
+ if (!vo_fs || s->cursor_autohide_delay > -2) {
+ s->display_cursor = requested_state;
+ CGDisplayShowCursor(kCGDirectMainDisplay);
+ }
+ } else {
+ if (s->cursor_autohide_delay != -1) {
+ s->display_cursor = requested_state;
+ CGDisplayHideCursor(kCGDirectMainDisplay);
+ }
+ }
+}
+
int vo_cocoa_check_events(struct vo *vo)
{
+ NSEvent *event;
+ float curTime = TickCount()/60;
+ int msCurTime = (int) (curTime * 1000);
+
+ // automatically hide mouse cursor
+ if (vo_fs && s->display_cursor &&
+ (msCurTime - s->cursor_timer >= s->cursor_autohide_delay)) {
+ vo_cocoa_display_cursor(0);
+ s->cursor_timer = msCurTime;
+ }
+
//update activity every 30 seconds to prevent
//screensaver from starting up.
- int curTime = TickCount()/60;
- if (curTime - s->last_screensaver_update >= 30 || s->last_screensaver_update == 0)
+ if ((int)curTime - s->last_screensaver_update >= 30 || s->last_screensaver_update == 0)
{
UpdateSystemActivity(UsrActivity);
- s->last_screensaver_update = curTime;
+ s->last_screensaver_update = (int)curTime;
}
- NSEvent *event;
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
inMode:NSEventTrackingRunLoopMode dequeue:YES];
if (event == nil)
@@ -333,14 +410,16 @@ bool is_lion_or_better(void)
- (void) fullscreen
{
if (!vo_fs) {
+ update_screen_info();
[NSApp setPresentationOptions:NSApplicationPresentationHideDock|NSApplicationPresentationHideMenuBar];
s->windowed_frame = [self frame];
[self setHasShadow:NO];
[self setStyleMask:s->fullscreen_mask];
[self setFrame:s->screen_frame display:YES animate:NO];
- [self setLevel:NSNormalWindowLevel + 1];
- CGDisplayHideCursor(kCGDirectMainDisplay);
+ [self setLevel:s->fullscreen_window_level];
vo_fs = VO_TRUE;
+ vo_cocoa_display_cursor(0);
+ [self setMovableByWindowBackground: NO];
} else {
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
[self setHasShadow:YES];
@@ -352,9 +431,10 @@ bool is_lion_or_better(void)
s->out_fs_resize = NO;
}
[self setContentAspectRatio:s->current_video_size];
- [self setLevel:NSNormalWindowLevel];
- CGDisplayShowCursor(kCGDirectMainDisplay);
+ [self setLevel:s->windowed_window_level];
vo_fs = VO_FALSE;
+ vo_cocoa_display_cursor(1);
+ [self setMovableByWindowBackground: YES];
}
}
@@ -372,6 +452,12 @@ bool is_lion_or_better(void)
return NO;
}
+- (BOOL) isMovableByWindowBackground
+{
+ // this is only valid as a starting value. it will be rewritten in the -fullscreen method.
+ return !vo_fs;
+}
+
- (void) handleQuitEvent:(NSAppleEventDescriptor*)e withReplyEvent:(NSAppleEventDescriptor*)r
{
mplayer_put_key(l_vo->key_fifo, KEY_CLOSE_WIN);
@@ -400,6 +486,12 @@ bool is_lion_or_better(void)
}
}
+- (void) mouseMoved: (NSEvent *) theEvent
+{
+ if (vo_fs)
+ vo_cocoa_display_cursor(1);
+}
+
- (void) mouseDragged:(NSEvent *)theEvent
{
[self mouseEvent: theEvent];
@@ -445,23 +537,23 @@ bool is_lion_or_better(void)
- (void) mouseEvent:(NSEvent *)theEvent
{
- if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 )
- {
+ if ([theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9) {
int buttonNumber = [theEvent buttonNumber];
// Fix to mplayer defined button order: left, middle, right
- if (buttonNumber == 1)
- buttonNumber = 2;
- else if (buttonNumber == 2)
- buttonNumber = 1;
+ if (buttonNumber == 1) buttonNumber = 2;
+ else if (buttonNumber == 2) buttonNumber = 1;
switch ([theEvent type]) {
case NSLeftMouseDown:
- break;
case NSRightMouseDown:
case NSOtherMouseDown:
mplayer_put_key(l_vo->key_fifo, (MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN);
+ // Looks like Cocoa doesn't create MouseUp events when we are
+ // doing the second click in a double click. Put in the key_fifo
+ // the key that would be put from the MouseUp handling code.
+ if([theEvent clickCount] == 2)
+ mplayer_put_key(l_vo->key_fifo, MOUSE_BTN0 + buttonNumber);
break;
case NSLeftMouseUp:
- break;
case NSRightMouseUp:
case NSOtherMouseUp:
mplayer_put_key(l_vo->key_fifo, MOUSE_BTN0 + buttonNumber);
@@ -473,7 +565,7 @@ bool is_lion_or_better(void)
- (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];
@@ -483,7 +575,7 @@ bool is_lion_or_better(void)
- (void) applicationWillResignActive:(NSNotification *)aNotification
{
if (vo_fs) {
- [s->window setLevel:NSNormalWindowLevel];
+ [s->window setLevel:s->windowed_window_level];
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
}
}