diff options
author | wm4 <wm4@nowhere> | 2013-12-21 19:33:45 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-21 20:50:13 +0100 |
commit | ed71606e65e697ea6bc9fc78caf2dd4089dc0aeb (patch) | |
tree | d3b80546a8e40c821ee7575c236d813021b8b7c8 /player | |
parent | dadf3a9a46d31a101aeaa1256b0d6f914eb32f1e (diff) | |
download | mpv-ed71606e65e697ea6bc9fc78caf2dd4089dc0aeb.tar.bz2 mpv-ed71606e65e697ea6bc9fc78caf2dd4089dc0aeb.tar.xz |
input: rework how input sources are added
Until now, there were two functions to add input sources (stuff like
stdin input, slave mode, lirc, joystick). Unify them to a single
function (mp_input_add_fd()), and make sure the associated callbacks
always have a context parameter.
Change the lirc and joystick code such that they take store their state
in a context struct (probably worthless), and use the new mp_msg
replacements (the point of this refactoring).
Additionally, get rid of the ugly USE_FD0_CMD_SELECT etc. ifdeffery in
the terminal handling code.
Diffstat (limited to 'player')
-rw-r--r-- | player/main.c | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/player/main.c b/player/main.c index 3dde2f6101..dfcc45cf44 100644 --- a/player/main.c +++ b/player/main.c @@ -270,28 +270,6 @@ static void osdep_preinit(int *p_argc, char ***p_argv) mp_time_init(); } -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->global); - 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->input); - // Set the libstream interrupt callback - stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input); - -#if HAVE_COCOA - cocoa_set_input_context(mpctx->input); -#endif -} - static int cfg_include(void *ctx, char *filename, int flags) { struct MPContext *mpctx = ctx; @@ -379,7 +357,11 @@ static int mpv_main(int argc, char *argv[]) set_priority(); #endif - init_input(mpctx); + mpctx->input = mp_input_init(mpctx->global); + stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input); +#if HAVE_COCOA + cocoa_set_input_context(mpctx->input); +#endif #if HAVE_ENCODING if (opts->encode_output.file && *opts->encode_output.file) { @@ -397,6 +379,11 @@ static int mpv_main(int argc, char *argv[]) } #endif + if (mpctx->opts->slave_mode) + terminal_setup_stdin_cmd_input(mpctx->input); + else if (mpctx->opts->consolecontrols) + terminal_setup_getch(mpctx->input); + if (opts->consolecontrols) getch2_enable(); |