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.
This commit is contained in:
wm4 2013-07-02 14:00:24 +02:00
parent 451f6788ce
commit 70a8079c8e
12 changed files with 74 additions and 110 deletions

View File

@ -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 \

View File

@ -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:

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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 <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#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);
}
}

View File

@ -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 */

View File

@ -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
}

View File

@ -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,

View File

@ -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;

View File

@ -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,

View File

@ -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);