From f1b5198b35285111c3084c8d53d69194a5fc08e0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 8 Sep 2013 01:44:47 +0200 Subject: input: rearrange code Let all key events go through mp_input_feed_key() internally, and also do double click and MP_INPUT_RELEASE_ALL handling there. Move check_autorepeat() to where it's actually used. --- mpvcore/input/input.c | 88 +++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c index 1de9f366f9..bf073d4fdd 100644 --- a/mpvcore/input/input.c +++ b/mpvcore/input/input.c @@ -1413,6 +1413,7 @@ static void update_mouse_section(struct input_ctx *ictx) get_cmd_from_keys(ictx, old, 1, (int[]){MP_KEY_MOUSE_LEAVE}); if (cmd) queue_add_tail(&ictx->cmd_queue, cmd); + ictx->got_new_events = true; } } @@ -1421,6 +1422,7 @@ static void release_down_cmd(struct input_ctx *ictx) if (ictx->current_down_cmd && ictx->current_down_cmd->key_up_follows) { ictx->current_down_cmd->key_up_follows = false; queue_add_tail(&ictx->cmd_queue, ictx->current_down_cmd); + ictx->got_new_events = true; } else { talloc_free(ictx->current_down_cmd); } @@ -1572,38 +1574,8 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale) queue_add_tail(&ictx->cmd_queue, cmd); } -static mp_cmd_t *check_autorepeat(struct input_ctx *ictx) -{ - // No input : autorepeat ? - if (ictx->ar_rate > 0 && ictx->ar_state >= 0 && ictx->num_key_down > 0 - && !(ictx->key_down[ictx->num_key_down - 1] & MP_NO_REPEAT_KEY)) { - int64_t t = mp_time_us(); - if (ictx->last_ar + 2000000 < t) - ictx->last_ar = t; - // First time : wait delay - if (ictx->ar_state == 0 - && (t - ictx->last_key_down) >= ictx->ar_delay * 1000) - { - if (!ictx->current_down_cmd) { - ictx->ar_state = -1; - return NULL; - } - ictx->ar_state = 1; - ictx->last_ar = ictx->last_key_down + ictx->ar_delay * 1000; - return mp_cmd_clone(ictx->current_down_cmd); - // Then send rate / sec event - } else if (ictx->ar_state == 1 - && (t - ictx->last_ar) >= 1000000 / ictx->ar_rate) { - ictx->last_ar += 1000000 / ictx->ar_rate; - return mp_cmd_clone(ictx->current_down_cmd); - } - } - return NULL; -} - -static void mp_input_feed_key(struct input_ctx *ictx, int code) +static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale) { - ictx->got_new_events = true; if (code == MP_INPUT_RELEASE_ALL) { mp_msg(MSGT_INPUT, MSGL_DBG2, "input: release all\n"); ictx->num_key_down = 0; @@ -1611,32 +1583,30 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code) update_mouse_section(ictx); return; } - interpret_key(ictx, code, 1); -} - -void mp_input_put_key(struct input_ctx *ictx, int code) -{ - input_lock(ictx); double now = mp_time_sec(); int doubleclick_time = ictx->doubleclick_time; // ignore system-doubleclick if we generate these events ourselves int unmod = code & ~MP_KEY_MODIFIER_MASK; - if (doubleclick_time && MP_KEY_IS_MOUSE_BTN_DBL(unmod)) { - input_unlock(ictx); + if (doubleclick_time && MP_KEY_IS_MOUSE_BTN_DBL(unmod)) return; - } - mp_input_feed_key(ictx, code); + interpret_key(ictx, code, scale); if (code & MP_KEY_STATE_DOWN) { code &= ~MP_KEY_STATE_DOWN; if (ictx->last_doubleclick_key_down == code && now - ictx->last_doubleclick_time < doubleclick_time / 1000.0) { if (code >= MP_MOUSE_BTN0 && code <= MP_MOUSE_BTN2) - mp_input_feed_key(ictx, code - MP_MOUSE_BTN0 + MP_MOUSE_BTN0_DBL); + interpret_key(ictx, code - MP_MOUSE_BTN0 + MP_MOUSE_BTN0_DBL, 1); } ictx->last_doubleclick_key_down = code; ictx->last_doubleclick_time = now; } +} + +void mp_input_put_key(struct input_ctx *ictx, int code) +{ + input_lock(ictx); + mp_input_feed_key(ictx, code, 1); input_unlock(ictx); } @@ -1653,7 +1623,7 @@ void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t) void mp_input_put_axis(struct input_ctx *ictx, int direction, double value) { input_lock(ictx); - interpret_key(ictx, direction, value); + mp_input_feed_key(ictx, direction, value); input_unlock(ictx); } @@ -1686,6 +1656,7 @@ void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y) talloc_free(tail); } queue_add_tail(&ictx->cmd_queue, cmd); + ictx->got_new_events = true; } } input_unlock(ictx); @@ -1715,7 +1686,7 @@ static void read_key_fd(struct input_ctx *ictx, struct input_fd *key_fd) { int code = key_fd->read_key(key_fd->ctx, key_fd->fd); if (code >= 0 || code == MP_INPUT_RELEASE_ALL) { - mp_input_feed_key(ictx, code); + mp_input_feed_key(ictx, code, 1); return; } @@ -1846,6 +1817,35 @@ int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd) return 1; } +static mp_cmd_t *check_autorepeat(struct input_ctx *ictx) +{ + // No input : autorepeat ? + if (ictx->ar_rate > 0 && ictx->ar_state >= 0 && ictx->num_key_down > 0 + && !(ictx->key_down[ictx->num_key_down - 1] & MP_NO_REPEAT_KEY)) { + int64_t t = mp_time_us(); + if (ictx->last_ar + 2000000 < t) + ictx->last_ar = t; + // First time : wait delay + if (ictx->ar_state == 0 + && (t - ictx->last_key_down) >= ictx->ar_delay * 1000) + { + if (!ictx->current_down_cmd) { + ictx->ar_state = -1; + return NULL; + } + ictx->ar_state = 1; + ictx->last_ar = ictx->last_key_down + ictx->ar_delay * 1000; + return mp_cmd_clone(ictx->current_down_cmd); + // Then send rate / sec event + } else if (ictx->ar_state == 1 + && (t - ictx->last_ar) >= 1000000 / ictx->ar_rate) { + ictx->last_ar += 1000000 / ictx->ar_rate; + return mp_cmd_clone(ictx->current_down_cmd); + } + } + return NULL; +} + /** * \param peek_only when set, the returned command stays in the queue. * Do not free the returned cmd whe you set this! -- cgit v1.2.3