[mutter] context: Move 'replace-current-wm' tracking to the context



commit ff0afb186a2741691deca02652a4c2f193246e50
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Apr 19 16:13:47 2021 +0200

    context: Move 'replace-current-wm' tracking to the context
    
    This move yet another scattered global static variable into the
    context's control.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>

 src/backends/meta-idle-manager.c    |  7 +++++--
 src/backends/meta-monitor-manager.c | 24 ++++++++++++++----------
 src/compositor/compositor.c         |  5 ++++-
 src/core/meta-context-main.c        | 10 +++++++++-
 src/core/meta-context-private.h     |  2 ++
 src/core/meta-context.c             |  6 ++++++
 src/core/util.c                     | 13 -------------
 src/meta/main.h                     |  3 ---
 src/meta/meta-context.h             |  3 +++
 src/tests/meta-context-test.c       |  7 +++++++
 src/x11/meta-x11-display.c          |  3 ++-
 11 files changed, 52 insertions(+), 31 deletions(-)
---
diff --git a/src/backends/meta-idle-manager.c b/src/backends/meta-idle-manager.c
index 8369ae5066..92ba0a2376 100644
--- a/src/backends/meta-idle-manager.c
+++ b/src/backends/meta-idle-manager.c
@@ -27,6 +27,7 @@
 #include "backends/meta-idle-monitor-private.h"
 #include "clutter/clutter.h"
 #include "meta/main.h"
+#include "meta/meta-context.h"
 #include "meta/meta-idle-monitor.h"
 #include "meta/util.h"
 
@@ -338,6 +339,7 @@ create_device_monitors (MetaIdleManager *idle_manager,
 MetaIdleManager *
 meta_idle_manager_new (MetaBackend *backend)
 {
+  MetaContext *context = meta_backend_get_context (backend);
   ClutterSeat *seat = meta_backend_get_default_seat (backend);
   MetaIdleManager *idle_manager;
 
@@ -348,8 +350,9 @@ meta_idle_manager_new (MetaBackend *backend)
     g_bus_own_name (G_BUS_TYPE_SESSION,
                     "org.gnome.Mutter.IdleMonitor",
                     G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
-                    (meta_get_replace_current_wm () ?
-                     G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
+                    (meta_context_is_replacing (context) ?
+                     G_BUS_NAME_OWNER_FLAGS_REPLACE :
+                     G_BUS_NAME_OWNER_FLAGS_NONE),
                     on_bus_acquired,
                     on_name_acquired,
                     on_name_lost,
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index 6fa4abed9e..e6d50bd999 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -2623,16 +2623,20 @@ on_name_lost (GDBusConnection *connection,
 static void
 initialize_dbus_interface (MetaMonitorManager *manager)
 {
-  manager->dbus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION,
-                                          "org.gnome.Mutter.DisplayConfig",
-                                          G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
-                                          (meta_get_replace_current_wm () ?
-                                           G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
-                                          on_bus_acquired,
-                                          on_name_acquired,
-                                          on_name_lost,
-                                          g_object_ref (manager),
-                                          g_object_unref);
+  MetaContext *context = meta_backend_get_context (manager->backend);
+
+  manager->dbus_name_id =
+    g_bus_own_name (G_BUS_TYPE_SESSION,
+                    "org.gnome.Mutter.DisplayConfig",
+                    G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+                    (meta_context_is_replacing (context) ?
+                     G_BUS_NAME_OWNER_FLAGS_REPLACE :
+                     G_BUS_NAME_OWNER_FLAGS_NONE),
+                    on_bus_acquired,
+                    on_name_acquired,
+                    on_name_lost,
+                    g_object_ref (manager),
+                    g_object_unref);
 }
 
 /**
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index 1770550d4c..9cdd39c15d 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -73,6 +73,7 @@
 #include "meta/meta-backend.h"
 #include "meta/meta-background-actor.h"
 #include "meta/meta-background-group.h"
+#include "meta/meta-context.h"
 #include "meta/meta-shadow-factory.h"
 #include "meta/meta-x11-errors.h"
 #include "meta/prefs.h"
@@ -477,13 +478,15 @@ meta_end_modal_for_plugin (MetaCompositor *compositor,
 static void
 redirect_windows (MetaX11Display *x11_display)
 {
+  MetaBackend *backend = meta_get_backend ();
+  MetaContext *context = meta_backend_get_context (backend);
   Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
   Window xroot = meta_x11_display_get_xroot (x11_display);
   int screen_number = meta_x11_display_get_screen_number (x11_display);
   guint n_retries;
   guint max_retries;
 
-  if (meta_get_replace_current_wm ())
+  if (meta_context_is_replacing (context))
     max_retries = 5;
   else
     max_retries = 1;
diff --git a/src/core/meta-context-main.c b/src/core/meta-context-main.c
index 6c40ba526f..8f669151aa 100644
--- a/src/core/meta-context-main.c
+++ b/src/core/meta-context-main.c
@@ -329,6 +329,14 @@ meta_context_main_get_x11_display_policy (MetaContext *context)
   g_assert_not_reached ();
 }
 
+static gboolean
+meta_context_main_is_replacing (MetaContext *context)
+{
+  MetaContextMain *context_main = META_CONTEXT_MAIN (context);
+
+  return context_main->options.x11.replace;
+}
+
 #ifdef HAVE_NATIVE_BACKEND
 static gboolean
 add_persistent_virtual_monitors (MetaContextMain  *context_main,
@@ -382,7 +390,6 @@ meta_context_main_setup (MetaContext  *context,
     return FALSE;
 
   meta_set_syncing (context_main->options.x11.sync || g_getenv ("MUTTER_SYNC"));
-  meta_set_replace_current_wm (context_main->options.x11.replace);
 
 #ifdef HAVE_NATIVE_BACKEND
   if (!add_persistent_virtual_monitors (context_main, error))
@@ -682,6 +689,7 @@ meta_context_main_class_init (MetaContextMainClass *klass)
   context_class->get_compositor_type = meta_context_main_get_compositor_type;
   context_class->get_x11_display_policy =
     meta_context_main_get_x11_display_policy;
+  context_class->is_replacing = meta_context_main_is_replacing;
   context_class->setup = meta_context_main_setup;
   context_class->create_backend = meta_context_main_create_backend;
   context_class->notify_ready = meta_context_main_notify_ready;
diff --git a/src/core/meta-context-private.h b/src/core/meta-context-private.h
index 422316cb59..503d78ef7f 100644
--- a/src/core/meta-context-private.h
+++ b/src/core/meta-context-private.h
@@ -39,6 +39,8 @@ struct _MetaContextClass
 
   MetaX11DisplayPolicy (* get_x11_display_policy) (MetaContext *context);
 
+  gboolean (* is_replacing) (MetaContext *context);
+
   gboolean (* setup) (MetaContext  *context,
                       GError      **error);
 
diff --git a/src/core/meta-context.c b/src/core/meta-context.c
index 79c3ff9d7f..291cdbd32f 100644
--- a/src/core/meta-context.c
+++ b/src/core/meta-context.c
@@ -212,6 +212,12 @@ meta_context_get_compositor_type (MetaContext *context)
   return META_CONTEXT_GET_CLASS (context)->get_compositor_type (context);
 }
 
+gboolean
+meta_context_is_replacing (MetaContext *context)
+{
+  return META_CONTEXT_GET_CLASS (context)->is_replacing (context);
+}
+
 MetaX11DisplayPolicy
 meta_context_get_x11_display_policy (MetaContext *context)
 {
diff --git a/src/core/util.c b/src/core/util.c
index 28e7947819..da3dfa5f45 100644
--- a/src/core/util.c
+++ b/src/core/util.c
@@ -80,7 +80,6 @@ meta_topic_real_valist (MetaDebugTopic topic,
 #endif
 
 static gint verbose_topics = 0;
-static gboolean replace_current = FALSE;
 static int no_prefix = 0;
 static gboolean is_wayland_compositor = FALSE;
 static int debug_paint_flags = 0;
@@ -218,18 +217,6 @@ meta_init_debug_utils (void)
     }
 }
 
-gboolean
-meta_get_replace_current_wm (void)
-{
-  return replace_current;
-}
-
-void
-meta_set_replace_current_wm (gboolean setting)
-{
-  replace_current = setting;
-}
-
 gboolean
 meta_is_wayland_compositor (void)
 {
diff --git a/src/meta/main.h b/src/meta/main.h
index f5512caa6d..3e5db424ae 100644
--- a/src/meta/main.h
+++ b/src/meta/main.h
@@ -26,9 +26,6 @@
 
 #include <meta/common.h>
 
-META_EXPORT
-gboolean        meta_get_replace_current_wm (void);  /* Actually defined in util.c */
-
 META_EXPORT
 void            meta_restart                (const char *message);
 
diff --git a/src/meta/meta-context.h b/src/meta/meta-context.h
index e4252daf67..50b4bd5f94 100644
--- a/src/meta/meta-context.h
+++ b/src/meta/meta-context.h
@@ -89,6 +89,9 @@ void meta_context_terminate_with_error (MetaContext *context,
 META_EXPORT
 MetaCompositorType meta_context_get_compositor_type (MetaContext *context);
 
+META_EXPORT
+gboolean meta_context_is_replacing (MetaContext *context);
+
 META_EXPORT
 MetaBackend * meta_context_get_backend (MetaContext *context);
 
diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c
index db544c04d4..7ce7ac85b9 100644
--- a/src/tests/meta-context-test.c
+++ b/src/tests/meta-context-test.c
@@ -102,6 +102,12 @@ meta_context_test_get_x11_display_policy (MetaContext *context)
     return META_X11_DISPLAY_POLICY_ON_DEMAND;
 }
 
+static gboolean
+meta_context_test_is_replacing (MetaContext *context)
+{
+  return FALSE;
+}
+
 static gboolean
 meta_context_test_setup (MetaContext  *context,
                          GError      **error)
@@ -263,6 +269,7 @@ meta_context_test_class_init (MetaContextTestClass *klass)
   context_class->get_compositor_type = meta_context_test_get_compositor_type;
   context_class->get_x11_display_policy =
     meta_context_test_get_x11_display_policy;
+  context_class->is_replacing = meta_context_test_is_replacing;
   context_class->setup = meta_context_test_setup;
   context_class->create_backend = meta_context_test_create_backend;
   context_class->notify_ready = meta_context_test_notify_ready;
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index 2646e3afe6..8b446e3485 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1157,7 +1157,8 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
   if (meta_is_syncing ())
     XSynchronize (xdisplay, True);
 
-  replace_current_wm = meta_get_replace_current_wm ();
+  replace_current_wm =
+    meta_context_is_replacing (meta_backend_get_context (backend));
 
   /* According to _gdk_x11_display_open (), this will be returned
    * by gdk_display_get_default_screen ()


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