From b4d149433651bf45de89a44d621e6985235b090f Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 27 Sep 2014 15:47:49 +0200 Subject: 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.) --- input/input.c | 34 ++++++++++++++++++++-------------- input/input.h | 3 +++ 2 files changed, 23 insertions(+), 14 deletions(-) (limited to 'input') diff --git a/input/input.c b/input/input.c index 6984676dfb..c8dad7d3c9 100644 --- a/input/input.c +++ b/input/input.c @@ -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) diff --git a/input/input.h b/input/input.h index c37a55da1c..9a6596d3d2 100644 --- a/input/input.h +++ b/input/input.h @@ -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, -- cgit v1.2.3