diff options
author | wm4 <wm4@nowhere> | 2014-09-07 20:44:54 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-09-07 20:44:54 +0200 |
commit | f5af5962378bd40a409716434a6a4d312e50c755 (patch) | |
tree | 0d507b7254fbd159a6ca0c29f4c0261c4a4becb4 /input/input.c | |
parent | 5546af421f853170ad3142008503bb865a81adef (diff) | |
download | mpv-f5af5962378bd40a409716434a6a4d312e50c755.tar.bz2 mpv-f5af5962378bd40a409716434a6a4d312e50c755.tar.xz |
player: some more input refactoring
Continues commit 348dfd93. Replace other places where input was manually
fetched with common code.
demux_was_interrupted() was a weird function; I'm not entirely sure
about its original purpose, but now we can just replace it with simpler
code as well. One difference is that we always look at the command
queue, rather than just when cache initialization failed. Also, instead
of discarding all but quit/playlist commands (aka abort command), run
all commands. This could possibly lead to unwanted side-effects, like
just ignoring commands that have no effect (consider pressing 'f' for
fullscreen right on start: since the window is not created yet, it would
get discarded). But playlist navigation still works as intended, and
some if not all these problems already existed before that in some
forms, so it should be ok.
Diffstat (limited to 'input/input.c')
-rw-r--r-- | input/input.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/input/input.c b/input/input.c index d2a57c726e..328877eeb4 100644 --- a/input/input.c +++ b/input/input.c @@ -192,6 +192,7 @@ int async_quit_request; static int parse_config(struct input_ctx *ictx, bool builtin, bstr data, const char *location, const char *restrict_section); static void close_input_sources(struct input_ctx *ictx); +static bool test_abort(struct input_ctx *ictx); #define OPT_BASE_STRUCT struct input_opts struct input_opts { @@ -1158,21 +1159,27 @@ static mp_cmd_t *check_autorepeat(struct input_ctx *ictx) return NULL; } -/** - * \param peek_only when set, the returned command stays in the queue. - * Do not free the returned cmd whe you set this! - */ -mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only) +void mp_input_wait(struct input_ctx *ictx, double seconds) +{ + if (seconds <= 0) + return; + input_lock(ictx); + if (ictx->cmd_queue.first) + seconds = 0; + MP_STATS(ictx, "start sleep"); + read_events(ictx, MPMIN(seconds * 1000, INT_MAX)); + MP_STATS(ictx, "end sleep"); + input_unlock(ictx); +} + +mp_cmd_t *mp_input_read_cmd(struct input_ctx *ictx) { input_lock(ictx); - if (async_quit_request) { + read_events(ictx, 0); + if (async_quit_request && !test_abort(ictx)) { struct mp_cmd *cmd = mp_input_parse_cmd(ictx, bstr0("quit"), ""); queue_add_head(&ictx->cmd_queue, cmd); } - - if (ictx->cmd_queue.first) - time = 0; - read_events(ictx, time); struct cmd_queue *queue = &ictx->cmd_queue; if (!queue->first) { struct mp_cmd *repeated = check_autorepeat(ictx); @@ -1186,7 +1193,7 @@ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only) } } struct mp_cmd *ret = queue_peek(queue); - if (ret && !peek_only) { + if (ret) { queue_remove(queue, ret); if (ret->mouse_move) { ictx->mouse_x = ret->mouse_x; |