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

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.
This commit is contained in:
Stefano Pigozzi 2011-12-08 11:17:59 +01:00 committed by Uoti Urpala
parent f30bf73bf2
commit 495dde4018
6 changed files with 56 additions and 20 deletions

View File

@ -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},

View File

@ -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,

View File

@ -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)
{
//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)
{
UpdateSystemActivity(UsrActivity);
s->last_screensaver_update = curTime;
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.
if ((int)curTime - s->last_screensaver_update >= 30 || s->last_screensaver_update == 0)
{
UpdateSystemActivity(UsrActivity);
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];

View File

@ -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);
}

View File

@ -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;

View File

@ -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;