1e895f
From d89c71ed2bdb18e9b01891d6b999c44f955778dc Mon Sep 17 00:00:00 2001
1e895f
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
1e895f
Date: Wed, 1 Sep 2021 21:12:03 +0200
1e895f
Subject: [PATCH 1/2] context: Add :unsafe-mode property
1e895f
1e895f
We are going to restrict several sensitive D-Bus APIs to a set
1e895f
of allowed callers (like Settings or portal implementations).
1e895f
1e895f
Add an :unsafe-mode property to the context to allow turning off
1e895f
those restrictions temporarily, in order to not get in the way
1e895f
of development/debugging.
1e895f
1e895f
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943
1e895f
1e895f
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1983>
1e895f
---
1e895f
 src/backends/meta-backend-private.h |  4 ++
1e895f
 src/backends/meta-backend.c         | 83 +++++++++++++++++++++++++++++
1e895f
 2 files changed, 87 insertions(+)
1e895f
1e895f
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
1e895f
index b930462b2..583d4e151 100644
1e895f
--- a/src/backends/meta-backend-private.h
1e895f
+++ b/src/backends/meta-backend-private.h
1e895f
@@ -133,6 +133,10 @@ void meta_backend_foreach_device_monitor (MetaBackend *backend,
1e895f
                                           GFunc        func,
1e895f
                                           gpointer     user_data);
1e895f
 
1e895f
+gboolean meta_backend_get_unsafe_mode (MetaBackend *backend);
1e895f
+void meta_backend_set_unsafe_mode (MetaBackend *backend,
1e895f
+                                   gboolean     enable);
1e895f
+
1e895f
 META_EXPORT_TEST
1e895f
 MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend);
1e895f
 MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend);
1e895f
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
1e895f
index ff84bfe6a..18bee2484 100644
1e895f
--- a/src/backends/meta-backend.c
1e895f
+++ b/src/backends/meta-backend.c
1e895f
@@ -88,6 +88,17 @@
1e895f
 #include "wayland/meta-wayland.h"
1e895f
 #endif
1e895f
 
1e895f
+enum
1e895f
+{
1e895f
+  PROP_0,
1e895f
+
1e895f
+  PROP_UNSAFE_MODE,
1e895f
+
1e895f
+  N_PROPS
1e895f
+};
1e895f
+
1e895f
+static GParamSpec *obj_props[N_PROPS];
1e895f
+
1e895f
 enum
1e895f
 {
1e895f
   KEYMAP_CHANGED,
1e895f
@@ -158,6 +169,8 @@ struct _MetaBackendPrivate
1e895f
 
1e895f
   gboolean is_pointer_position_initialized;
1e895f
 
1e895f
+  gboolean unsafe_mode;
1e895f
+
1e895f
   guint device_update_idle_id;
1e895f
 
1e895f
   GHashTable *device_monitors;
1e895f
@@ -814,6 +827,64 @@ upower_vanished (GDBusConnection *connection,
1e895f
   g_clear_object (&priv->upower_proxy);
1e895f
 }
1e895f
 
1e895f
+gboolean
1e895f
+meta_backend_get_unsafe_mode (MetaBackend *backend)
1e895f
+{
1e895f
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
1e895f
+
1e895f
+  return priv->unsafe_mode;
1e895f
+}
1e895f
+
1e895f
+void
1e895f
+meta_backend_set_unsafe_mode (MetaBackend *backend,
1e895f
+                              gboolean     enable)
1e895f
+{
1e895f
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
1e895f
+
1e895f
+  if (priv->unsafe_mode == enable)
1e895f
+    return;
1e895f
+
1e895f
+  priv->unsafe_mode = enable;
1e895f
+  g_object_notify_by_pspec (G_OBJECT (backend), obj_props[PROP_UNSAFE_MODE]);
1e895f
+}
1e895f
+
1e895f
+static void
1e895f
+meta_backend_get_property (GObject    *object,
1e895f
+                           guint       prop_id,
1e895f
+                           GValue     *value,
1e895f
+                           GParamSpec *pspec)
1e895f
+{
1e895f
+  MetaBackend *backend = META_BACKEND (object);
1e895f
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
1e895f
+
1e895f
+  switch (prop_id)
1e895f
+    {
1e895f
+    case PROP_UNSAFE_MODE:
1e895f
+      g_value_set_boolean (value, priv->unsafe_mode);
1e895f
+      break;
1e895f
+    default:
1e895f
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1e895f
+    }
1e895f
+}
1e895f
+
1e895f
+static void
1e895f
+meta_backend_set_property (GObject      *object,
1e895f
+                           guint         prop_id,
1e895f
+                           const GValue *value,
1e895f
+                           GParamSpec   *pspec)
1e895f
+{
1e895f
+  MetaBackend *backend = META_BACKEND (object);
1e895f
+
1e895f
+  switch (prop_id)
1e895f
+    {
1e895f
+    case PROP_UNSAFE_MODE:
1e895f
+      meta_backend_set_unsafe_mode (backend, g_value_get_boolean (value));
1e895f
+      break;
1e895f
+    default:
1e895f
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1e895f
+    }
1e895f
+}
1e895f
+
1e895f
 static void
1e895f
 meta_backend_constructed (GObject *object)
1e895f
 {
1e895f
@@ -851,6 +922,8 @@ meta_backend_class_init (MetaBackendClass *klass)
1e895f
 
1e895f
   object_class->dispose = meta_backend_dispose;
1e895f
   object_class->constructed = meta_backend_constructed;
1e895f
+  object_class->get_property = meta_backend_get_property;
1e895f
+  object_class->set_property = meta_backend_set_property;
1e895f
 
1e895f
   klass->post_init = meta_backend_real_post_init;
1e895f
   klass->grab_device = meta_backend_real_grab_device;
1e895f
@@ -907,6 +980,16 @@ meta_backend_class_init (MetaBackendClass *klass)
1e895f
                   NULL, NULL, NULL,
1e895f
                   G_TYPE_NONE, 0);
1e895f
 
1e895f
+  obj_props[PROP_UNSAFE_MODE] =
1e895f
+    g_param_spec_boolean ("unsafe-mode",
1e895f
+                          "unsafe mode",
1e895f
+                          "Unsafe mode",
1e895f
+                          FALSE,
1e895f
+                          G_PARAM_READWRITE |
1e895f
+                          G_PARAM_EXPLICIT_NOTIFY |
1e895f
+                          G_PARAM_STATIC_STRINGS);
1e895f
+  g_object_class_install_properties (object_class, N_PROPS, obj_props);
1e895f
+
1e895f
   mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS");
1e895f
   stage_views_disabled = g_strcmp0 (mutter_stage_views, "0") == 0;
1e895f
 }
1e895f
-- 
1e895f
2.35.1
1e895f
1e895f
1e895f
From dc69aa57be79fa7f371788c852f6e23cf0d261cb Mon Sep 17 00:00:00 2001
1e895f
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
1e895f
Date: Thu, 2 Sep 2021 18:41:16 +0200
1e895f
Subject: [PATCH 2/2] context: Add (hidden) --unsafe-mode option
1e895f
1e895f
When running gnome-shell, it is possible to toggle unsafe-mode in
1e895f
looking glass. We'll eventually start using the property in mutter
1e895f
as well, so to make stand-alone debugging easier, also expose it
1e895f
as a hidden command line option.
1e895f
1e895f
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943
1e895f
1e895f
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1983>
1e895f
---
1e895f
 src/core/main.c | 7 +++++++
1e895f
 1 file changed, 7 insertions(+)
1e895f
1e895f
diff --git a/src/core/main.c b/src/core/main.c
1e895f
index 0d241f952..991d583a0 100644
1e895f
--- a/src/core/main.c
1e895f
+++ b/src/core/main.c
1e895f
@@ -218,6 +218,7 @@ static char     *opt_wayland_display;
1e895f
 static gboolean  opt_display_server;
1e895f
 static gboolean  opt_headless;
1e895f
 #endif
1e895f
+static gboolean  opt_unsafe_mode;
1e895f
 static gboolean  opt_x11;
1e895f
 
1e895f
 #ifdef HAVE_NATIVE_BACKEND
1e895f
@@ -306,6 +307,11 @@ static GOptionEntry meta_options[] = {
1e895f
     N_("Add persistent virtual monitor (WxH or WxH@R)")
1e895f
   },
1e895f
 #endif
1e895f
+  {
1e895f
+    "unsafe-mode", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
1e895f
+    &opt_unsafe_mode,
1e895f
+    "Run in unsafe mode"
1e895f
+  },
1e895f
   {
1e895f
     "x11", 0, 0, G_OPTION_ARG_NONE,
1e895f
     &opt_x11,
1e895f
@@ -865,6 +871,7 @@ meta_init (void)
1e895f
   add_persistent_virtual_monitors ();
1e895f
 #endif
1e895f
 
1e895f
+  meta_backend_set_unsafe_mode (meta_get_backend(), opt_unsafe_mode);
1e895f
   meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL));
1e895f
 
1e895f
   if (opt_replace_wm)
1e895f
-- 
1e895f
2.35.1
1e895f