summaryrefslogtreecommitdiff
path: root/src/backends
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2014-08-13 19:46:32 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2014-08-13 20:08:46 -0400
commit467465c99c413376240e9cbd6d832157660e8776 (patch)
treef574f981ace5ac8f163e80a648ca54dcb710e38d /src/backends
parente935b52e51d4c200554a6ac046e1a6643c1de1bc (diff)
downloadmutter-467465c99c413376240e9cbd6d832157660e8776.tar.gz
backend: Create the stage in the backend, rather than the compositor
This allows creating the stage much earlier than it otherwise would have been. Our initialization sequence has always been a bit haphazard, with first the MetaBackend created, then the MetaDisplay, and inside of that, the MetaScreen and MetaCompositor. Refactor this out so that the MetaBackend creates the Clutter stage. Besides the clarity of early initialization, we now have much easier access to the stage, allowing us to use it for things such as key focus and beyond.
Diffstat (limited to 'src/backends')
-rw-r--r--src/backends/meta-backend-private.h3
-rw-r--r--src/backends/meta-backend.c65
-rw-r--r--src/backends/meta-cursor-renderer.c9
-rw-r--r--src/backends/meta-stage.c176
-rw-r--r--src/backends/meta-stage.h59
-rw-r--r--src/backends/native/meta-launcher.c4
-rw-r--r--src/backends/x11/meta-backend-x11.c47
7 files changed, 346 insertions, 17 deletions
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 13dd53c70..bd665c17a 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -84,6 +84,9 @@ struct _MetaBackendClass
void (* lock_layout_group) (MetaBackend *backend,
guint idx);
+
+ void (* update_screen_size) (MetaBackend *backend, int width, int height);
+ void (* select_stage_events) (MetaBackend *backend);
};
MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index d2cd2eea9..75222daef 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -27,9 +27,8 @@
#include <meta/meta-backend.h>
#include "meta-backend-private.h"
-#include <clutter/clutter.h>
-
#include "backends/x11/meta-backend-x11.h"
+#include "meta-stage.h"
#ifdef HAVE_NATIVE_BACKEND
#include "backends/native/meta-backend-native.h"
@@ -54,6 +53,8 @@ struct _MetaBackendPrivate
{
MetaMonitorManager *monitor_manager;
MetaCursorRenderer *cursor_renderer;
+
+ ClutterActor *stage;
};
typedef struct _MetaBackendPrivate MetaBackendPrivate;
@@ -78,11 +79,39 @@ meta_backend_finalize (GObject *object)
}
static void
+meta_backend_sync_screen_size (MetaBackend *backend)
+{
+ MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+ int width, height;
+
+ meta_monitor_manager_get_screen_size (priv->monitor_manager, &width, &height);
+
+ META_BACKEND_GET_CLASS (backend)->update_screen_size (backend, width, height);
+}
+
+static void
+on_monitors_changed (MetaMonitorManager *monitors,
+ gpointer user_data)
+{
+ MetaBackend *backend = META_BACKEND (user_data);
+ meta_backend_sync_screen_size (backend);
+}
+
+static void
meta_backend_real_post_init (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+ priv->stage = meta_stage_new ();
+ clutter_actor_realize (priv->stage);
+ META_BACKEND_GET_CLASS (backend)->select_stage_events (backend);
+
priv->monitor_manager = META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend);
+
+ g_signal_connect (priv->monitor_manager, "monitors-changed",
+ G_CALLBACK (on_monitors_changed), backend);
+ meta_backend_sync_screen_size (backend);
+
priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend);
}
@@ -111,6 +140,21 @@ meta_backend_real_ungrab_device (MetaBackend *backend,
}
static void
+meta_backend_real_update_screen_size (MetaBackend *backend,
+ int width, int height)
+{
+ MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+
+ clutter_actor_set_size (priv->stage, width, height);
+}
+
+static void
+meta_backend_real_select_stage_events (MetaBackend *backend)
+{
+ /* Do nothing */
+}
+
+static void
meta_backend_class_init (MetaBackendClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -121,6 +165,8 @@ meta_backend_class_init (MetaBackendClass *klass)
klass->create_cursor_renderer = meta_backend_real_create_cursor_renderer;
klass->grab_device = meta_backend_real_grab_device;
klass->ungrab_device = meta_backend_real_ungrab_device;
+ klass->update_screen_size = meta_backend_real_update_screen_size;
+ klass->select_stage_events = meta_backend_real_select_stage_events;
}
static void
@@ -251,6 +297,21 @@ meta_backend_lock_layout_group (MetaBackend *backend,
META_BACKEND_GET_CLASS (backend)->lock_layout_group (backend, idx);
}
+/**
+ * meta_backend_get_stage:
+ * @backend: A #MetaBackend
+ *
+ * Gets the global #ClutterStage that's managed by this backend.
+ *
+ * Returns: (transfer none): the #ClutterStage
+ */
+ClutterActor *
+meta_backend_get_stage (MetaBackend *backend)
+{
+ MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+ return priv->stage;
+}
+
static GType
get_backend_type (void)
{
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c
index 21f1a463e..3d1f85718 100644
--- a/src/backends/meta-cursor-renderer.c
+++ b/src/backends/meta-cursor-renderer.c
@@ -27,14 +27,15 @@
#include "meta-cursor-renderer.h"
#include "meta-cursor-private.h"
+#include <meta/meta-backend.h>
+#include <meta/util.h>
+
#include <cogl/cogl.h>
#include <cogl/cogl-wayland-server.h>
#include <clutter/clutter.h>
#include "meta-stage.h"
-#include "wayland/meta-wayland-private.h"
-
struct _MetaCursorRendererPrivate
{
int current_x, current_y;
@@ -51,8 +52,8 @@ static void
queue_redraw (MetaCursorRenderer *renderer)
{
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
- MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
- ClutterActor *stage = compositor->stage;
+ MetaBackend *backend = meta_get_backend ();
+ ClutterActor *stage = meta_backend_get_stage (backend);
/* During early initialization, we can have no stage */
if (!stage)
diff --git a/src/backends/meta-stage.c b/src/backends/meta-stage.c
new file mode 100644
index 000000000..3f4ddac3b
--- /dev/null
+++ b/src/backends/meta-stage.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2014 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre@mecheye.net>
+ */
+
+#include <config.h>
+
+#include "meta-stage.h"
+
+#include "meta-cursor-private.h"
+#include <meta/meta-backend.h>
+#include <meta/util.h>
+
+struct _MetaStagePrivate {
+ CoglPipeline *pipeline;
+ gboolean should_paint_cursor;
+
+ MetaCursorReference *cursor;
+
+ MetaRectangle current_rect;
+ MetaRectangle previous_rect;
+ gboolean previous_is_valid;
+};
+typedef struct _MetaStagePrivate MetaStagePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MetaStage, meta_stage, CLUTTER_TYPE_STAGE);
+
+static void
+update_pipeline (MetaStage *stage)
+{
+ MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
+
+ if (priv->cursor)
+ {
+ CoglTexture *texture = meta_cursor_reference_get_cogl_texture (priv->cursor, NULL, NULL);
+ cogl_pipeline_set_layer_texture (priv->pipeline, 0, texture);
+ }
+ else
+ cogl_pipeline_set_layer_texture (priv->pipeline, 0, NULL);
+}
+
+static void
+meta_stage_finalize (GObject *object)
+{
+ MetaStage *stage = META_STAGE (object);
+ MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
+
+ if (priv->pipeline)
+ cogl_object_unref (priv->pipeline);
+}
+
+static void
+paint_cursor (MetaStage *stage)
+{
+ MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
+
+ g_assert (meta_is_wayland_compositor ());
+
+ if (!priv->cursor)
+ return;
+
+ cogl_framebuffer_draw_rectangle (cogl_get_draw_framebuffer (),
+ priv->pipeline,
+ priv->current_rect.x,
+ priv->current_rect.y,
+ priv->current_rect.x +
+ priv->current_rect.width,
+ priv->current_rect.y +
+ priv->current_rect.height);
+
+ priv->previous_rect = priv->current_rect;
+ priv->previous_is_valid = TRUE;
+}
+
+static void
+meta_stage_paint (ClutterActor *actor)
+{
+ MetaStage *stage = META_STAGE (actor);
+
+ CLUTTER_ACTOR_CLASS (meta_stage_parent_class)->paint (actor);
+
+ if (meta_is_wayland_compositor ())
+ paint_cursor (stage);
+}
+
+static void
+meta_stage_class_init (MetaStageClass *klass)
+{
+ ClutterActorClass *actor_class = (ClutterActorClass *) klass;
+ GObjectClass *object_class = (GObjectClass *) klass;
+
+ object_class->finalize = meta_stage_finalize;
+
+ actor_class->paint = meta_stage_paint;
+}
+
+static void
+meta_stage_init (MetaStage *stage)
+{
+ CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
+ MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
+
+ priv->pipeline = cogl_pipeline_new (ctx);
+
+ clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE);
+}
+
+ClutterActor *
+meta_stage_new (void)
+{
+ return g_object_new (META_TYPE_STAGE,
+ "cursor-visible", FALSE,
+ NULL);
+}
+
+static void
+queue_redraw (MetaStage *stage)
+{
+ MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
+ cairo_rectangle_int_t clip;
+
+ /* Clear the location the cursor was at before, if we need to. */
+ if (priv->previous_is_valid)
+ {
+ clip.x = priv->previous_rect.x;
+ clip.y = priv->previous_rect.y;
+ clip.width = priv->previous_rect.width;
+ clip.height = priv->previous_rect.height;
+ clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip);
+ priv->previous_is_valid = FALSE;
+ }
+
+ /* And queue a redraw for the current cursor location. */
+ if (priv->cursor)
+ {
+ clip.x = priv->current_rect.x;
+ clip.y = priv->current_rect.y;
+ clip.width = priv->current_rect.width;
+ clip.height = priv->current_rect.height;
+ clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip);
+ }
+}
+
+void
+meta_stage_set_cursor (MetaStage *stage,
+ MetaCursorReference *cursor,
+ MetaRectangle *rect)
+{
+ MetaStagePrivate *priv = meta_stage_get_instance_private (stage);
+
+ if (priv->cursor != cursor)
+ {
+ priv->cursor = cursor;
+ update_pipeline (stage);
+ }
+
+ priv->current_rect = *rect;
+ queue_redraw (stage);
+}
diff --git a/src/backends/meta-stage.h b/src/backends/meta-stage.h
new file mode 100644
index 000000000..df11feba0
--- /dev/null
+++ b/src/backends/meta-stage.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_STAGE_H
+#define META_STAGE_H
+
+#include <clutter/clutter.h>
+
+#include "meta-cursor.h"
+#include <meta/boxes.h>
+
+G_BEGIN_DECLS
+
+#define META_TYPE_STAGE (meta_stage_get_type ())
+#define META_STAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_STAGE, MetaStage))
+#define META_STAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_STAGE, MetaStageClass))
+#define META_IS_STAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_STAGE))
+#define META_IS_STAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_STAGE))
+#define META_STAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_STAGE, MetaStageClass))
+
+typedef struct _MetaStage MetaStage;
+typedef struct _MetaStageClass MetaStageClass;
+
+struct _MetaStageClass
+{
+ ClutterStageClass parent_class;
+};
+
+struct _MetaStage
+{
+ ClutterStage parent;
+};
+
+GType meta_stage_get_type (void) G_GNUC_CONST;
+
+ClutterActor *meta_stage_new (void);
+
+void meta_stage_set_cursor (MetaStage *stage,
+ MetaCursorReference *cursor,
+ MetaRectangle *rect);
+G_END_DECLS
+
+#endif /* META_STAGE_H */
diff --git a/src/backends/native/meta-launcher.c b/src/backends/native/meta-launcher.c
index 87b3f28dd..70454bb01 100644
--- a/src/backends/native/meta-launcher.c
+++ b/src/backends/native/meta-launcher.c
@@ -101,15 +101,15 @@ session_unpause (void)
clutter_egl_thaw_master_clock ();
{
- MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
MetaBackend *backend = meta_get_backend ();
MetaCursorRenderer *renderer = meta_backend_get_cursor_renderer (backend);
+ ClutterActor *stage = meta_backend_get_stage (backend);
/* When we mode-switch back, we need to immediately queue a redraw
* in case nothing else queued one for us, and force the cursor to
* update. */
- clutter_actor_queue_redraw (compositor->stage);
+ clutter_actor_queue_redraw (stage);
meta_cursor_renderer_native_force_update (META_CURSOR_RENDERER_NATIVE (renderer));
}
}
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 5e8c25a05..2d420cb05 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -593,6 +593,40 @@ meta_backend_x11_lock_layout_group (MetaBackend *backend,
}
static void
+meta_backend_x11_update_screen_size (MetaBackend *backend,
+ int width, int height)
+{
+ MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
+ MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
+ Window xwin = meta_backend_x11_get_xwindow (x11);
+ XResizeWindow (priv->xdisplay, xwin, width, height);
+}
+
+static void
+meta_backend_x11_select_stage_events (MetaBackend *backend)
+{
+ MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
+ MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
+ Window xwin = meta_backend_x11_get_xwindow (x11);
+ unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
+ XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
+
+ XISetMask (mask.mask, XI_KeyPress);
+ XISetMask (mask.mask, XI_KeyRelease);
+ XISetMask (mask.mask, XI_ButtonPress);
+ XISetMask (mask.mask, XI_ButtonRelease);
+ XISetMask (mask.mask, XI_Enter);
+ XISetMask (mask.mask, XI_Leave);
+ XISetMask (mask.mask, XI_FocusIn);
+ XISetMask (mask.mask, XI_FocusOut);
+ XISetMask (mask.mask, XI_Motion);
+ XIClearMask (mask.mask, XI_TouchBegin);
+ XIClearMask (mask.mask, XI_TouchEnd);
+ XIClearMask (mask.mask, XI_TouchUpdate);
+ XISelectEvents (priv->xdisplay, xwin, &mask, 1);
+}
+
+static void
meta_backend_x11_class_init (MetaBackendX11Class *klass)
{
MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
@@ -601,13 +635,14 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
backend_class->create_idle_monitor = meta_backend_x11_create_idle_monitor;
backend_class->create_monitor_manager = meta_backend_x11_create_monitor_manager;
backend_class->create_cursor_renderer = meta_backend_x11_create_cursor_renderer;
-
backend_class->grab_device = meta_backend_x11_grab_device;
backend_class->ungrab_device = meta_backend_x11_ungrab_device;
backend_class->warp_pointer = meta_backend_x11_warp_pointer;
backend_class->set_keymap = meta_backend_x11_set_keymap;
backend_class->get_keymap = meta_backend_x11_get_keymap;
backend_class->lock_layout_group = meta_backend_x11_lock_layout_group;
+ backend_class->update_screen_size = meta_backend_x11_update_screen_size;
+ backend_class->select_stage_events = meta_backend_x11_select_stage_events;
}
static void
@@ -628,12 +663,6 @@ meta_backend_x11_get_xdisplay (MetaBackendX11 *x11)
Window
meta_backend_x11_get_xwindow (MetaBackendX11 *x11)
{
- MetaDisplay *display = meta_get_display ();
- MetaCompositor *compositor = display->compositor;
-
- if (compositor == NULL)
- return None;
-
- ClutterStage *stage = CLUTTER_STAGE (compositor->stage);
- return clutter_x11_get_stage_window (stage);
+ ClutterActor *stage = meta_backend_get_stage (META_BACKEND (x11));
+ return clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
}