From 495dde4018e071f81462052d5b4c09c973f25f16 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 8 Dec 2011 11:17:59 +0100 Subject: 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. --- cfg-mplayer.h | 1 + defaultopts.c | 1 + libvo/cocoa_common.m | 49 +++++++++++++++++++++++++++++++++++++++++++------ libvo/x11_common.c | 15 ++++++--------- libvo/x11_common.h | 1 - options.h | 1 + 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 6a167ece54..6d105569ae 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -803,6 +803,7 @@ const m_option_t mplayer_opts[]={ {"grabpointer", &vo_grabpointer, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"nograbpointer", &vo_grabpointer, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + OPT_INTRANGE("cursor-autohide-delay", cursor_autohide_delay, 0, -2, 30000), {"adapter", &vo_adapter_num, CONF_TYPE_INT, CONF_RANGE, 0, 5, NULL}, {"refreshrate",&vo_refresh_rate,CONF_TYPE_INT,CONF_RANGE, 0,100, NULL}, diff --git a/defaultopts.c b/defaultopts.c index b6f58b715d..da557117bf 100644 --- a/defaultopts.c +++ b/defaultopts.c @@ -14,6 +14,7 @@ void set_default_mplayer_options(struct MPOpts *opts) .ao_buffersize = -1, .monitor_pixel_aspect = 1.0, .vo_panscanrange = 1.0, + .cursor_autohide_delay = 1000, .vo_gamma_gamma = 1000, .vo_gamma_brightness = 1000, .vo_gamma_contrast = 1000, 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]; diff --git a/libvo/x11_common.c b/libvo/x11_common.c index d5af7a41ab..ee50ba5575 100644 --- a/libvo/x11_common.c +++ b/libvo/x11_common.c @@ -780,12 +780,13 @@ static int check_resize(struct vo *vo) int vo_x11_check_events(struct vo *vo) { struct vo_x11_state *x11 = vo->x11; + struct MPOpts *opts = vo->opts; Display *display = vo->x11->display; int ret = 0; XEvent Event; - if (x11->vo_mouse_autohide && x11->mouse_waiting_hide && - (GetTimerMS() - x11->mouse_timer >= 1000)) { + if (x11->mouse_waiting_hide && opts->cursor_autohide_delay != -1 && + (GetTimerMS() - x11->mouse_timer >= opts->cursor_autohide_delay)) { vo_hidecursor(display, x11->window); x11->mouse_waiting_hide = 0; } @@ -846,16 +847,14 @@ int vo_x11_check_events(struct vo *vo) case MotionNotify: vo_mouse_movement(vo, Event.xmotion.x, Event.xmotion.y); - if (x11->vo_mouse_autohide) - { + if (opts->cursor_autohide_delay > -2) { vo_showcursor(display, x11->window); x11->mouse_waiting_hide = 1; x11->mouse_timer = GetTimerMS(); } break; case ButtonPress: - if (x11->vo_mouse_autohide) - { + if (opts->cursor_autohide_delay > -2) { vo_showcursor(display, x11->window); x11->mouse_waiting_hide = 1; x11->mouse_timer = GetTimerMS(); @@ -865,8 +864,7 @@ int vo_x11_check_events(struct vo *vo) | MP_KEY_DOWN); break; case ButtonRelease: - if (x11->vo_mouse_autohide) - { + if (opts->cursor_autohide_delay > -2) { vo_showcursor(display, x11->window); x11->mouse_waiting_hide = 1; x11->mouse_timer = GetTimerMS(); @@ -1176,7 +1174,6 @@ final: x11->vo_gc = XCreateGC(mDisplay, x11->window, 0, NULL); XSync(mDisplay, False); - x11->vo_mouse_autohide = 1; vo->event_fd = ConnectionNumber(x11->display); } diff --git a/libvo/x11_common.h b/libvo/x11_common.h index 6ba2780747..14c7e44549 100644 --- a/libvo/x11_common.h +++ b/libvo/x11_common.h @@ -48,7 +48,6 @@ struct vo_x11_state { unsigned long xv_colorkey; unsigned int xv_port; - int vo_mouse_autohide; int wm_type; int fs_type; int window_state; diff --git a/options.h b/options.h index 8b8d2f5c3b..48f5c539a5 100644 --- a/options.h +++ b/options.h @@ -28,6 +28,7 @@ typedef struct MPOpts { int requested_colorspace; int requested_input_range; int requested_output_range; + int cursor_autohide_delay; // ranges -100 - 100, 1000 if the vo default should be used int vo_gamma_gamma; -- cgit v1.2.3