mirror of
https://github.com/brl/mutter.git
synced 2024-11-24 17:10:40 -05:00
context: Make the context owner of the backend
There is still the `_backend` singleton still, as there are still the `meta_get_backend()` that needs to work for now. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
parent
1972d4ec90
commit
b1c643eeaa
@ -107,11 +107,7 @@ struct _MetaBackendClass
|
||||
MetaPointerConstraint *constraint);
|
||||
};
|
||||
|
||||
void meta_init_backend (GType backend_gtype,
|
||||
unsigned int n_properties,
|
||||
const char *names[],
|
||||
const GValue *values);
|
||||
void meta_release_backend (void);
|
||||
void meta_backend_destroy (MetaBackend *backend);
|
||||
|
||||
void meta_backend_prepare_shutdown (MetaBackend *backend);
|
||||
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include "clutter/clutter-seat-private.h"
|
||||
#include "meta/main.h"
|
||||
#include "meta/meta-backend.h"
|
||||
#include "meta/meta-context.h"
|
||||
#include "meta/util.h"
|
||||
|
||||
#ifdef HAVE_PROFILER
|
||||
@ -89,6 +90,17 @@
|
||||
#include "wayland/meta-wayland.h"
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
||||
PROP_CONTEXT,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *obj_props[N_PROPS];
|
||||
|
||||
enum
|
||||
{
|
||||
KEYMAP_CHANGED,
|
||||
@ -122,6 +134,8 @@ meta_get_backend (void)
|
||||
|
||||
struct _MetaBackendPrivate
|
||||
{
|
||||
MetaContext *context;
|
||||
|
||||
MetaMonitorManager *monitor_manager;
|
||||
MetaOrientationManager *orientation_manager;
|
||||
MetaCursorTracker *cursor_tracker;
|
||||
@ -199,6 +213,8 @@ meta_backend_dispose (GObject *object)
|
||||
MetaBackend *backend = META_BACKEND (object);
|
||||
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
||||
|
||||
_backend = NULL;
|
||||
|
||||
g_clear_pointer (&priv->cursor_tracker, meta_cursor_tracker_destroy);
|
||||
g_clear_object (&priv->current_device);
|
||||
g_clear_object (&priv->monitor_manager);
|
||||
@ -249,7 +265,7 @@ meta_backend_dispose (GObject *object)
|
||||
G_OBJECT_CLASS (meta_backend_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
meta_backend_destroy (MetaBackend *backend)
|
||||
{
|
||||
g_object_run_dispose (G_OBJECT (backend));
|
||||
@ -737,6 +753,8 @@ meta_backend_constructed (GObject *object)
|
||||
MetaBackendClass *backend_class =
|
||||
META_BACKEND_GET_CLASS (backend);
|
||||
|
||||
g_assert (priv->context);
|
||||
|
||||
#ifdef HAVE_LIBWACOM
|
||||
priv->wacom_db = libwacom_database_new ();
|
||||
if (!priv->wacom_db)
|
||||
@ -758,6 +776,46 @@ meta_backend_constructed (GObject *object)
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_backend_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MetaBackend *backend = META_BACKEND (object);
|
||||
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
priv->context = g_value_get_object (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_backend_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MetaBackend *backend = META_BACKEND (object);
|
||||
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_value_set_object (value, priv->context);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_backend_class_init (MetaBackendClass *klass)
|
||||
{
|
||||
@ -766,6 +824,8 @@ meta_backend_class_init (MetaBackendClass *klass)
|
||||
|
||||
object_class->dispose = meta_backend_dispose;
|
||||
object_class->constructed = meta_backend_constructed;
|
||||
object_class->set_property = meta_backend_set_property;
|
||||
object_class->get_property = meta_backend_get_property;
|
||||
|
||||
klass->post_init = meta_backend_real_post_init;
|
||||
klass->grab_device = meta_backend_real_grab_device;
|
||||
@ -774,6 +834,16 @@ meta_backend_class_init (MetaBackendClass *klass)
|
||||
klass->is_lid_closed = meta_backend_real_is_lid_closed;
|
||||
klass->create_cursor_tracker = meta_backend_real_create_cursor_tracker;
|
||||
|
||||
obj_props[PROP_CONTEXT] =
|
||||
g_param_spec_object ("context",
|
||||
"context",
|
||||
"MetaContext",
|
||||
META_TYPE_CONTEXT,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
||||
|
||||
signals[KEYMAP_CHANGED] =
|
||||
g_signal_new ("keymap-changed",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
@ -1279,6 +1349,20 @@ meta_backend_grab_device (MetaBackend *backend,
|
||||
return META_BACKEND_GET_CLASS (backend)->grab_device (backend, device_id, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* meta_backend_get_context:
|
||||
* @backend: the #MetaBackend
|
||||
*
|
||||
* Returns: (transfer none): The #MetaContext
|
||||
*/
|
||||
MetaContext *
|
||||
meta_backend_get_context (MetaBackend *backend)
|
||||
{
|
||||
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
|
||||
|
||||
return priv->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* meta_backend_ungrab_device: (skip)
|
||||
*/
|
||||
@ -1458,34 +1542,6 @@ meta_backend_get_clutter_backend (MetaBackend *backend)
|
||||
return priv->clutter_backend;
|
||||
}
|
||||
|
||||
void
|
||||
meta_init_backend (GType backend_gtype,
|
||||
unsigned int n_properties,
|
||||
const char *names[],
|
||||
const GValue *values)
|
||||
{
|
||||
MetaBackend *backend;
|
||||
GError *error = NULL;
|
||||
|
||||
/* meta_backend_init() above install the backend globally so
|
||||
* so meta_get_backend() works even during initialization. */
|
||||
backend = META_BACKEND (g_object_new_with_properties (backend_gtype,
|
||||
n_properties,
|
||||
names,
|
||||
values));
|
||||
if (!g_initable_init (G_INITABLE (backend), NULL, &error))
|
||||
{
|
||||
g_warning ("Failed to create backend: %s", error->message);
|
||||
meta_exit (META_EXIT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
meta_release_backend (void)
|
||||
{
|
||||
g_clear_pointer (&_backend, meta_backend_destroy);
|
||||
}
|
||||
|
||||
void
|
||||
meta_backend_prepare_shutdown (MetaBackend *backend)
|
||||
{
|
||||
|
@ -381,6 +381,7 @@ create_x11_cm_backend (MetaContext *context,
|
||||
|
||||
return g_initable_new (META_TYPE_BACKEND_X11_CM,
|
||||
NULL, error,
|
||||
"context", context,
|
||||
"display-name", context_main->options.x11.display_name,
|
||||
NULL);
|
||||
}
|
||||
@ -392,6 +393,7 @@ create_nested_backend (MetaContext *context,
|
||||
{
|
||||
return g_initable_new (META_TYPE_BACKEND_X11_NESTED,
|
||||
NULL, error,
|
||||
"context", context,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@ -402,6 +404,7 @@ create_headless_backend (MetaContext *context,
|
||||
{
|
||||
return g_initable_new (META_TYPE_BACKEND_NATIVE,
|
||||
NULL, error,
|
||||
"context", context,
|
||||
"headless", TRUE,
|
||||
NULL);
|
||||
}
|
||||
@ -412,6 +415,7 @@ create_native_backend (MetaContext *context,
|
||||
{
|
||||
return g_initable_new (META_TYPE_BACKEND_NATIVE,
|
||||
NULL, error,
|
||||
"context", context,
|
||||
NULL);
|
||||
}
|
||||
#endif /* HAVE_NATIVE_BACKEND */
|
||||
|
@ -54,6 +54,8 @@ typedef struct _MetaContextPrivate
|
||||
|
||||
GOptionContext *option_context;
|
||||
|
||||
MetaBackend *backend;
|
||||
|
||||
GMainLoop *main_loop;
|
||||
GError *termination_error;
|
||||
} MetaContextPrivate;
|
||||
@ -111,6 +113,20 @@ meta_context_notify_ready (MetaContext *context)
|
||||
META_CONTEXT_GET_CLASS (context)->notify_ready (context);
|
||||
}
|
||||
|
||||
/**
|
||||
* meta_context_get_backend:
|
||||
* @context: The #MetaContext
|
||||
*
|
||||
* Returns: (transfer none): the #MetaBackend
|
||||
*/
|
||||
MetaBackend *
|
||||
meta_context_get_backend (MetaContext *context)
|
||||
{
|
||||
MetaContextPrivate *priv = meta_context_get_instance_private (context);
|
||||
|
||||
return priv->backend;
|
||||
}
|
||||
|
||||
MetaCompositorType
|
||||
meta_context_get_compositor_type (MetaContext *context)
|
||||
{
|
||||
@ -231,7 +247,15 @@ static gboolean
|
||||
meta_context_real_setup (MetaContext *context,
|
||||
GError **error)
|
||||
{
|
||||
return !!META_CONTEXT_GET_CLASS (context)->create_backend (context, error);
|
||||
MetaContextPrivate *priv = meta_context_get_instance_private (context);
|
||||
MetaBackend *backend;
|
||||
|
||||
backend = META_CONTEXT_GET_CLASS (context)->create_backend (context, error);
|
||||
if (!backend)
|
||||
return FALSE;
|
||||
|
||||
priv->backend = backend;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -381,15 +405,13 @@ meta_context_finalize (GObject *object)
|
||||
MetaContext *context = META_CONTEXT (object);
|
||||
MetaContextPrivate *priv = meta_context_get_instance_private (context);
|
||||
MetaDisplay *display;
|
||||
MetaBackend *backend;
|
||||
#ifdef HAVE_WAYLAND
|
||||
MetaWaylandCompositor *compositor;
|
||||
MetaCompositorType compositor_type;
|
||||
#endif
|
||||
|
||||
backend = meta_get_backend ();
|
||||
if (backend)
|
||||
meta_backend_prepare_shutdown (backend);
|
||||
if (priv->backend)
|
||||
meta_backend_prepare_shutdown (priv->backend);
|
||||
|
||||
#ifdef HAVE_WAYLAND
|
||||
compositor = meta_wayland_compositor_get_default ();
|
||||
@ -407,7 +429,7 @@ meta_context_finalize (GObject *object)
|
||||
meta_wayland_finalize ();
|
||||
#endif
|
||||
|
||||
meta_release_backend ();
|
||||
g_clear_pointer (&priv->backend, meta_backend_destroy);
|
||||
|
||||
g_clear_pointer (&priv->option_context, g_option_context_free);
|
||||
g_clear_pointer (&priv->main_loop, g_main_loop_unref);
|
||||
|
@ -49,6 +49,9 @@ META_EXPORT
|
||||
void meta_backend_lock_layout_group (MetaBackend *backend,
|
||||
guint idx);
|
||||
|
||||
META_EXPORT
|
||||
MetaContext * meta_backend_get_context (MetaBackend *backend);
|
||||
|
||||
META_EXPORT
|
||||
ClutterActor *meta_backend_get_stage (MetaBackend *backend);
|
||||
|
||||
|
@ -81,4 +81,7 @@ void meta_context_terminate_with_error (MetaContext *context,
|
||||
META_EXPORT
|
||||
MetaCompositorType meta_context_get_compositor_type (MetaContext *context);
|
||||
|
||||
META_EXPORT
|
||||
MetaBackend * meta_context_get_backend (MetaContext *context);
|
||||
|
||||
#endif /* META_CONTEXT_H */
|
||||
|
@ -121,6 +121,7 @@ create_nested_backend (MetaContext *context,
|
||||
{
|
||||
return g_initable_new (META_TYPE_BACKEND_TEST,
|
||||
NULL, error,
|
||||
"context", context,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@ -131,6 +132,7 @@ create_headless_backend (MetaContext *context,
|
||||
{
|
||||
return g_initable_new (META_TYPE_BACKEND_NATIVE,
|
||||
NULL, error,
|
||||
"context", context,
|
||||
"headless", TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user