diff --git a/core/cog-utils.c b/core/cog-utils.c index c2696a91..93428966 100644 --- a/core/cog-utils.c +++ b/core/cog-utils.c @@ -384,6 +384,39 @@ cog_option_entries_from_class (GObjectClass *klass) return g_steal_pointer (&entries); } +/** + * cog_key_file_parse_params_string: + * @key_file: A key file + * @group_name: Name of a key file group + * @params_string: Input string + * @error: Where to store an error, if any + * + * Parse parameters string storing values in a key file. + * + * Since: 0.18 + */ +void +cog_key_file_parse_params_string(GKeyFile *key_file, const char *group_name, const char *params_string) +{ + g_return_if_fail(key_file); + g_return_if_fail(group_name); + g_return_if_fail(params_string); + + g_auto(GStrv) params = g_strsplit(params_string, ",", 0); + for (unsigned i = 0; params[i]; i++) { + g_auto(GStrv) kv = g_strsplit(params[i], "=", 2); + if (g_strv_length(kv) != 2) { + g_warning("%s: Invalid parameter syntax '%s'.", __func__, params[i]); + continue; + } + + const char *k = g_strstrip(kv[0]); + const char *v = g_strstrip(kv[1]); + + g_key_file_set_value(key_file, group_name, k, v); + } +} + /** * cog_apply_properties_from_key_file: * @object: An object to set properties on diff --git a/core/cog-utils.h b/core/cog-utils.h index dd24468b..49d395b4 100644 --- a/core/cog-utils.h +++ b/core/cog-utils.h @@ -28,6 +28,10 @@ char* cog_uri_guess_from_user_input (const char *uri_like, GError **error); GOptionEntry* cog_option_entries_from_class (GObjectClass *klass); + +void +cog_key_file_parse_params_string(GKeyFile *key_file, const char *group_name, const char *params_string); + gboolean cog_apply_properties_from_key_file(GObject *object, GKeyFile *key_file, const char *group_name, GError **error); diff --git a/platform/drm/cog-platform-drm.c b/platform/drm/cog-platform-drm.c index 951988bf..f8377bdb 100644 --- a/platform/drm/cog-platform-drm.c +++ b/platform/drm/cog-platform-drm.c @@ -239,45 +239,16 @@ static void init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string) { GKeyFile *key_file = cog_shell_get_config_file(shell); + + if (params_string) + cog_key_file_parse_params_string(key_file, "drm", params_string); + if (key_file) { g_autoptr(GError) error = NULL; if (!cog_apply_properties_from_key_file(G_OBJECT(self), key_file, "drm", &error)) g_warning("Reading config file: %s", error->message); } - if (params_string) { - g_auto(GStrv) params = g_strsplit(params_string, ",", 0); - for (unsigned i = 0; params[i]; i++) { - g_auto(GStrv) kv = g_strsplit(params[i], "=", 2); - if (g_strv_length(kv) != 2) { - g_warning("Invalid parameter syntax '%s'.", params[i]); - continue; - } - - const char *k = g_strstrip(kv[0]); - const char *v = g_strstrip(kv[1]); - - if (g_strcmp0(k, "renderer") == 0) { - if (g_strcmp0(v, "modeset") == 0) - self->use_gles = false; - else if (g_strcmp0(v, "gles") == 0) - self->use_gles = true; - else - g_warning("Invalid value '%s' for parameter '%s'.", v, k); - } else if (g_strcmp0(k, "rotation") == 0) { - char *endp = NULL; - const char *str = v ? v : ""; - uint64_t val = g_ascii_strtoull(str, &endp, 10); - if (val > 3 || *endp != '\0') - g_warning("Invalid value '%s' for parameter '%s'.", v, k); - else - self->rotation = val; - } else { - g_warning("Invalid parameter '%s'.", k); - } - } - } - float device_scale_factor = cog_shell_get_device_scale_factor(shell); if (device_scale_factor >= 0.2f) { g_debug("%s: Overriding CogDrmPlatform<%p>.device-scale-factor = <%.2f> from shell", __func__, self,