diff options
author | wm4 <wm4@nowhere> | 2013-05-16 23:17:46 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-26 16:44:19 +0200 |
commit | 3c8f8b7714331746233e288206b247366257cb99 (patch) | |
tree | 2a42c1d9c60bf24e5a680ec7e6d599ff33e60232 /core/input | |
parent | 8df780cb50ec4bb615ac25987de52bb3b4126de9 (diff) | |
download | mpv-3c8f8b7714331746233e288206b247366257cb99.tar.bz2 mpv-3c8f8b7714331746233e288206b247366257cb99.tar.xz |
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.
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/input.c | 24 | ||||
-rw-r--r-- | core/input/input.h | 3 |
2 files changed, 20 insertions, 7 deletions
diff --git a/core/input/input.c b/core/input/input.c index 24bba1c14a..c756efcbdc 100644 --- a/core/input/input.c +++ b/core/input/input.c @@ -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; +} diff --git a/core/input/input.h b/core/input/input.h index e09e080db1..1f079e7451 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -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, |