From ca893689fefdac74338b41aa21fbc601ae102ff6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 2 Mar 2013 22:50:09 +0100 Subject: x11_common: fix --cursor-autohide when paused When paused, --cursor-autohide worked with a precision of 500ms, which is the main loop's default sleep time when paused. Cursor hiding is polled in x11_common, and the main loop never called the X11 code at the right time. Fix this by allowing the VO to set a time when it should be called next. --- core/mplayer.c | 10 ++++++++-- video/out/vo.c | 25 ++++++++++++++++++------- video/out/vo.h | 4 ++++ video/out/x11_common.c | 42 ++++++++++++++++++++++-------------------- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/core/mplayer.c b/core/mplayer.c index 6e0256fbaa..a4c9c09960 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -3471,8 +3471,14 @@ static void run_playloop(struct MPContext *mpctx) } } } - if (sleeptime > 0) - mp_input_get_cmd(mpctx->input, sleeptime * 1000, true); + if (sleeptime > 0) { + int sleep_ms = sleeptime * 1000; + if (mpctx->sh_video) { + unsigned int vo_sleep = vo_get_sleep_time(mpctx->video_out); + sleep_ms = FFMIN(sleep_ms, vo_sleep); + } + mp_input_get_cmd(mpctx->input, sleep_ms, true); + } } //================= Keyboard events, SEEKing ==================== diff --git a/video/out/vo.c b/video/out/vo.c index 6fff185c6c..52ed04d3b5 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -25,11 +25,12 @@ #include #include -//#include + +#include "talloc.h" #include "config.h" +#include "osdep/timer.h" #include "core/options.h" -#include "talloc.h" #include "core/bstr.h" #include "vo.h" #include "aspect.h" @@ -41,11 +42,6 @@ #include "video/vfcap.h" #include "sub/sub.h" -#include "osdep/shmem.h" -#ifdef CONFIG_X11 -#include "x11_common.h" -#endif - int xinerama_x; int xinerama_y; @@ -247,6 +243,7 @@ void vo_flip_page(struct vo *vo, unsigned int pts_us, int duration) void vo_check_events(struct vo *vo) { + vo->next_wakeup_time = GetTimerMS() + 60 * 1000; if (!vo->config_ok) { if (vo->registered_fd != -1) mp_input_rm_key_fd(vo->input_ctx, vo->registered_fd); @@ -256,6 +253,20 @@ void vo_check_events(struct vo *vo) vo->driver->check_events(vo); } +// Return the amount of time vo_check_events() should be called in milliseconds. +// Note: video timing is completely separate from this. +unsigned int vo_get_sleep_time(struct vo *vo) +{ + unsigned int sleep = 60 * 1000; + if (vo->config_ok && vo->next_wakeup_time) { + unsigned int now = GetTimerMS(); + sleep = 0; + if (vo->next_wakeup_time >= now) + sleep = vo->next_wakeup_time - now; + } + return sleep; +} + void vo_seek_reset(struct vo *vo) { vo_control(vo, VOCTRL_RESET, NULL); diff --git a/video/out/vo.h b/video/out/vo.h index d10d360657..ca252337b1 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -238,6 +238,9 @@ struct vo { double flip_queue_offset; // queue flip events at most this much in advance + unsigned int next_wakeup_time; // deadline for next vo_check_events() call, + // in GetTimerMS() units (set by VO) + const struct vo_driver *driver; void *priv; struct MPOpts *opts; @@ -294,6 +297,7 @@ void vo_new_frame_imminent(struct vo *vo); void vo_draw_osd(struct vo *vo, struct osd_state *osd); void vo_flip_page(struct vo *vo, unsigned int pts_us, int duration); void vo_check_events(struct vo *vo); +unsigned int vo_get_sleep_time(struct vo *vo); void vo_seek_reset(struct vo *vo); void vo_destroy(struct vo *vo); diff --git a/video/out/x11_common.c b/video/out/x11_common.c index 7d5ef0da33..0fa8f2ad47 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -665,6 +665,20 @@ void vo_x11_uninit(struct vo *vo) vo->x11 = NULL; } +static void vo_x11_unhide_cursor(struct vo *vo) +{ + struct vo_x11_state *x11 = vo->x11; + struct MPOpts *opts = vo->opts; + + if (opts->cursor_autohide_delay > -2) { + vo_showcursor(x11->display, x11->window); + if (opts->cursor_autohide_delay >= 0) { + x11->mouse_waiting_hide = 1; + x11->mouse_timer = GetTimerMS() + opts->cursor_autohide_delay; + } + } +} + static void update_vo_size(struct vo *vo) { struct vo_x11_state *x11 = vo->x11; @@ -679,13 +693,10 @@ static void update_vo_size(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; XEvent Event; - if (x11->mouse_waiting_hide && opts->cursor_autohide_delay != -1 && - (GetTimerMS() - x11->mouse_timer >= opts->cursor_autohide_delay)) - { + if (x11->mouse_waiting_hide && GetTimerMS() >= x11->mouse_timer) { vo_hidecursor(display, x11->window); x11->mouse_waiting_hide = 0; } @@ -740,29 +751,16 @@ int vo_x11_check_events(struct vo *vo) break; case MotionNotify: vo_mouse_movement(vo, Event.xmotion.x, Event.xmotion.y); - - if (opts->cursor_autohide_delay > -2) { - vo_showcursor(display, x11->window); - x11->mouse_waiting_hide = 1; - x11->mouse_timer = GetTimerMS(); - } + vo_x11_unhide_cursor(vo); break; case ButtonPress: - if (opts->cursor_autohide_delay > -2) { - vo_showcursor(display, x11->window); - x11->mouse_waiting_hide = 1; - x11->mouse_timer = GetTimerMS(); - } + vo_x11_unhide_cursor(vo); mplayer_put_key(vo->key_fifo, (MP_MOUSE_BTN0 + Event.xbutton.button - 1) | MP_KEY_STATE_DOWN); break; case ButtonRelease: - if (opts->cursor_autohide_delay > -2) { - vo_showcursor(display, x11->window); - x11->mouse_waiting_hide = 1; - x11->mouse_timer = GetTimerMS(); - } + vo_x11_unhide_cursor(vo); mplayer_put_key(vo->key_fifo, MP_MOUSE_BTN0 + Event.xbutton.button - 1); break; @@ -795,6 +793,10 @@ int vo_x11_check_events(struct vo *vo) break; } } + + if (x11->mouse_waiting_hide) + vo->next_wakeup_time = FFMIN(vo->next_wakeup_time, x11->mouse_timer); + update_vo_size(vo); if (WinID >= 0 && (x11->pending_vo_events & VO_EVENT_RESIZE)) { int x = x11->win_x, y = x11->win_y; -- cgit v1.2.3