From d3920ddb67450266597aab0d37cadd1fe8fe7956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 5 Dec 2016 18:31:40 +0800 Subject: [PATCH] core: Add private API to override compositor configuration Add private API for overriding the compositor configuration, i.e. the compositor type (X11 WM or Wayland compositor) and backend type. This will make it possible to add a special test backend used by src/tests/. https://bugzilla.gnome.org/show_bug.cgi?id=777732 --- src/backends/meta-backend-private.h | 2 +- src/backends/meta-backend.c | 21 ++------------- src/core/main-private.h | 34 +++++++++++++++++++++++ src/core/main.c | 42 +++++++++++++++++++++++------ src/core/util-private.h | 16 ----------- 5 files changed, 71 insertions(+), 44 deletions(-) create mode 100644 src/core/main-private.h diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index 57ae8a715..39b42c4b5 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -97,7 +97,7 @@ struct _MetaBackendClass }; -void meta_init_backend (MetaBackendType backend_type); +void meta_init_backend (GType backend_gtype); ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend); diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 06d435d02..68917944f 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -796,31 +796,14 @@ meta_get_clutter_backend (void) } void -meta_init_backend (MetaBackendType backend_type) +meta_init_backend (GType backend_gtype) { - GType type; MetaBackend *backend; GError *error = NULL; - switch (backend_type) - { - case META_BACKEND_TYPE_X11: - type = META_TYPE_BACKEND_X11; - break; - -#ifdef HAVE_NATIVE_BACKEND - case META_BACKEND_TYPE_NATIVE: - type = META_TYPE_BACKEND_NATIVE; - break; -#endif - - default: - g_assert_not_reached (); - } - /* meta_backend_init() above install the backend globally so * so meta_get_backend() works even during initialization. */ - backend = g_object_new (type, NULL); + backend = g_object_new (backend_gtype, NULL); if (!g_initable_init (G_INITABLE (backend), NULL, &error)) { g_warning ("Failed to create backend: %s", error->message); diff --git a/src/core/main-private.h b/src/core/main-private.h new file mode 100644 index 000000000..36f4b313a --- /dev/null +++ b/src/core/main-private.h @@ -0,0 +1,34 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2016 Red Hat, Inc. + * + * 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, see . + */ + +#ifndef META_MAIN_PRIVATE_H +#define META_MAIN_PRIVATE_H + +typedef enum _MetaCompositorType +{ +#ifdef HAVE_WAYLAND + META_COMPOSITOR_TYPE_WAYLAND, +#endif + META_COMPOSITOR_TYPE_X11, +} MetaCompositorType; + +void meta_override_compositor_configuration (MetaCompositorType compositor_type, + GType backend_gtype); + +#endif /* META_MAIN_PRIVATE_H */ diff --git a/src/core/main.c b/src/core/main.c index 25586bec6..dc40f6e0d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -52,6 +52,7 @@ #include #include #include +#include "core/main-private.h" #include #include @@ -82,10 +83,14 @@ # endif #include "backends/meta-backend-private.h" +#include "backends/x11/meta-backend-x11.h" -#if defined(HAVE_NATIVE_BACKEND) && defined(HAVE_WAYLAND) +#ifdef HAVE_NATIVE_BACKEND +#include "backends/native/meta-backend-native.h" +#ifdef HAVE_WAYLAND #include -#endif +#endif /* HAVE_WAYLAND */ +#endif /* HAVE_NATIVE_BACKEND */ /* * The exit code we'll return to our parent process when we eventually die. @@ -394,7 +399,7 @@ check_for_wayland_session_type (void) static void calculate_compositor_configuration (MetaCompositorType *compositor_type, - MetaBackendType *backend_type) + GType *backend_gtype) { #ifdef HAVE_WAYLAND gboolean run_as_wayland_compositor = opt_wayland; @@ -411,12 +416,12 @@ calculate_compositor_configuration (MetaCompositorType *compositor_type, #ifdef CLUTTER_WINDOWING_EGL if (opt_display_server || (run_as_wayland_compositor && !opt_nested)) - *backend_type = META_BACKEND_TYPE_NATIVE; + *backend_gtype = META_TYPE_BACKEND_NATIVE; else #endif #endif #endif - *backend_type = META_BACKEND_TYPE_X11; + *backend_gtype = META_TYPE_BACKEND_X11; #ifdef HAVE_WAYLAND if (run_as_wayland_compositor) @@ -426,6 +431,19 @@ calculate_compositor_configuration (MetaCompositorType *compositor_type, *compositor_type = META_COMPOSITOR_TYPE_X11; } +static gboolean _compositor_configuration_overridden = FALSE; +static MetaCompositorType _compositor_type_override; +static GType _backend_gtype_override; + +void +meta_override_compositor_configuration (MetaCompositorType compositor_type, + GType backend_gtype) +{ + _compositor_configuration_overridden = TRUE; + _compositor_type_override = compositor_type; + _backend_gtype_override = backend_gtype; +} + /** * meta_init: (skip) * @@ -438,7 +456,7 @@ meta_init (void) struct sigaction act; sigset_t empty_mask; MetaCompositorType compositor_type; - MetaBackendType backend_type; + GType backend_gtype; sigemptyset (&empty_mask); act.sa_handler = SIG_IGN; @@ -460,7 +478,15 @@ meta_init (void) if (g_getenv ("MUTTER_DEBUG")) meta_set_debugging (TRUE); - calculate_compositor_configuration (&compositor_type, &backend_type); + if (_compositor_configuration_overridden) + { + compositor_type = _compositor_type_override; + backend_gtype = _backend_gtype_override; + } + else + { + calculate_compositor_configuration (&compositor_type, &backend_gtype); + } #ifdef HAVE_WAYLAND if (compositor_type == META_COMPOSITOR_TYPE_WAYLAND) @@ -488,7 +514,7 @@ meta_init (void) if (!meta_is_wayland_compositor ()) meta_select_display (opt_display_name); - meta_init_backend (backend_type); + meta_init_backend (backend_gtype); meta_clutter_init (); diff --git a/src/core/util-private.h b/src/core/util-private.h index c9f090aec..7d1f4b915 100644 --- a/src/core/util-private.h +++ b/src/core/util-private.h @@ -28,22 +28,6 @@ #include #include -typedef enum _MetaCompositorType -{ -#ifdef HAVE_WAYLAND - META_COMPOSITOR_TYPE_WAYLAND, -#endif - META_COMPOSITOR_TYPE_X11, -} MetaCompositorType; - -typedef enum _MetaBackendType -{ -#ifdef HAVE_NATIVE_BACKEND - META_BACKEND_TYPE_NATIVE, -#endif - META_BACKEND_TYPE_X11, -} MetaBackendType; - void meta_set_verbose (gboolean setting); void meta_set_debugging (gboolean setting); void meta_set_syncing (gboolean setting);