[mutter] backends: Move most of the code from meta_backend_init into the subclasses



commit 48dc544beff407b5502fae32c3259d87c8e31b0c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Apr 21 19:47:04 2014 -0400

    backends: Move most of the code from meta_backend_init into the subclasses

 src/backends/meta-backend.c               |   65 -----------------------------
 src/backends/meta-backend.h               |    2 -
 src/backends/native/meta-backend-native.c |   54 +++++++++++++++++++++++-
 src/backends/native/meta-backend-native.h |    2 +
 src/backends/x11/meta-backend-x11.c       |   21 +++++++++
 src/core/keybindings.c                    |    2 +-
 6 files changed, 77 insertions(+), 69 deletions(-)
---
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 5f2f03a..0cf95c7 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -26,17 +26,13 @@
 
 #include "meta-backend.h"
 #include "meta-backend-private.h"
-#include <meta/main.h>
 
-#include <gdk/gdkx.h>
 #include <clutter/clutter.h>
-#include <clutter/x11/clutter-x11.h>
 
 #include "backends/x11/meta-backend-x11.h"
 #include "backends/native/meta-backend-native.h"
 
 #include "backends/native/meta-weston-launch.h"
-#include <meta/util.h>
 
 static MetaBackend *_backend;
 
@@ -181,8 +177,6 @@ static GSourceFuncs event_funcs = {
   event_dispatch
 };
 
-static MetaLauncher *launcher;
-
 void
 meta_clutter_init (void)
 {
@@ -190,31 +184,6 @@ meta_clutter_init (void)
 
   meta_create_backend ();
 
-  /* When running as an X11 compositor, we install our own event filter and
-   * pass events to Clutter explicitly, so we need to prevent Clutter from
-   * handling our events.
-   *
-   * However, when running as a Wayland compostior under X11 nested, Clutter
-   * Clutter needs to see events related to its own window. We need to
-   * eventually replace this with a proper frontend / backend split: Clutter
-   * under nested is connecting to the "host X server" to get its events it
-   * needs to put up a window, and GTK+ is connecting to the "inner X server".
-   * The two would the same in the X11 compositor case, but not when running
-   * XWayland as a Wayland compositor.
-   */
-  if (!meta_is_wayland_compositor ())
-    {
-      clutter_x11_set_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
-      clutter_x11_disable_event_retrieval ();
-    }
-
-  /* If we're running on bare metal, we're a display server,
-   * so start talking to weston-launch. */
-#if defined(CLUTTER_WINDOWING_EGL)
-  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
-    launcher = meta_launcher_new ();
-#endif
-
   if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
     g_error ("Unable to initialize Clutter.\n");
 
@@ -222,37 +191,3 @@ meta_clutter_init (void)
   g_source_attach (source, NULL);
   g_source_unref (source);
 }
-
-gboolean
-meta_activate_vt (int vt, GError **error)
-{
-  if (launcher)
-    return meta_launcher_activate_vt (launcher, vt, error);
-  else
-    {
-      g_debug ("Ignoring VT switch keybinding, not running as display server");
-      return TRUE;
-    }
-}
-
-/**
- * meta_activate_session:
- *
- * Tells mutter to activate the session. When mutter is a
- * Wayland compositor, this tells logind to switch over to
- * the new session.
- */
-gboolean
-meta_activate_session (void)
-{
-  GError *error = NULL;
-
-  if (!meta_launcher_activate_vt (launcher, -1, &error))
-    {
-      g_warning ("Could not activate session: %s\n", error->message);
-      g_error_free (error);
-      return FALSE;
-    }
-
-  return TRUE;
-}
diff --git a/src/backends/meta-backend.h b/src/backends/meta-backend.h
index 021e235..7047c5e 100644
--- a/src/backends/meta-backend.h
+++ b/src/backends/meta-backend.h
@@ -41,6 +41,4 @@ MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
 
 void meta_clutter_init (void);
 
-gboolean meta_activate_vt (int vt, GError **error);
-
 #endif /* META_BACKEND_H */
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 5e6ec7c..01ce26d 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -24,11 +24,19 @@
 
 #include "config.h"
 
+#include <meta/main.h>
 #include "meta-backend-native.h"
 
 #include "meta-idle-monitor-native.h"
+#include "meta-weston-launch.h"
 
-G_DEFINE_TYPE (MetaBackendNative, meta_backend_native, META_TYPE_BACKEND);
+struct _MetaBackendNativePrivate
+{
+  MetaLauncher *launcher;
+};
+typedef struct _MetaBackendNativePrivate MetaBackendNativePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (MetaBackendNative, meta_backend_native, META_TYPE_BACKEND);
 
 static MetaIdleMonitor *
 meta_backend_native_create_idle_monitor (MetaBackend *backend,
@@ -50,4 +58,48 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
 static void
 meta_backend_native_init (MetaBackendNative *native)
 {
+  MetaBackendNativePrivate *priv = meta_backend_native_get_instance_private (native);
+
+  /* We're a display server, so start talking to weston-launch. */
+  priv->launcher = meta_launcher_new ();
+}
+
+gboolean
+meta_activate_vt (int vt, GError **error)
+{
+  MetaBackend *backend = meta_get_backend ();
+  MetaBackendNative *native = META_BACKEND_NATIVE (backend);
+  MetaBackendNativePrivate *priv = meta_backend_native_get_instance_private (native);
+
+  return meta_launcher_activate_vt (priv->launcher, vt, error);
+}
+
+/**
+ * meta_activate_session:
+ *
+ * Tells mutter to activate the session. When mutter is a
+ * Wayland compositor, this tells logind to switch over to
+ * the new session.
+ */
+gboolean
+meta_activate_session (void)
+{
+  GError *error = NULL;
+  MetaBackend *backend = meta_get_backend ();
+
+  /* Do nothing. */
+  if (!META_IS_BACKEND_NATIVE (backend))
+    return TRUE;
+
+  MetaBackendNative *native = META_BACKEND_NATIVE (backend);
+  MetaBackendNativePrivate *priv = meta_backend_native_get_instance_private (native);
+
+  if (!meta_launcher_activate_vt (priv->launcher, -1, &error))
+    {
+      g_warning ("Could not activate session: %s\n", error->message);
+      g_error_free (error);
+      return FALSE;
+    }
+
+  return TRUE;
 }
diff --git a/src/backends/native/meta-backend-native.h b/src/backends/native/meta-backend-native.h
index 4ee6efc..64a494b 100644
--- a/src/backends/native/meta-backend-native.h
+++ b/src/backends/native/meta-backend-native.h
@@ -49,4 +49,6 @@ struct _MetaBackendNativeClass
 
 GType meta_backend_native_get_type (void) G_GNUC_CONST;
 
+gboolean meta_activate_vt (int vt, GError **error);
+
 #endif /* META_BACKEND_NATIVE_H */
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 35e8416..61de444 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -26,6 +26,10 @@
 
 #include "meta-backend-x11.h"
 
+#include <gdk/gdkx.h>
+#include <clutter/x11/clutter-x11.h>
+
+#include <meta/util.h>
 #include "meta-idle-monitor-xsync.h"
 
 G_DEFINE_TYPE (MetaBackendX11, meta_backend_x11, META_TYPE_BACKEND);
@@ -50,6 +54,23 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
 static void
 meta_backend_x11_init (MetaBackendX11 *x11)
 {
+  /* When running as an X11 compositor, we install our own event filter and
+   * pass events to Clutter explicitly, so we need to prevent Clutter from
+   * handling our events.
+   *
+   * However, when running as a Wayland compostior under X11 nested, Clutter
+   * Clutter needs to see events related to its own window. We need to
+   * eventually replace this with a proper frontend / backend split: Clutter
+   * under nested is connecting to the "host X server" to get its events it
+   * needs to put up a window, and GTK+ is connecting to the "inner X server".
+   * The two would the same in the X11 compositor case, but not when running
+   * XWayland as a Wayland compositor.
+   */
+  if (!meta_is_wayland_compositor ())
+    {
+      clutter_x11_set_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+      clutter_x11_disable_event_retrieval ();
+    }
 }
 
 void
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 19376e4..43bffca 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -56,7 +56,7 @@
 #endif
 
 #include "wayland/meta-wayland.h"
-#include "meta-backend.h"
+#include "backends/native/meta-backend-native.h"
 
 #define SCHEMA_COMMON_KEYBINDINGS "org.gnome.desktop.wm.keybindings"
 #define SCHEMA_MUTTER_KEYBINDINGS "org.gnome.mutter.keybindings"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]