wayland/surface: Stop using deprecated g_object_newv

Replace it with g_object_new_with_properties. This fixes a warning
about using deprecated API.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/5
https://bugzilla.gnome.org/show_bug.cgi?id=791938
This commit is contained in:
Jonas Ådahl 2017-12-13 12:57:08 +08:00
parent dbf56e24cb
commit bd5e36cf0e

View File

@ -191,31 +191,20 @@ window_position_changed (MetaWindow *window,
MetaWaylandSurface *surface); MetaWaylandSurface *surface);
static void static void
unset_param_value (GParameter *param) role_assignment_valist_to_properties (GType role_type,
{ const char *first_property_name,
g_value_unset (&param->value); va_list var_args,
} GArray *names,
GArray *values)
static GArray *
role_assignment_valist_to_params (GType role_type,
const char *first_property_name,
va_list var_args)
{ {
GObjectClass *object_class; GObjectClass *object_class;
const char *property_name = first_property_name; const char *property_name = first_property_name;
GArray *params;
object_class = g_type_class_ref (role_type); object_class = g_type_class_ref (role_type);
params = g_array_new (FALSE, FALSE, sizeof (GParameter));
g_array_set_clear_func (params, (GDestroyNotify) unset_param_value);
while (property_name) while (property_name)
{ {
GParameter param = { GValue value = G_VALUE_INIT;
.name = property_name,
.value = G_VALUE_INIT
};
GParamSpec *pspec; GParamSpec *pspec;
GType ptype; GType ptype;
gchar *error = NULL; gchar *error = NULL;
@ -225,17 +214,16 @@ role_assignment_valist_to_params (GType role_type,
g_assert (pspec); g_assert (pspec);
ptype = G_PARAM_SPEC_VALUE_TYPE (pspec); ptype = G_PARAM_SPEC_VALUE_TYPE (pspec);
G_VALUE_COLLECT_INIT (&param.value, ptype, var_args, 0, &error); G_VALUE_COLLECT_INIT (&value, ptype, var_args, 0, &error);
g_assert (!error); g_assert (!error);
g_array_append_val (params, param); g_array_append_val (names, property_name);
g_array_append_val (values, value);
property_name = va_arg (var_args, const char *); property_name = va_arg (var_args, const char *);
} }
g_type_class_unref (object_class); g_type_class_unref (object_class);
return params;
} }
gboolean gboolean
@ -250,27 +238,39 @@ meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
{ {
if (first_property_name) if (first_property_name)
{ {
GArray *params; GArray *names;
GParameter param; GArray *values;
const char *surface_prop_name;
GValue surface_value = G_VALUE_INIT;
GObject *role_object;
names = g_array_new (FALSE, FALSE, sizeof (const char *));
values = g_array_new (FALSE, FALSE, sizeof (GValue));
g_array_set_clear_func (values, (GDestroyNotify) g_value_unset);
va_start (var_args, first_property_name); va_start (var_args, first_property_name);
params = role_assignment_valist_to_params (role_type, role_assignment_valist_to_properties (role_type,
first_property_name, first_property_name,
var_args); var_args,
names,
values);
va_end (var_args); va_end (var_args);
param = (GParameter) { surface_prop_name = "surface";
.name = "surface", g_value_init (&surface_value, META_TYPE_WAYLAND_SURFACE);
.value = G_VALUE_INIT g_value_set_object (&surface_value, surface);
}; g_array_append_val (names, surface_prop_name);
g_value_init (&param.value, META_TYPE_WAYLAND_SURFACE); g_array_append_val (values, surface_value);
g_value_set_object (&param.value, surface);
g_array_append_val (params, param);
surface->role = g_object_newv (role_type, params->len, role_object =
(GParameter *) params->data); g_object_new_with_properties (role_type,
values->len,
(const char **) names->data,
(const GValue *) values->data);
surface->role = META_WAYLAND_SURFACE_ROLE (role_object);
g_array_unref (params); g_array_free (names, FALSE);
g_array_free (values, TRUE);
} }
else else
{ {