gchar *get_config_file_path(void) { gchar *config_dir; gchar *result; config_dir = get_config_dir_path(); result = g_build_filename(config_dir, "gnome-mpv.conf", NULL); g_free(config_dir); return result; }
void gmpv_mpv_obj_initialize(GmpvMpvObj *mpv) { GSettings *main_settings = g_settings_new(CONFIG_ROOT); gchar *config_dir = get_config_dir_path(); gchar *mpvopt = NULL; gchar *current_vo = NULL; gchar *mpv_version = NULL; const struct { const gchar *name; const gchar *value; } options[] = { {"osd-level", "1"}, {"softvol", "yes"}, {"force-window", "yes"}, {"input-default-bindings", "yes"}, {"audio-client-name", ICON_NAME}, {"title", "${media-title}"}, {"autofit-larger", "75%"}, {"window-scale", "1"}, {"pause", "no"}, {"ytdl", "yes"}, {"osd-bar", "no"}, {"input-cursor", "no"}, {"cursor-autohide", "no"}, {"softvol-max", "100"}, {"config", "yes"}, {"screenshot-template", "gnome-mpv-shot%n"}, {"config-dir", config_dir}, {NULL, NULL} }; g_assert(mpv->mpv_ctx); for(gint i = 0; options[i].name; i++) { g_debug( "Applying default option --%s=%s", options[i].name, options[i].value ); mpv_set_option_string( mpv->mpv_ctx, options[i].name, options[i].value ); } if(g_settings_get_boolean(main_settings, "mpv-config-enable")) { gchar *mpv_conf = g_settings_get_string (main_settings, "mpv-config-file"); g_info("Loading config file: %s", mpv_conf); mpv_load_config_file(mpv->mpv_ctx, mpv_conf); g_free(mpv_conf); } if(g_settings_get_boolean(main_settings, "mpv-input-config-enable")) { gchar *input_conf = g_settings_get_string (main_settings, "mpv-input-config-file"); g_info("Loading input config file: %s", input_conf); load_input_conf(mpv, input_conf); g_free(input_conf); } else { load_input_conf(mpv, NULL); } mpvopt = g_settings_get_string(main_settings, "mpv-options"); g_debug("Applying extra mpv options: %s", mpvopt); /* Apply extra options */ if(mpv_obj_apply_args(mpv->mpv_ctx, mpvopt) < 0) { const gchar *msg = _("Failed to apply one or more MPV options."); g_signal_emit_by_name(mpv, "mpv-error", msg); } if(mpv->force_opengl) { g_info("Forcing --vo=opengl-cb"); mpv_set_option_string(mpv->mpv_ctx, "vo", "opengl-cb"); } else { g_debug( "Attaching mpv window to wid %#x", (guint)mpv->wid ); mpv_set_option(mpv->mpv_ctx, "wid", MPV_FORMAT_INT64, &mpv->wid); } mpv_observe_property(mpv->mpv_ctx, 0, "aid", MPV_FORMAT_INT64); mpv_observe_property(mpv->mpv_ctx, 0, "chapters", MPV_FORMAT_INT64); mpv_observe_property(mpv->mpv_ctx, 0, "core-idle", MPV_FORMAT_FLAG); mpv_observe_property(mpv->mpv_ctx, 0, "fullscreen", MPV_FORMAT_FLAG); mpv_observe_property(mpv->mpv_ctx, 0, "pause", MPV_FORMAT_FLAG); mpv_observe_property(mpv->mpv_ctx, 0, "length", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv->mpv_ctx, 0, "media-title", MPV_FORMAT_STRING); mpv_observe_property(mpv->mpv_ctx, 0, "playlist-pos", MPV_FORMAT_INT64); mpv_observe_property(mpv->mpv_ctx, 0, "track-list", MPV_FORMAT_NODE); mpv_observe_property(mpv->mpv_ctx, 0, "volume", MPV_FORMAT_DOUBLE); mpv_set_wakeup_callback(mpv->mpv_ctx, wakeup_callback, mpv); mpv_check_error(mpv_initialize(mpv->mpv_ctx)); mpv_version = gmpv_mpv_obj_get_property_string(mpv, "mpv-version"); current_vo = gmpv_mpv_obj_get_property_string(mpv, "current-vo"); g_info("Using %s", mpv_version); if(current_vo && !GDK_IS_X11_DISPLAY(gdk_display_get_default())) { g_info( "The chosen vo is %s but the display is not X11; " "forcing --vo=opengl-cb and resetting", current_vo ); mpv->force_opengl = TRUE; mpv->state.paused = FALSE; gmpv_mpv_obj_reset(mpv); } else { GSettings *win_settings; gdouble volume; win_settings = g_settings_new(CONFIG_WIN_STATE); volume = g_settings_get_double(win_settings, "volume")*100; g_debug("Setting volume to %f", volume); mpv_set_property( mpv->mpv_ctx, "volume", MPV_FORMAT_DOUBLE, &volume ); /* The vo should be opengl-cb if current_vo is NULL*/ if(!current_vo) { mpv->opengl_ctx = mpv_get_sub_api ( mpv->mpv_ctx, MPV_SUB_API_OPENGL_CB ); } gmpv_mpv_opt_handle_msg_level(mpv); gmpv_mpv_opt_handle_fs(mpv); gmpv_mpv_opt_handle_geometry(mpv); mpv->force_opengl = FALSE; mpv->state.ready = TRUE; g_signal_emit_by_name(mpv, "mpv-init"); g_clear_object(&win_settings); } g_clear_object(&main_settings); g_free(config_dir); g_free(mpvopt); mpv_free(current_vo); mpv_free(mpv_version); }