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. --- Makefile | 1 - core/command.c | 2 +- core/input/input.c | 40 +++++++++++++++++++++++++++- core/input/input.h | 9 +++++-- core/mp_core.h | 1 - core/mp_fifo.c | 78 ------------------------------------------------------ core/mp_fifo.h | 18 +++++++++---- core/mplayer.c | 26 ++++++++---------- core/options.c | 3 +-- core/options.h | 2 +- video/out/vo.c | 3 +-- video/out/vo.h | 1 - 12 files changed, 74 insertions(+), 110 deletions(-) delete mode 100644 core/mp_fifo.c diff --git a/Makefile b/Makefile index 2a912182d7..6b6f05dc86 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,6 @@ SOURCES = talloc.c \ core/m_property.c \ core/m_struct.c \ core/mp_common.c \ - core/mp_fifo.c \ core/mp_msg.c \ core/mp_ring.c \ core/mplayer.c \ diff --git a/core/command.c b/core/command.c index dec3ae9c9f..46e747cf2b 100644 --- a/core/command.c +++ b/core/command.c @@ -2431,7 +2431,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) break; case MP_CMD_KEYDOWN_EVENTS: - mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i); + mp_input_put_key(mpctx->input, cmd->args[0].v.i); break; case MP_CMD_ENABLE_INPUT_SECTION: 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); diff --git a/core/mp_core.h b/core/mp_core.h index 600c56c4d6..b9c835e497 100644 --- a/core/mp_core.h +++ b/core/mp_core.h @@ -115,7 +115,6 @@ enum { typedef struct MPContext { struct MPOpts opts; struct m_config *mconfig; - struct mp_fifo *key_fifo; struct input_ctx *input; struct osd_state *osd; struct mp_osd_msg *osd_msg_stack; diff --git a/core/mp_fifo.c b/core/mp_fifo.c deleted file mode 100644 index 1c83e99dcd..0000000000 --- a/core/mp_fifo.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include "osdep/timer.h" -#include "input/input.h" -#include "input/keycodes.h" -#include "mp_fifo.h" -#include "talloc.h" -#include "core/options.h" - - -struct mp_fifo { - struct MPOpts *opts; - struct input_ctx *input; - int last_key_down; - double last_down_time; -}; - -struct mp_fifo *mp_fifo_create(struct input_ctx *input, struct MPOpts *opts) -{ - struct mp_fifo *fifo = talloc_zero(NULL, struct mp_fifo); - fifo->input = input; - fifo->opts = opts; - return fifo; -} - -static void put_double(struct mp_fifo *fifo, int code) -{ - if (code >= MP_MOUSE_BTN0 && code <= MP_MOUSE_BTN2) - mp_input_feed_key(fifo->input, code - MP_MOUSE_BTN0 + MP_MOUSE_BTN0_DBL); -} - -void mplayer_put_key(struct mp_fifo *fifo, int code) -{ - double now = mp_time_sec(); - int doubleclick_time = fifo->opts->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(fifo->input, code); - if (code & MP_KEY_STATE_DOWN) { - code &= ~MP_KEY_STATE_DOWN; - if (fifo->last_key_down == code - && now - fifo->last_down_time < doubleclick_time / 1000.0) - put_double(fifo, code); - fifo->last_key_down = code; - fifo->last_down_time = now; - } -} - -void mplayer_put_key_utf8(struct mp_fifo *fifo, int mods, struct bstr t) -{ - while (t.len) { - int code = bstr_decode_utf8(t, &t); - if (code < 0) - break; - mplayer_put_key(fifo, code | mods); - } -} diff --git a/core/mp_fifo.h b/core/mp_fifo.h index f08cd00415..91a481a5b6 100644 --- a/core/mp_fifo.h +++ b/core/mp_fifo.h @@ -20,13 +20,21 @@ #define MPLAYER_MP_FIFO_H #include "core/bstr.h" +#include "core/input/input.h" struct mp_fifo; -void mplayer_put_key(struct mp_fifo *fifo, int code); -void mplayer_put_key_utf8(struct mp_fifo *fifo, int mods, struct bstr code); -// Can be freed with talloc_free() struct input_ctx; -struct MPOpts; -struct mp_fifo *mp_fifo_create(struct input_ctx *input, struct MPOpts *opts); + +// New code should use the wrapped functions directly. + +static inline void mplayer_put_key(struct mp_fifo *fifo, int code) +{ + mp_input_put_key((struct input_ctx *)fifo, code); +} + +static inline void mplayer_put_key_utf8(struct mp_fifo *fifo, int mods, struct bstr t) +{ + mp_input_put_key_utf8((struct input_ctx *)fifo, mods, t); +} #endif /* MPLAYER_MP_FIFO_H */ diff --git a/core/mplayer.c b/core/mplayer.c index 28d120f636..bf284551a1 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -588,8 +588,6 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx, mpctx->ass_library = NULL; #endif - talloc_free(mpctx->key_fifo); - if (how != EXIT_NONE) { const char *reason; switch (how) { @@ -2384,9 +2382,8 @@ int reinit_video_chain(struct MPContext *mpctx) double ar = -1.0; //================== Init VIDEO (codec & libvo) ========================== if (!opts->fixed_vo || !(mpctx->initialized_flags & INITIALIZED_VO)) { - mpctx->video_out - = init_best_video_out(&opts->vo, mpctx->key_fifo, mpctx->input, - mpctx->encode_lavc_ctx); + mpctx->video_out = init_best_video_out(&opts->vo, mpctx->input, + mpctx->encode_lavc_ctx); if (!mpctx->video_out) { mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Error opening/initializing " "the selected video_out (-vo) device.\n"); @@ -3736,13 +3733,6 @@ static void run_playloop(struct MPContext *mpctx) execute_queued_seek(mpctx); } -static int read_keys(void *ctx, int fd) -{ - if (getch2(ctx)) - return MP_INPUT_NOTHING; - return MP_INPUT_DEAD; -} - static bool attachment_is_font(struct demux_attachment *att) { if (!att->name || !att->type || !att->data || !att->data_size) @@ -3849,20 +3839,26 @@ static void check_previous_track_selection(struct MPContext *mpctx) talloc_free(h); } +static int read_keys(void *ctx, int fd) +{ + if (getch2(ctx)) + return MP_INPUT_NOTHING; + return MP_INPUT_DEAD; +} + static void init_input(struct MPContext *mpctx) { mpctx->input = mp_input_init(&mpctx->opts.input, mpctx->opts.load_config); - mpctx->key_fifo = mp_fifo_create(mpctx->input, &mpctx->opts); if (mpctx->opts.slave_mode) mp_input_add_cmd_fd(mpctx->input, 0, USE_FD0_CMD_SELECT, MP_INPUT_SLAVE_CMD_FUNC, NULL); else if (mpctx->opts.consolecontrols) - mp_input_add_key_fd(mpctx->input, 0, 1, read_keys, NULL, mpctx->key_fifo); + mp_input_add_key_fd(mpctx->input, 0, 1, read_keys, NULL, mpctx->input); // Set the libstream interrupt callback stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input); #ifdef CONFIG_COCOA cocoa_set_input_context(mpctx->input); - cocoa_set_key_fifo(mpctx->key_fifo); + cocoa_set_key_fifo((struct mp_fifo *)mpctx->input); #endif } diff --git a/core/options.c b/core/options.c index a12d041420..5e1104d3e6 100644 --- a/core/options.c +++ b/core/options.c @@ -686,7 +686,6 @@ const m_option_t mp_opts[] = { OPT_INTRANGE("key-fifo-size", input.key_fifo_size, CONF_GLOBAL, 2, 65000), OPT_FLAG("consolecontrols", consolecontrols, CONF_GLOBAL), OPT_FLAG("mouse-movements", vo.enable_mouse_movements, CONF_GLOBAL), - OPT_INTRANGE("doubleclick-time", doubleclick_time, 0, 0, 1000), #ifdef CONFIG_TV {"tvscan", (void *) tvscan_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, #endif /* CONFIG_TV */ @@ -782,7 +781,6 @@ const struct MPOpts mp_default_opts = { .initial_audio_sync = 1, .term_osd = 2, .consolecontrols = 1, - .doubleclick_time = 300, .play_frames = -1, .keep_open = 0, .audio_id = -1, @@ -820,6 +818,7 @@ const struct MPOpts mp_default_opts = { }, .input = { .key_fifo_size = 7, + .doubleclick_time = 300, .ar_delay = 200, .ar_rate = 40, .use_joystick = 1, diff --git a/core/options.h b/core/options.h index 48a51a9c27..80398bae95 100644 --- a/core/options.h +++ b/core/options.h @@ -119,7 +119,6 @@ typedef struct MPOpts { int player_idle_mode; int slave_mode; int consolecontrols; - int doubleclick_time; int list_properties; struct m_rel_time play_start; struct m_rel_time play_end; @@ -228,6 +227,7 @@ typedef struct MPOpts { struct input_conf { char *config_file; + int doubleclick_time; int key_fifo_size; int ar_delay; int ar_rate; diff --git a/video/out/vo.c b/video/out/vo.c index f3af26273d..b2bf8765a8 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -285,7 +285,6 @@ static void replace_legacy_vo_name(bstr *name) } struct vo *init_best_video_out(struct mp_vo_opts *opts, - struct mp_fifo *key_fifo, struct input_ctx *input_ctx, struct encode_lavc_context *encode_lavc_ctx) { @@ -294,7 +293,7 @@ struct vo *init_best_video_out(struct mp_vo_opts *opts, struct vo *vo = talloc_ptrtype(NULL, vo); struct vo initial_values = { .opts = opts, - .key_fifo = key_fifo, + .key_fifo = (struct mp_fifo *)input_ctx, .encode_lavc_ctx = encode_lavc_ctx, .input_ctx = input_ctx, .event_fd = -1, diff --git a/video/out/vo.h b/video/out/vo.h index 9300fa37c0..611f7ec6f3 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -291,7 +291,6 @@ struct vo { }; struct vo *init_best_video_out(struct mp_vo_opts *opts, - struct mp_fifo *key_fifo, struct input_ctx *input_ctx, struct encode_lavc_context *encode_lavc_ctx); int vo_reconfig(struct vo *vo, struct mp_image_params *p, int flags); -- cgit v1.2.3