summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-16 23:17:46 +0200
committerwm4 <wm4@nowhere>2013-05-26 16:44:19 +0200
commit3c8f8b7714331746233e288206b247366257cb99 (patch)
tree2a42c1d9c60bf24e5a680ec7e6d599ff33e60232 /core
parent8df780cb50ec4bb615ac25987de52bb3b4126de9 (diff)
downloadmpv-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')
-rw-r--r--core/defaultopts.c1
-rw-r--r--core/input/input.c24
-rw-r--r--core/input/input.h3
-rw-r--r--core/mp_core.h7
-rw-r--r--core/mplayer.c29
5 files changed, 57 insertions, 7 deletions
diff --git a/core/defaultopts.c b/core/defaultopts.c
index 28eb9bcbb1..1efb8a1c97 100644
--- a/core/defaultopts.c
+++ b/core/defaultopts.c
@@ -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,
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,
diff --git a/core/mp_core.h b/core/mp_core.h
index ce576273b4..6f784b4b7c 100644
--- a/core/mp_core.h
+++ b/core/mp_core.h
@@ -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;
diff --git a/core/mplayer.c b/core/mplayer.c
index c0415093e2..5036d1e476 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -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);
}