From 70a8079c8e0109eb89db3f3278be2a75a710c95e Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 2 Jul 2013 14:00:24 +0200 Subject: core: remove mp_fifo indirection For some reason mp_fifo specifically handled double clicks, and other than that was a pointless wrapper around input.c functionality. Move the double click handling into input.c, and get rid of mp_fifo. Add some compatibility wrappers, because so much VO code uses these functions. Where struct mp_fifo is still used it's just a casted struct input_ctx. --- core/input/input.c | 40 +++++++++++++++++++++++++++++++++++++++- core/input/input.h | 9 +++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) (limited to 'core/input') diff --git a/core/input/input.c b/core/input/input.c index 9f63114530..278793100d 100644 --- a/core/input/input.c +++ b/core/input/input.c @@ -520,6 +520,10 @@ struct input_ctx { int64_t last_key_down; struct mp_cmd *current_down_cmd; + int doubleclick_time; + int last_doubleclick_key_down; + double last_doubleclick_time; + // Mouse position on the consumer side (as command.c sees it) int mouse_x, mouse_y; char *mouse_section; // last section to receive mouse event @@ -580,6 +584,7 @@ static const m_option_t input_conf[] = { static const m_option_t mp_input_opts[] = { { "input", (void *)&input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, + OPT_INTRANGE("doubleclick-time", input.doubleclick_time, 0, 0, 1000), OPT_FLAG("joystick", input.use_joystick, CONF_GLOBAL), OPT_FLAG("lirc", input.use_lirc, CONF_GLOBAL), OPT_FLAG("lircc", input.use_lircc, CONF_GLOBAL), @@ -1417,7 +1422,7 @@ static bool key_updown_ok(enum mp_command_type cmd) } } -void mp_input_feed_key(struct input_ctx *ictx, int code) +static void mp_input_feed_key(struct input_ctx *ictx, int code) { ictx->got_new_events = true; if (code == MP_INPUT_RELEASE_ALL) { @@ -1443,6 +1448,38 @@ void mp_input_feed_key(struct input_ctx *ictx, int code) add_key_cmd(ictx, cmd); } +void mp_input_put_key(struct input_ctx *ictx, int code) +{ + 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)) + return; + mp_input_feed_key(ictx, code); + 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); + } + ictx->last_doubleclick_key_down = code; + ictx->last_doubleclick_time = now; + } +} + +void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t) +{ + while (t.len) { + int code = bstr_decode_utf8(t, &t); + if (code < 0) + break; + mp_input_put_key(ictx, code | mods); + } +} + static void trigger_mouse_leave(struct input_ctx *ictx, char *new_section) { if (!new_section) @@ -1980,6 +2017,7 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf, struct input_ctx *ictx = talloc_ptrtype(NULL, ictx); *ictx = (struct input_ctx){ .key_fifo_size = input_conf->key_fifo_size, + .doubleclick_time = input_conf->doubleclick_time, .ar_state = -1, .ar_delay = input_conf->ar_delay, .ar_rate = input_conf->ar_rate, diff --git a/core/input/input.h b/core/input/input.h index 5b6170c7ae..2a9b3832c1 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -175,8 +175,13 @@ int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select, int read_func(void *ctx, int fd), int close_func(int fd), void *ctx); -// Feed a keypress (alternative to being returned from read_func above) -void mp_input_feed_key(struct input_ctx *ictx, int code); +// Process keyboard input. code is a key code from keycodes.h, possibly +// with modifiers applied. MP_INPUT_RELEASE_ALL is also a valid value. +void mp_input_put_key(struct input_ctx *ictx, int code); + +// Like mp_input_put_key(), but process all UTF-8 characters in the given +// string as key events. +void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t); // Update mouse position (in window coordinates). void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y); -- cgit v1.2.3