diff options
-rw-r--r-- | input/input.c | 123 | ||||
-rw-r--r-- | input/input.h | 5 | ||||
-rw-r--r-- | options/m_option.h | 3 | ||||
-rw-r--r-- | options/options.c | 9 | ||||
-rw-r--r-- | options/options.h | 1 | ||||
-rw-r--r-- | player/command.c | 21 | ||||
-rw-r--r-- | player/main.c | 14 |
7 files changed, 105 insertions, 71 deletions
diff --git a/input/input.c b/input/input.c index da1f85b829..9525dbcbb1 100644 --- a/input/input.c +++ b/input/input.c @@ -102,10 +102,8 @@ struct input_ctx { struct m_config_cache *opts_cache; struct input_opts *opts; - bool using_alt_gr; bool using_ar; bool using_cocoa_media_keys; - bool win_drag; // Autorepeat stuff short ar_state; @@ -174,28 +172,30 @@ struct input_opts { int enable_mouse_movements; int vo_key_input; int test; + int allow_win_drag; }; const struct m_sub_options input_config = { .opts = (const m_option_t[]) { - OPT_STRING("conf", config_file, CONF_GLOBAL | M_OPT_FILE), - OPT_INT("ar-delay", ar_delay, CONF_GLOBAL), - OPT_INT("ar-rate", ar_rate, CONF_GLOBAL), - OPT_PRINT("keylist", mp_print_key_list), - OPT_PRINT("cmdlist", mp_print_cmd_list), - OPT_FLAG("default-bindings", default_bindings, CONF_GLOBAL), - OPT_FLAG("test", test, CONF_GLOBAL), - OPT_INTRANGE("doubleclick-time", doubleclick_time, 0, 0, 1000), - OPT_FLAG("right-alt-gr", use_alt_gr, CONF_GLOBAL), - OPT_INTRANGE("key-fifo-size", key_fifo_size, CONF_GLOBAL, 2, 65000), - OPT_FLAG("cursor", enable_mouse_movements, CONF_GLOBAL), - OPT_FLAG("vo-keyboard", vo_key_input, CONF_GLOBAL), + OPT_STRING("input-conf", config_file, M_OPT_FIXED | M_OPT_FILE), + OPT_INT("input-ar-delay", ar_delay, 0), + OPT_INT("input-ar-rate", ar_rate, 0), + OPT_PRINT("input-keylist", mp_print_key_list), + OPT_PRINT("input-cmdlist", mp_print_cmd_list), + OPT_FLAG("input-default-bindings", default_bindings, 0), + OPT_FLAG("input-test", test, 0), + OPT_INTRANGE("input-doubleclick-time", doubleclick_time, 0, 0, 1000), + OPT_FLAG("input-right-alt-gr", use_alt_gr, 0), + OPT_INTRANGE("input-key-fifo-size", key_fifo_size, 0, 2, 65000), + OPT_FLAG("input-cursor", enable_mouse_movements, 0), + OPT_FLAG("input-vo-keyboard", vo_key_input, 0), #if HAVE_COCOA - OPT_FLAG("appleremote", use_appleremote, CONF_GLOBAL), - OPT_FLAG("media-keys", use_media_keys, CONF_GLOBAL), - OPT_FLAG("app-events", use_app_events, CONF_GLOBAL), + OPT_FLAG("input-appleremote", use_appleremote, 0), + OPT_FLAG("input-media-keys", use_media_keys, 0), + OPT_FLAG("input-app-events", use_app_events, M_OPT_FIXED), #endif - OPT_REPLACED("x11-keyboard", "input-vo-keyboard"), + OPT_FLAG("window-dragging", allow_win_drag, 0), + OPT_REPLACED("input-x11-keyboard", "input-vo-keyboard"), {0} }, .size = sizeof(struct input_opts), @@ -213,7 +213,9 @@ const struct m_sub_options input_config = { #endif .default_bindings = 1, .vo_key_input = 1, + .allow_win_drag = 1, }, + .change_flags = UPDATE_INPUT, }; static const char builtin_input_conf[] = @@ -985,7 +987,8 @@ bool mp_input_test_mouse_active(struct input_ctx *ictx, int x, int y) bool mp_input_test_dragging(struct input_ctx *ictx, int x, int y) { input_lock(ictx); - bool r = !ictx->win_drag || test_mouse(ictx, x, y, MP_INPUT_ALLOW_VO_DRAGGING); + bool r = !ictx->opts->allow_win_drag || + test_mouse(ictx, x, y, MP_INPUT_ALLOW_VO_DRAGGING); input_unlock(ictx); return r; } @@ -1232,12 +1235,46 @@ struct input_ctx *mp_input_init(struct mpv_global *global, return ictx; } -void mp_input_load(struct input_ctx *ictx) +static void reload_opts(struct input_ctx *ictx, bool shutdown) { - struct input_opts *input_conf = ictx->opts; - m_config_cache_update(ictx->opts_cache); +#if HAVE_COCOA + struct input_opts *opts = ictx->opts; + + if (ictx->using_ar != (opts->use_appleremote && !shutdown)) { + ictx->using_ar = !ictx->using_ar; + if (ictx->using_ar) { + cocoa_init_apple_remote(); + } else { + cocoa_uninit_apple_remote(); + } + } + + if (ictx->using_cocoa_media_keys != (opts->use_media_keys && !shutdown)) { + ictx->using_cocoa_media_keys = !ictx->using_cocoa_media_keys; + if (ictx->using_cocoa_media_keys) { + cocoa_init_media_keys(); + } else { + cocoa_uninit_media_keys(); + } + } +#endif +} + +void mp_input_update_opts(struct input_ctx *ictx) +{ + input_lock(ictx); + reload_opts(ictx, false); + input_unlock(ictx); +} + +void mp_input_load_config(struct input_ctx *ictx) +{ + input_lock(ictx); + + reload_opts(ictx, false); + // "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); @@ -1249,8 +1286,8 @@ void mp_input_load(struct input_ctx *ictx) } bool config_ok = false; - if (input_conf->config_file) - config_ok = parse_config_file(ictx, input_conf->config_file, true); + if (ictx->opts->config_file && ictx->opts->config_file[0]) + config_ok = parse_config_file(ictx, ictx->opts->config_file, true); if (!config_ok) { // Try global conf dir void *tmp = talloc_new(NULL); @@ -1260,32 +1297,17 @@ void mp_input_load(struct input_ctx *ictx) talloc_free(tmp); } - if (input_conf->use_alt_gr) { - ictx->using_alt_gr = true; - } - #if HAVE_COCOA - if (input_conf->use_app_events) { + if (ictx->opts->use_app_events) cocoa_start_event_monitor(); - } - - if (input_conf->use_appleremote) { - cocoa_init_apple_remote(); - ictx->using_ar = true; - } - - if (input_conf->use_media_keys) { - cocoa_init_media_keys(); - ictx->using_cocoa_media_keys = true; - } #endif - ictx->win_drag = ictx->global->opts->allow_win_drag; - #if defined(__MINGW32__) if (ictx->global->opts->input_file && *ictx->global->opts->input_file) mp_input_pipe_add(ictx, ictx->global->opts->input_file); #endif + + input_unlock(ictx); } static void clear_queue(struct cmd_queue *queue) @@ -1302,15 +1324,9 @@ void mp_input_uninit(struct input_ctx *ictx) if (!ictx) return; -#if HAVE_COCOA - if (ictx->using_ar) { - cocoa_uninit_apple_remote(); - } - - if (ictx->using_cocoa_media_keys) { - cocoa_uninit_media_keys(); - } -#endif + input_lock(ictx); + reload_opts(ictx, true); + input_unlock(ictx); close_input_sources(ictx); clear_queue(&ictx->cmd_queue); @@ -1328,7 +1344,10 @@ void mp_input_set_cancel(struct input_ctx *ictx, struct mp_cancel *cancel) bool mp_input_use_alt_gr(struct input_ctx *ictx) { - return ictx->using_alt_gr; + input_lock(ictx); + bool r = ictx->opts->use_alt_gr; + input_unlock(ictx); + return r; } struct mp_cmd *mp_input_parse_cmd(struct input_ctx *ictx, bstr str, diff --git a/input/input.h b/input/input.h index 16262efbe5..5b5edd580d 100644 --- a/input/input.h +++ b/input/input.h @@ -227,8 +227,9 @@ struct input_ctx *mp_input_init(struct mpv_global *global, void (*wakeup_cb)(void *ctx), void *wakeup_ctx); -// Load config, options, and devices. -void mp_input_load(struct input_ctx *ictx); +void mp_input_load_config(struct input_ctx *ictx); + +void mp_input_update_opts(struct input_ctx *ictx); void mp_input_uninit(struct input_ctx *ictx); diff --git a/options/m_option.h b/options/m_option.h index 63ba4fac03..1744023663 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -387,7 +387,8 @@ struct m_option { #define UPDATE_OSD (1 << 10) // related to OSD rendering #define UPDATE_BUILTIN_SCRIPTS (1 << 11) // osc/ytdl #define UPDATE_IMGPAR (1 << 12) // video image params overrides -#define UPDATE_OPT_LAST (1 << 12) +#define UPDATE_INPUT (1 << 13) // mostly --input-* options +#define UPDATE_OPT_LAST (1 << 13) // All bits between _FIRST and _LAST (inclusive) #define UPDATE_OPTS_MASK \ diff --git a/options/options.c b/options/options.c index 1476b384b5..3512ee15e8 100644 --- a/options/options.c +++ b/options/options.c @@ -505,8 +505,6 @@ const m_option_t mp_opts[] = { OPT_CHOICE("force-window", force_vo, 0, ({"no", 0}, {"yes", 1}, {"immediate", 2})), - OPT_FLAG("window-dragging", allow_win_drag, CONF_GLOBAL), - OPT_CHOICE("softvol", softvol, 0, ({"no", SOFTVOL_NO}, {"yes", SOFTVOL_YES}, @@ -653,14 +651,14 @@ const m_option_t mp_opts[] = { OPT_FLAG("input-terminal", consolecontrols, UPDATE_TERM), - OPT_STRING("input-file", input_file, M_OPT_FILE), - OPT_STRING("input-ipc-server", ipc_path, M_OPT_FILE | M_OPT_FIXED), + OPT_STRING("input-file", input_file, M_OPT_FILE | UPDATE_INPUT), + OPT_STRING("input-ipc-server", ipc_path, M_OPT_FILE | UPDATE_INPUT), OPT_SUBSTRUCT("screenshot", screenshot_image_opts, screenshot_conf, 0), OPT_STRING("screenshot-template", screenshot_template, 0), OPT_STRING("screenshot-directory", screenshot_directory, 0), - OPT_SUBSTRUCT("input", input_opts, input_config, 0), + OPT_SUBSTRUCT("", input_opts, input_config, 0), OPT_PRINT("list-protocols", stream_print_proto_list), OPT_PRINT("help", print_help), @@ -777,7 +775,6 @@ const struct MPOpts mp_default_opts = { .audio_buffer = 0.2, .audio_device = "auto", .audio_client_name = "mpv", - .allow_win_drag = 1, .wintitle = "${?media-title:${media-title}}${!media-title:No file} - mpv", .heartbeat_interval = 30.0, .stop_screensaver = 1, diff --git a/options/options.h b/options/options.h index b148a3dbdc..48654c4296 100644 --- a/options/options.h +++ b/options/options.h @@ -101,7 +101,6 @@ typedef struct MPOpts { double audio_buffer; mp_vo_opts *vo; - int allow_win_drag; char *wintitle; char *media_title; diff --git a/player/command.c b/player/command.c index 3a496e6de1..4bb26303b1 100644 --- a/player/command.c +++ b/player/command.c @@ -97,6 +97,9 @@ struct command_ctx { int64_t hook_seq; // for hook_handler.seq struct ao_hotplug *hotplug; + + char *cur_ipc; + char *cur_ipc_input; }; struct overlay { @@ -5581,6 +5584,7 @@ void mp_notify(struct MPContext *mpctx, int event, void *arg) void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags) { struct MPContext *mpctx = ctx; + struct command_ctx *cmd = mpctx->command_ctx; if (flags & UPDATE_TERM) mp_update_logging(mpctx); @@ -5608,6 +5612,23 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags) mp_force_video_refresh(mpctx); } } + + if (flags & UPDATE_INPUT) { + mp_input_update_opts(mpctx->input); + + // Rather coarse change-detection, but sufficient effort. + struct MPOpts *opts = mpctx->opts; + if (!bstr_equals(bstr0(cmd->cur_ipc), bstr0(opts->ipc_path)) || + !bstr_equals(bstr0(cmd->cur_ipc_input), bstr0(opts->input_file))) + { + talloc_free(cmd->cur_ipc); + talloc_free(cmd->cur_ipc_input); + cmd->cur_ipc = talloc_strdup(cmd, opts->ipc_path); + cmd->cur_ipc_input = talloc_strdup(cmd, opts->input_file); + mp_uninit_ipc(mpctx->ipc_ctx); + mpctx->ipc_ctx = mp_init_ipc(mpctx->clients, mpctx->global); + } + } } void mp_notify_property(struct MPContext *mpctx, const char *property) diff --git a/player/main.c b/player/main.c index c3488fc60c..676f82946c 100644 --- a/player/main.c +++ b/player/main.c @@ -408,6 +408,8 @@ int mp_initialize(struct MPContext *mpctx, char **options) return r == M_OPT_EXIT ? -2 : -1; } + mp_get_resume_defaults(mpctx); + // From this point on, all mpctx members are initialized. mpctx->initialized = true; mpctx->mconfig->option_set_callback = mp_on_set_option; @@ -434,12 +436,12 @@ int mp_initialize(struct MPContext *mpctx, char **options) return -1; } - MP_STATS(mpctx, "start init"); - if (!mpctx->playlist->first && !opts->player_idle_mode) return -3; - mp_input_load(mpctx->input); + MP_STATS(mpctx, "start init"); + + mp_input_load_config(mpctx->input); #if HAVE_ENCODING if (opts->encode_opts->file && opts->encode_opts->file[0]) { @@ -459,17 +461,11 @@ int mp_initialize(struct MPContext *mpctx, char **options) MP_WARN(mpctx, "There will be no OSD and no text subtitles.\n"); #endif - mp_get_resume_defaults(mpctx); - - // Lua user scripts (etc.) can call arbitrary functions. Load them at a point - // where this is safe. mp_load_scripts(mpctx); if (opts->force_vo == 2 && handle_force_window(mpctx, false) < 0) return -1; - mpctx->ipc_ctx = mp_init_ipc(mpctx->clients, mpctx->global); - #ifdef _WIN32 if (opts->w32_priority > 0) SetPriorityClass(GetCurrentProcess(), opts->w32_priority); |