mirror of https://github.com/mpv-player/mpv
input: separate creation and loading of config
Until now, creating the input_ctx was delayed until the command line and config files were parsed. Separate creation and loading so that input_ctx is available from start. This should make it possible to simplify some things. For example, some complications with Cocoa were apparently only because input_ctx was available only "later". (Although I'm not sure if this is still relevant, or if the Cocoa code should even be organized this way.)
This commit is contained in:
parent
acf6aef882
commit
b4d1494336
|
@ -1196,21 +1196,14 @@ done:
|
|||
|
||||
struct input_ctx *mp_input_init(struct mpv_global *global)
|
||||
{
|
||||
struct input_opts *input_conf = global->opts->input_opts;
|
||||
|
||||
struct input_ctx *ictx = talloc_ptrtype(NULL, ictx);
|
||||
*ictx = (struct input_ctx){
|
||||
.global = global,
|
||||
.opts = input_conf,
|
||||
.log = mp_log_new(ictx, global->log, "input"),
|
||||
.key_fifo_size = input_conf->key_fifo_size,
|
||||
.doubleclick_time = input_conf->doubleclick_time,
|
||||
.opts = talloc_zero(ictx, struct input_opts), // replaced later
|
||||
.ar_state = -1,
|
||||
.ar_delay = input_conf->ar_delay,
|
||||
.ar_rate = input_conf->ar_rate,
|
||||
.default_bindings = input_conf->default_bindings,
|
||||
.log = mp_log_new(ictx, global->log, "input"),
|
||||
.mouse_section = "default",
|
||||
.test = input_conf->test,
|
||||
};
|
||||
|
||||
if (sem_init(&ictx->wakeup, 0, 0)) {
|
||||
|
@ -1225,6 +1218,21 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
|||
MP_INPUT_ALLOW_HIDE_CURSOR);
|
||||
mp_input_set_section_mouse_area(ictx, NULL, INT_MIN, INT_MIN, INT_MAX, INT_MAX);
|
||||
|
||||
return ictx;
|
||||
}
|
||||
|
||||
void mp_input_load(struct input_ctx *ictx)
|
||||
{
|
||||
struct input_opts *input_conf = ictx->global->opts->input_opts;
|
||||
|
||||
ictx->opts = input_conf;
|
||||
ictx->key_fifo_size = input_conf->key_fifo_size;
|
||||
ictx->doubleclick_time = input_conf->doubleclick_time;
|
||||
ictx->ar_delay = input_conf->ar_delay;
|
||||
ictx->ar_rate = input_conf->ar_rate;
|
||||
ictx->default_bindings = input_conf->default_bindings;
|
||||
ictx->test = input_conf->test;
|
||||
|
||||
// "Uncomment" the default key bindings in etc/input.conf and add them.
|
||||
// All lines that do not start with '# ' are parsed.
|
||||
bstr builtin = bstr0(builtin_input_conf);
|
||||
|
@ -1238,9 +1246,9 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
|||
bool config_ok = false;
|
||||
if (input_conf->config_file)
|
||||
config_ok = parse_config_file(ictx, input_conf->config_file, true);
|
||||
if (!config_ok && global->opts->load_config) {
|
||||
if (!config_ok && ictx->global->opts->load_config) {
|
||||
// Try global conf dir
|
||||
char *file = mp_find_config_file(NULL, global, "input.conf");
|
||||
char *file = mp_find_config_file(NULL, ictx->global, "input.conf");
|
||||
config_ok = file && parse_config_file(ictx, file, false);
|
||||
talloc_free(file);
|
||||
}
|
||||
|
@ -1274,7 +1282,7 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
|||
}
|
||||
#endif
|
||||
|
||||
ictx->win_drag = global->opts->allow_win_drag;
|
||||
ictx->win_drag = ictx->global->opts->allow_win_drag;
|
||||
|
||||
if (input_conf->in_file && input_conf->in_file[0]) {
|
||||
#if !defined(__MINGW32__) || HAVE_WAIO
|
||||
|
@ -1283,8 +1291,6 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
|||
MP_ERR(ictx, "Pipes not available.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
return ictx;
|
||||
}
|
||||
|
||||
static void clear_queue(struct cmd_queue *queue)
|
||||
|
|
|
@ -221,6 +221,9 @@ bool mp_input_test_dragging(struct input_ctx *ictx, int x, int y);
|
|||
struct mpv_global;
|
||||
struct input_ctx *mp_input_init(struct mpv_global *global);
|
||||
|
||||
// Load config, options, and devices.
|
||||
void mp_input_load(struct input_ctx *ictx);
|
||||
|
||||
void mp_input_uninit(struct input_ctx *ictx);
|
||||
|
||||
// Sleep for the given amount of seconds, until mp_input_wakeup() is called,
|
||||
|
|
|
@ -333,6 +333,7 @@ struct MPContext *mp_create(void)
|
|||
|
||||
mpctx->global->opts = mpctx->opts;
|
||||
|
||||
mpctx->input = mp_input_init(mpctx->global);
|
||||
screenshot_init(mpctx);
|
||||
mpctx->mixer = mixer_init(mpctx, mpctx->global);
|
||||
command_init(mpctx);
|
||||
|
@ -377,7 +378,7 @@ int mp_initialize(struct MPContext *mpctx)
|
|||
m_config_set_option0(mpctx->mconfig, "input-file", "/dev/stdin");
|
||||
}
|
||||
|
||||
mpctx->input = mp_input_init(mpctx->global);
|
||||
mp_input_load(mpctx->input);
|
||||
mp_input_set_cancel(mpctx->input, mpctx->playback_abort);
|
||||
|
||||
mp_dispatch_set_wakeup_fn(mpctx->dispatch, wakeup_playloop, mpctx);
|
||||
|
|
Loading…
Reference in New Issue