diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2011-12-08 11:17:59 +0100 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2012-03-25 22:30:37 +0300 |
commit | 495dde4018e071f81462052d5b4c09c973f25f16 (patch) | |
tree | 9601e9ff288c8f4305c1dd16ce4aaa43ea596ac6 /libvo/cocoa_common.m | |
parent | f30bf73bf22ed054233507d7277e3658e51d86bd (diff) | |
download | mpv-495dde4018e071f81462052d5b4c09c973f25f16.tar.bz2 mpv-495dde4018e071f81462052d5b4c09c973f25f16.tar.xz |
options, x11+cocoa: add option --cursor-autohide-delay
Add option --cursor-autohide-delay to control the number of milliseconds
with no user interaction before the mouse cursor is hidden.
There are two negative values with useful special meanings:
* A value of -1 prevents the cursor from hiding (useful for users
with multiple displays).
* A value of -2 prevents the cursor from showing upon activity.
The default is 1 second to keep the behaviour consistent with the
past X11 backend implementation.
Remove the vo_mouse_autohide field as it was always true.
Diffstat (limited to 'libvo/cocoa_common.m')
-rw-r--r-- | libvo/cocoa_common.m | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m index ba7d0ebc7c..aa8480bec5 100644 --- a/libvo/cocoa_common.m +++ b/libvo/cocoa_common.m @@ -55,6 +55,10 @@ struct vo_cocoa_state { int last_screensaver_update; + int display_cursor; + int cursor_timer; + int cursor_autohide_delay; + bool did_resize; bool out_fs_resize; }; @@ -68,6 +72,7 @@ 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); struct vo_cocoa_state *vo_cocoa_init_state(void) @@ -82,6 +87,7 @@ struct vo_cocoa_state *vo_cocoa_init_state(void) .fullscreen_window_level = NSNormalWindowLevel + 1, .windowed_frame = {{0,0},{0,0}}, .out_fs_resize = NO, + .display_cursor = 1, }; return s; } @@ -90,6 +96,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]; @@ -245,18 +252,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) @@ -335,8 +366,8 @@ void create_menu() [self setStyleMask:s->fullscreen_mask]; [self setFrame:s->screen_frame display:YES animate:NO]; [self setLevel:s->fullscreen_window_level]; - CGDisplayHideCursor(kCGDirectMainDisplay); vo_fs = VO_TRUE; + vo_cocoa_display_cursor(0); } else { [NSApp setPresentationOptions:NSApplicationPresentationDefault]; [self setHasShadow:YES]; @@ -349,8 +380,8 @@ void create_menu() } [self setContentAspectRatio:s->current_video_size]; [self setLevel:s->windowed_window_level]; - CGDisplayShowCursor(kCGDirectMainDisplay); vo_fs = VO_FALSE; + vo_cocoa_display_cursor(1); } } @@ -396,6 +427,12 @@ void create_menu() } } +- (void) mouseMoved: (NSEvent *) theEvent +{ + if (vo_fs) + vo_cocoa_display_cursor(1); +} + - (void) mouseDragged:(NSEvent *)theEvent { [self mouseEvent: theEvent]; |