compositor: Let MetaDisplay choose the correct compositor type

A base type shouldn't know about sub types, so let MetaDisplay make
the correct choice of what type of MetaCompositor it should create. No
other semantical changes introduced.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/727
This commit is contained in:
Jonas Ådahl 2019-08-19 10:24:17 +02:00 committed by Georges Basile Stavracas Neto
parent 8ee00cee60
commit 0db38c4999
7 changed files with 90 additions and 24 deletions

View File

@ -58,7 +58,6 @@
#include "backends/meta-dnd-private.h" #include "backends/meta-dnd-private.h"
#include "clutter/clutter-mutter.h" #include "clutter/clutter-mutter.h"
#include "compositor/meta-compositor-x11.h"
#include "compositor/meta-window-actor-x11.h" #include "compositor/meta-window-actor-x11.h"
#include "compositor/meta-window-actor-wayland.h" #include "compositor/meta-window-actor-wayland.h"
#include "compositor/meta-window-actor-private.h" #include "compositor/meta-window-actor-private.h"
@ -80,10 +79,20 @@
#include "x11/meta-x11-display-private.h" #include "x11/meta-x11-display-private.h"
#ifdef HAVE_WAYLAND #ifdef HAVE_WAYLAND
#include "compositor/meta-compositor-server.h"
#include "wayland/meta-wayland-private.h" #include "wayland/meta-wayland-private.h"
#endif #endif
enum
{
PROP_0,
PROP_DISPLAY,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS] = { NULL, };
typedef struct _MetaCompositorPrivate typedef struct _MetaCompositorPrivate
{ {
GObject parent; GObject parent;
@ -1140,28 +1149,44 @@ on_shadow_factory_changed (MetaShadowFactory *factory,
meta_window_actor_invalidate_shadow (l->data); meta_window_actor_invalidate_shadow (l->data);
} }
/** static void
* meta_compositor_new: (skip) meta_compositor_set_property (GObject *object,
* @display: guint prop_id,
* const GValue *value,
*/ GParamSpec *pspec)
MetaCompositor *
meta_compositor_new (MetaDisplay *display)
{ {
MetaCompositor *compositor; MetaCompositor *compositor = META_COMPOSITOR (object);
MetaCompositorPrivate *priv; MetaCompositorPrivate *priv =
meta_compositor_get_instance_private (compositor);
#ifdef HAVE_WAYLAND switch (prop_id)
if (meta_is_wayland_compositor ()) {
compositor = g_object_new (META_TYPE_COMPOSITOR_SERVER, NULL); case PROP_DISPLAY:
else priv->display = g_value_get_object (value);
#endif break;
compositor = g_object_new (META_TYPE_COMPOSITOR_X11, NULL); default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
priv = meta_compositor_get_instance_private (compositor); static void
priv->display = display; meta_compositor_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaCompositor *compositor = META_COMPOSITOR (object);
MetaCompositorPrivate *priv =
meta_compositor_get_instance_private (compositor);
return compositor; switch (prop_id)
{
case PROP_DISPLAY:
g_value_set_object (value, priv->display);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
} }
static void static void
@ -1222,11 +1247,23 @@ meta_compositor_class_init (MetaCompositorClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = meta_compositor_set_property;
object_class->get_property = meta_compositor_get_property;
object_class->dispose = meta_compositor_dispose; object_class->dispose = meta_compositor_dispose;
klass->remove_window = meta_compositor_real_remove_window; klass->remove_window = meta_compositor_real_remove_window;
klass->pre_paint = meta_compositor_real_pre_paint; klass->pre_paint = meta_compositor_real_pre_paint;
klass->post_paint = meta_compositor_real_post_paint; klass->post_paint = meta_compositor_real_post_paint;
obj_props[PROP_DISPLAY] =
g_param_spec_object ("display",
"display",
"MetaDisplay",
META_TYPE_DISPLAY,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
} }
/** /**

View File

@ -39,6 +39,14 @@ meta_compositor_server_unmanage (MetaCompositor *compositor)
{ {
} }
MetaCompositorServer *
meta_compositor_server_new (MetaDisplay *display)
{
return g_object_new (META_TYPE_COMPOSITOR_SERVER,
"display", display,
NULL);
}
static void static void
meta_compositor_server_init (MetaCompositorServer *compositor_server) meta_compositor_server_init (MetaCompositorServer *compositor_server)
{ {

View File

@ -27,4 +27,6 @@
G_DECLARE_FINAL_TYPE (MetaCompositorServer, meta_compositor_server, G_DECLARE_FINAL_TYPE (MetaCompositorServer, meta_compositor_server,
META, COMPOSITOR_SERVER, MetaCompositor) META, COMPOSITOR_SERVER, MetaCompositor)
MetaCompositorServer * meta_compositor_server_new (MetaDisplay *display);
#endif /* META_COMPOSITOR_SERVER_H */ #endif /* META_COMPOSITOR_SERVER_H */

View File

@ -322,6 +322,14 @@ meta_compositor_x11_get_output_xwindow (MetaCompositorX11 *compositor_x11)
return compositor_x11->output; return compositor_x11->output;
} }
MetaCompositorX11 *
meta_compositor_x11_new (MetaDisplay *display)
{
return g_object_new (META_TYPE_COMPOSITOR_X11,
"display", display,
NULL);
}
static void static void
meta_compositor_x11_dispose (GObject *object) meta_compositor_x11_dispose (GObject *object)
{ {

View File

@ -27,6 +27,8 @@
G_DECLARE_FINAL_TYPE (MetaCompositorX11, meta_compositor_x11, G_DECLARE_FINAL_TYPE (MetaCompositorX11, meta_compositor_x11,
META, COMPOSITOR_X11, MetaCompositor) META, COMPOSITOR_X11, MetaCompositor)
MetaCompositorX11 * meta_compositor_x11_new (MetaDisplay *display);
void meta_compositor_x11_process_xevent (MetaCompositorX11 *compositor_x11, void meta_compositor_x11_process_xevent (MetaCompositorX11 *compositor_x11,
XEvent *xevent, XEvent *xevent,
MetaWindow *window); MetaWindow *window);

View File

@ -50,6 +50,7 @@
#include "backends/x11/cm/meta-backend-x11-cm.h" #include "backends/x11/cm/meta-backend-x11-cm.h"
#include "clutter/x11/clutter-x11.h" #include "clutter/x11/clutter-x11.h"
#include "compositor/compositor-private.h" #include "compositor/compositor-private.h"
#include "compositor/meta-compositor-x11.h"
#include "core/bell.h" #include "core/bell.h"
#include "core/boxes-private.h" #include "core/boxes-private.h"
#include "core/display-private.h" #include "core/display-private.h"
@ -76,6 +77,7 @@
#include "x11/xprops.h" #include "x11/xprops.h"
#ifdef HAVE_WAYLAND #ifdef HAVE_WAYLAND
#include "compositor/meta-compositor-server.h"
#include "wayland/meta-xwayland-private.h" #include "wayland/meta-xwayland-private.h"
#include "wayland/meta-wayland-tablet-seat.h" #include "wayland/meta-wayland-tablet-seat.h"
#include "wayland/meta-wayland-tablet-pad.h" #include "wayland/meta-wayland-tablet-pad.h"
@ -538,6 +540,16 @@ meta_display_remove_pending_pings_for_window (MetaDisplay *display,
g_slist_free (dead); g_slist_free (dead);
} }
static MetaCompositor *
create_compositor (MetaDisplay *display)
{
#ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor ())
return META_COMPOSITOR (meta_compositor_server_new (display));
else
#endif
return META_COMPOSITOR (meta_compositor_x11_new (display));
}
static void static void
enable_compositor (MetaDisplay *display) enable_compositor (MetaDisplay *display)
@ -567,7 +579,7 @@ enable_compositor (MetaDisplay *display)
} }
if (!display->compositor) if (!display->compositor)
display->compositor = meta_compositor_new (display); display->compositor = create_compositor (display);
meta_compositor_manage (display->compositor); meta_compositor_manage (display->compositor);
} }

View File

@ -66,9 +66,6 @@ typedef enum
META_SIZE_CHANGE_UNFULLSCREEN, META_SIZE_CHANGE_UNFULLSCREEN,
} MetaSizeChange; } MetaSizeChange;
META_EXPORT
MetaCompositor *meta_compositor_new (MetaDisplay *display);
META_EXPORT META_EXPORT
void meta_compositor_destroy (MetaCompositor *compositor); void meta_compositor_destroy (MetaCompositor *compositor);