mirror of
https://github.com/mpv-player/mpv
synced 2025-01-13 02:16:40 +00:00
core: do mouse cursor hiding business in frontend
Do this so that not every VO backend has to setup a timer for cursor hiding and interpret the --cursor-autohide option.
This commit is contained in:
parent
8df780cb50
commit
3c8f8b7714
@ -29,6 +29,7 @@ void set_default_mplayer_options(struct MPOpts *opts)
|
||||
.fsscreen_id = -1,
|
||||
.stop_screensaver = 1,
|
||||
.nomouse_input = 0,
|
||||
.enable_mouse_movements = 1,
|
||||
.fsmode = 0,
|
||||
.panscan = 0.0f,
|
||||
.keepaspect = 1,
|
||||
|
@ -491,6 +491,8 @@ struct input_ctx {
|
||||
// events sources. If yes, the sources may have more queued.
|
||||
bool got_new_events;
|
||||
|
||||
unsigned int last_mouse_event;
|
||||
|
||||
struct input_fd key_fds[MP_MAX_KEY_FD];
|
||||
unsigned int num_key_fd;
|
||||
|
||||
@ -1315,6 +1317,9 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx)
|
||||
void mp_input_feed_key(struct input_ctx *ictx, int code)
|
||||
{
|
||||
ictx->got_new_events = true;
|
||||
int unmod = code & ~(MP_KEY_MODIFIER_MASK | MP_KEY_STATE_DOWN);
|
||||
if (unmod >= MP_MOUSE_BASE && unmod <= MP_MOUSE_BTN_END)
|
||||
ictx->last_mouse_event = GetTimerMS();
|
||||
if (code == MP_INPUT_RELEASE_ALL) {
|
||||
mp_msg(MSGT_INPUT, MSGL_V, "input: release all\n");
|
||||
memset(ictx->key_down, 0, sizeof(ictx->key_down));
|
||||
@ -1383,6 +1388,7 @@ static void read_events(struct input_ctx *ictx, int time)
|
||||
time = FFMIN(time, 1000 / ictx->ar_rate);
|
||||
time = FFMIN(time, ictx->ar_delay);
|
||||
}
|
||||
time = FFMAX(time, 0);
|
||||
ictx->got_new_events = false;
|
||||
struct input_fd *key_fds = ictx->key_fds;
|
||||
struct input_fd *cmd_fds = ictx->cmd_fds;
|
||||
@ -1419,12 +1425,9 @@ static void read_events(struct input_ctx *ictx, int time)
|
||||
FD_SET(cmd_fds[i].fd, &fds);
|
||||
}
|
||||
struct timeval tv, *time_val;
|
||||
if (time >= 0) {
|
||||
tv.tv_sec = time / 1000;
|
||||
tv.tv_usec = (time % 1000) * 1000;
|
||||
time_val = &tv;
|
||||
} else
|
||||
time_val = NULL;
|
||||
tv.tv_sec = time / 1000;
|
||||
tv.tv_usec = (time % 1000) * 1000;
|
||||
time_val = &tv;
|
||||
if (select(max_fd + 1, &fds, NULL, NULL, time_val) < 0) {
|
||||
if (errno != EINTR)
|
||||
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Select error: %s\n",
|
||||
@ -1432,7 +1435,7 @@ static void read_events(struct input_ctx *ictx, int time)
|
||||
FD_ZERO(&fds);
|
||||
}
|
||||
#else
|
||||
if (time)
|
||||
if (time > 0)
|
||||
usec_sleep(time * 1000);
|
||||
#endif
|
||||
|
||||
@ -1479,6 +1482,8 @@ int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd)
|
||||
ictx->got_new_events = true;
|
||||
if (!cmd)
|
||||
return 0;
|
||||
if (cmd->id == MP_CMD_SET_MOUSE_POS)
|
||||
ictx->last_mouse_event = GetTimerMS();
|
||||
queue_add(&ictx->control_cmd_queue, cmd, false);
|
||||
return 1;
|
||||
}
|
||||
@ -1908,3 +1913,8 @@ int mp_input_check_interrupt(struct input_ctx *ictx, int time)
|
||||
read_all_events(ictx, time);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int mp_input_get_last_mouse_event_time(struct input_ctx *ictx)
|
||||
{
|
||||
return ictx->last_mouse_event;
|
||||
}
|
||||
|
@ -208,6 +208,9 @@ void mp_input_set_section(struct input_ctx *ictx, char *name, int flags);
|
||||
// Get current input section
|
||||
char *mp_input_get_section(struct input_ctx *ictx);
|
||||
|
||||
// Used to detect mouse movement.
|
||||
unsigned int mp_input_get_last_mouse_event_time(struct input_ctx *ictx);
|
||||
|
||||
// Initialize the input system
|
||||
struct input_conf;
|
||||
struct input_ctx *mp_input_init(struct input_conf *input_conf,
|
||||
|
@ -235,6 +235,13 @@ typedef struct MPContext {
|
||||
float audio_delay;
|
||||
|
||||
unsigned int last_heartbeat;
|
||||
|
||||
unsigned int mouse_timer;
|
||||
unsigned int mouse_last_time;
|
||||
int mouse_waiting_hide;
|
||||
|
||||
unsigned int next_wakup_time;
|
||||
|
||||
// used to prevent hanging in some error cases
|
||||
unsigned int start_timestamp;
|
||||
|
||||
|
@ -2555,6 +2555,10 @@ int reinit_video_chain(struct MPContext *mpctx)
|
||||
"the selected video_out (-vo) device.\n");
|
||||
goto err_out;
|
||||
}
|
||||
if (opts->vo.cursor_autohide_delay != -1) {
|
||||
vo_control(mpctx->video_out, VOCTRL_SET_CURSOR_VISIBILITY,
|
||||
&(bool){false});
|
||||
}
|
||||
mpctx->initialized_flags |= INITIALIZED_VO;
|
||||
}
|
||||
|
||||
@ -3503,6 +3507,27 @@ static void run_playloop(struct MPContext *mpctx)
|
||||
// ================================================================
|
||||
vo_check_events(vo);
|
||||
|
||||
unsigned int mouse_last_time =
|
||||
mp_input_get_last_mouse_event_time(mpctx->input);
|
||||
if (mpctx->mouse_last_time != mouse_last_time) {
|
||||
mpctx->mouse_last_time = mouse_last_time;
|
||||
if (opts->vo.cursor_autohide_delay > -1) {
|
||||
vo_control(vo, VOCTRL_SET_CURSOR_VISIBILITY, &(bool){true});
|
||||
if (opts->vo.cursor_autohide_delay >= 0) {
|
||||
mpctx->mouse_waiting_hide = 1;
|
||||
mpctx->mouse_timer =
|
||||
GetTimerMS() + opts->vo.cursor_autohide_delay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mpctx->mouse_waiting_hide == 1 &&
|
||||
GetTimerMS() >= mpctx->mouse_timer)
|
||||
{
|
||||
vo_control(vo, VOCTRL_SET_CURSOR_VISIBILITY, &(bool){false});
|
||||
mpctx->mouse_waiting_hide = 2;
|
||||
}
|
||||
|
||||
if (opts->heartbeat_cmd) {
|
||||
unsigned now = GetTimerMS();
|
||||
if (now - mpctx->last_heartbeat >
|
||||
@ -3751,6 +3776,10 @@ static void run_playloop(struct MPContext *mpctx)
|
||||
if (mpctx->sh_video) {
|
||||
unsigned int vo_sleep = vo_get_sleep_time(mpctx->video_out);
|
||||
sleep_ms = FFMIN(sleep_ms, vo_sleep);
|
||||
if (mpctx->mouse_waiting_hide) {
|
||||
vo_sleep = mpctx->mouse_timer - GetTimerMS();
|
||||
sleep_ms = FFMIN(sleep_ms, vo_sleep);
|
||||
}
|
||||
}
|
||||
mp_input_get_cmd(mpctx->input, sleep_ms, true);
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ enum mp_voctrl {
|
||||
VOCTRL_ONTOP,
|
||||
VOCTRL_BORDER,
|
||||
|
||||
VOCTRL_SET_CURSOR_VISIBILITY, // bool
|
||||
|
||||
VOCTRL_SET_DEINTERLACE,
|
||||
VOCTRL_GET_DEINTERLACE,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user