main: Make it possible to set properties when overriding configuration
This makes it possible to pass custom properties to backends when constructing tests. This will be used to create "headless" native backend instances for testing the headless native backend. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1698>
This commit is contained in:
parent
1e2ef9023d
commit
9bf57f82d3
@ -47,7 +47,9 @@ typedef enum _MetaDisplayPolicy
|
||||
|
||||
META_EXPORT_TEST
|
||||
void meta_override_compositor_configuration (MetaCompositorType compositor_type,
|
||||
GType backend_gtype);
|
||||
GType backend_gtype,
|
||||
const char *first_property_name,
|
||||
...);
|
||||
|
||||
META_EXPORT_TEST
|
||||
MetaDisplayPolicy meta_get_x11_display_policy (void);
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib-unix.h>
|
||||
#include <gobject/gvaluecollector.h>
|
||||
#include <locale.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@ -581,14 +582,61 @@ calculate_compositor_configuration (MetaCompositorType *compositor_type,
|
||||
static gboolean _compositor_configuration_overridden = FALSE;
|
||||
static MetaCompositorType _compositor_type_override;
|
||||
static GType _backend_gtype_override;
|
||||
static GArray *_backend_property_names;
|
||||
static GArray *_backend_property_values;
|
||||
|
||||
void
|
||||
meta_override_compositor_configuration (MetaCompositorType compositor_type,
|
||||
GType backend_gtype)
|
||||
GType backend_gtype,
|
||||
const char *first_property_name,
|
||||
...)
|
||||
{
|
||||
va_list var_args;
|
||||
GArray *names;
|
||||
GArray *values;
|
||||
GObjectClass *object_class;
|
||||
const char *property_name;
|
||||
|
||||
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);
|
||||
|
||||
object_class = g_type_class_ref (backend_gtype);
|
||||
|
||||
property_name = first_property_name;
|
||||
|
||||
va_start (var_args, first_property_name);
|
||||
|
||||
while (property_name)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
GParamSpec *pspec;
|
||||
GType ptype;
|
||||
char *error = NULL;
|
||||
|
||||
pspec = g_object_class_find_property (object_class,
|
||||
property_name);
|
||||
g_assert (pspec);
|
||||
|
||||
ptype = G_PARAM_SPEC_VALUE_TYPE (pspec);
|
||||
G_VALUE_COLLECT_INIT (&value, ptype, var_args, 0, &error);
|
||||
g_assert (!error);
|
||||
|
||||
g_array_append_val (names, property_name);
|
||||
g_array_append_val (values, value);
|
||||
|
||||
property_name = va_arg (var_args, const char *);
|
||||
}
|
||||
|
||||
va_end (var_args);
|
||||
|
||||
g_type_class_unref (object_class);
|
||||
|
||||
_compositor_configuration_overridden = TRUE;
|
||||
_compositor_type_override = compositor_type;
|
||||
_backend_gtype_override = backend_gtype;
|
||||
_backend_property_names = names;
|
||||
_backend_property_values = values;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -647,9 +695,9 @@ meta_init (void)
|
||||
{
|
||||
compositor_type = _compositor_type_override;
|
||||
backend_gtype = _backend_gtype_override;
|
||||
n_properties = 0;
|
||||
prop_names = NULL;
|
||||
prop_values = NULL;
|
||||
n_properties = _backend_property_names->len;
|
||||
prop_names = (const char **) _backend_property_names->data;
|
||||
prop_values = (GValue *) _backend_property_values->data;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -693,6 +741,12 @@ meta_init (void)
|
||||
for (i = 0; i < n_properties; i++)
|
||||
g_value_reset (&prop_values[i]);
|
||||
|
||||
if (_backend_property_names)
|
||||
{
|
||||
g_array_free (_backend_property_names, TRUE);
|
||||
g_array_free (_backend_property_values, TRUE);
|
||||
}
|
||||
|
||||
meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL));
|
||||
|
||||
if (opt_replace_wm)
|
||||
@ -864,7 +918,8 @@ meta_test_init (void)
|
||||
int fd = g_mkstemp (display_name);
|
||||
|
||||
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
|
||||
META_TYPE_BACKEND_X11_NESTED);
|
||||
META_TYPE_BACKEND_X11_NESTED,
|
||||
NULL);
|
||||
meta_wayland_override_display_name (display_name);
|
||||
meta_xwayland_override_display_number (512 + rand() % 512);
|
||||
meta_init ();
|
||||
|
@ -129,7 +129,8 @@ main (int argc, char **argv)
|
||||
meta_wayland_override_display_name ("mutter-test-display");
|
||||
meta_xwayland_override_display_number (512);
|
||||
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
|
||||
META_TYPE_BACKEND_X11_NESTED);
|
||||
META_TYPE_BACKEND_X11_NESTED,
|
||||
NULL);
|
||||
meta_init ();
|
||||
|
||||
module = g_module_open (NULL, 0);
|
||||
|
@ -217,7 +217,8 @@ main (int argc, char *argv[])
|
||||
meta_plugin_manager_load (test_get_plugin_name ());
|
||||
|
||||
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
|
||||
META_TYPE_BACKEND_TEST);
|
||||
META_TYPE_BACKEND_TEST,
|
||||
NULL);
|
||||
|
||||
meta_init ();
|
||||
meta_register_with_session ();
|
||||
|
@ -1192,7 +1192,8 @@ main (int argc, char *argv[])
|
||||
meta_plugin_manager_load (test_get_plugin_name ());
|
||||
|
||||
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
|
||||
META_TYPE_BACKEND_TEST);
|
||||
META_TYPE_BACKEND_TEST,
|
||||
NULL);
|
||||
|
||||
meta_init ();
|
||||
meta_register_with_session ();
|
||||
|
@ -269,7 +269,8 @@ main (int argc, char *argv[])
|
||||
meta_plugin_manager_load (test_get_plugin_name ());
|
||||
|
||||
meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND,
|
||||
META_TYPE_BACKEND_TEST);
|
||||
META_TYPE_BACKEND_TEST,
|
||||
NULL);
|
||||
|
||||
meta_init ();
|
||||
meta_register_with_session ();
|
||||
|
Loading…
Reference in New Issue
Block a user