mirror of
https://github.com/mpv-player/mpv
synced 2025-02-07 23:51:49 +00:00
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.
This commit is contained in:
parent
9efe32120b
commit
ca893689fe
@ -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 ====================
|
||||
|
@ -25,11 +25,12 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <unistd.h>
|
||||
//#include <sys/mman.h>
|
||||
|
||||
#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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user