Blame SOURCES/0001-display-Only-display-configuration-options-if-apply-.patch

44c0da
From 22c43422f83a69d7654953db368585f168952aab Mon Sep 17 00:00:00 2001
44c0da
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
44c0da
Date: Fri, 4 Feb 2022 11:45:53 +0100
44c0da
Subject: [PATCH] display: Only display configuration options if apply is
44c0da
 allowed
44c0da
44c0da
org.gnome.Mutter.DisplayConfig contains a new property that tells
44c0da
whether apply will be allowed to be called or not. Whether it is true or
44c0da
not depends on policy stored in any of its monitors.xml configuration
44c0da
files.
44c0da
44c0da
In order to make it clearer that configuration is not possible, except
44c0da
for night light, make sure to hide the unconfigurable parts, leaving
44c0da
only night light.
44c0da
---
44c0da
 .../display/cc-display-config-manager-dbus.c  | 36 +++++++++++++++++++
44c0da
 panels/display/cc-display-config-manager.c    |  6 ++++
44c0da
 panels/display/cc-display-config-manager.h    |  3 ++
44c0da
 panels/display/cc-display-panel.c             | 23 ++++++++++++
44c0da
 4 files changed, 68 insertions(+)
44c0da
44c0da
diff --git a/panels/display/cc-display-config-manager-dbus.c b/panels/display/cc-display-config-manager-dbus.c
44c0da
index 8912faaa8..7f85c3a01 100644
44c0da
--- a/panels/display/cc-display-config-manager-dbus.c
44c0da
+++ b/panels/display/cc-display-config-manager-dbus.c
44c0da
@@ -31,6 +31,8 @@ struct _CcDisplayConfigManagerDBus
44c0da
   guint monitors_changed_id;
44c0da
 
44c0da
   GVariant *current_state;
44c0da
+
44c0da
+  gboolean apply_allowed;
44c0da
 };
44c0da
 
44c0da
 G_DEFINE_TYPE (CcDisplayConfigManagerDBus,
44c0da
@@ -119,6 +121,8 @@ bus_gotten (GObject      *object,
44c0da
   CcDisplayConfigManagerDBus *self;
44c0da
   GDBusConnection *connection;
44c0da
   GError *error = NULL;
44c0da
+  g_autoptr(GDBusProxy) proxy = NULL;
44c0da
+  g_autoptr(GVariant) variant = NULL;
44c0da
 
44c0da
   connection = g_bus_get_finish (result, &error);
44c0da
   if (!connection)
44c0da
@@ -145,12 +149,35 @@ bus_gotten (GObject      *object,
44c0da
                                         monitors_changed,
44c0da
                                         self,
44c0da
                                         NULL);
44c0da
+
44c0da
+  proxy = g_dbus_proxy_new_sync (self->connection,
44c0da
+                                 G_DBUS_PROXY_FLAGS_NONE,
44c0da
+                                 NULL,
44c0da
+                                 "org.gnome.Mutter.DisplayConfig",
44c0da
+                                 "/org/gnome/Mutter/DisplayConfig",
44c0da
+                                 "org.gnome.Mutter.DisplayConfig",
44c0da
+                                 NULL,
44c0da
+                                 &error);
44c0da
+  if (!proxy)
44c0da
+    {
44c0da
+      g_warning ("Failed to create D-Bus proxy to \"org.gnome.Mutter.DisplayConfig\": %s",
44c0da
+                 error->message);
44c0da
+      return;
44c0da
+    }
44c0da
+
44c0da
+  variant = g_dbus_proxy_get_cached_property (proxy, "ApplyMonitorsConfigAllowed");
44c0da
+  if (variant)
44c0da
+    self->apply_allowed = g_variant_get_boolean (variant);
44c0da
+  else
44c0da
+    g_warning ("Missing property 'ApplyMonitorsConfigAllowed' on DisplayConfig API");
44c0da
+
44c0da
   get_current_state (self);
44c0da
 }
44c0da
 
44c0da
 static void
44c0da
 cc_display_config_manager_dbus_init (CcDisplayConfigManagerDBus *self)
44c0da
 {
44c0da
+  self->apply_allowed = TRUE;
44c0da
   self->cancellable = g_cancellable_new ();
44c0da
   g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, bus_gotten, self);
44c0da
 }
44c0da
@@ -172,6 +199,14 @@ cc_display_config_manager_dbus_finalize (GObject *object)
44c0da
   G_OBJECT_CLASS (cc_display_config_manager_dbus_parent_class)->finalize (object);
44c0da
 }
44c0da
 
44c0da
+static gboolean
44c0da
+cc_display_config_manager_dbus_get_apply_allowed (CcDisplayConfigManager *pself)
44c0da
+{
44c0da
+  CcDisplayConfigManagerDBus *self = CC_DISPLAY_CONFIG_MANAGER_DBUS (pself);
44c0da
+
44c0da
+  return self->apply_allowed;
44c0da
+}
44c0da
+
44c0da
 static void
44c0da
 cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klass)
44c0da
 {
44c0da
@@ -181,6 +216,7 @@ cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klas
44c0da
   gobject_class->finalize = cc_display_config_manager_dbus_finalize;
44c0da
 
44c0da
   parent_class->get_current = cc_display_config_manager_dbus_get_current;
44c0da
+  parent_class->get_apply_allowed = cc_display_config_manager_dbus_get_apply_allowed;
44c0da
 }
44c0da
 
44c0da
 CcDisplayConfigManager *
44c0da
diff --git a/panels/display/cc-display-config-manager.c b/panels/display/cc-display-config-manager.c
44c0da
index 0da298a29..3d683c53d 100644
44c0da
--- a/panels/display/cc-display-config-manager.c
44c0da
+++ b/panels/display/cc-display-config-manager.c
44c0da
@@ -59,3 +59,9 @@ cc_display_config_manager_get_current (CcDisplayConfigManager *self)
44c0da
 {
44c0da
   return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_current (self);
44c0da
 }
44c0da
+
44c0da
+gboolean
44c0da
+cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self)
44c0da
+{
44c0da
+  return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_apply_allowed (self);
44c0da
+}
44c0da
diff --git a/panels/display/cc-display-config-manager.h b/panels/display/cc-display-config-manager.h
44c0da
index 134cea0a1..22c16758c 100644
44c0da
--- a/panels/display/cc-display-config-manager.h
44c0da
+++ b/panels/display/cc-display-config-manager.h
44c0da
@@ -35,10 +35,13 @@ struct _CcDisplayConfigManagerClass
44c0da
   GObjectClass parent_class;
44c0da
 
44c0da
   CcDisplayConfig * (*get_current) (CcDisplayConfigManager *self);
44c0da
+  gboolean (* get_apply_allowed) (CcDisplayConfigManager *self);
44c0da
 };
44c0da
 
44c0da
 CcDisplayConfig * cc_display_config_manager_get_current (CcDisplayConfigManager *self);
44c0da
 
44c0da
+gboolean cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self);
44c0da
+
44c0da
 void _cc_display_config_manager_emit_changed (CcDisplayConfigManager *self);
44c0da
 
44c0da
 G_END_DECLS
44c0da
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
44c0da
index 0b4fa193d..1b0db8321 100644
44c0da
--- a/panels/display/cc-display-panel.c
44c0da
+++ b/panels/display/cc-display-panel.c
44c0da
@@ -1245,6 +1245,22 @@ make_output_ui (CcDisplayPanel *panel)
44c0da
   return listbox;
44c0da
 }
44c0da
 
44c0da
+static GtkWidget *
44c0da
+make_night_light_only_ui (CcDisplayPanel *panel)
44c0da
+{
44c0da
+  CcDisplayPanelPrivate *priv = panel->priv;
44c0da
+  GtkWidget *vbox;
44c0da
+
44c0da
+  priv->rows_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
44c0da
+
44c0da
+  vbox = make_main_vbox (priv->main_size_group);
44c0da
+
44c0da
+  gtk_container_add (GTK_CONTAINER (vbox), make_night_light_widget (panel));
44c0da
+
44c0da
+  g_clear_object (&priv->rows_size_group);
44c0da
+  return make_scrollable (vbox);
44c0da
+}
44c0da
+
44c0da
 static GtkWidget *
44c0da
 make_single_output_ui (CcDisplayPanel *panel)
44c0da
 {
44c0da
@@ -2097,6 +2113,12 @@ on_screen_changed (CcDisplayPanel *panel)
44c0da
   if (!priv->current_config)
44c0da
     goto show_error;
44c0da
 
44c0da
+  if (!cc_display_config_manager_get_apply_allowed (priv->manager))
44c0da
+    {
44c0da
+      main_widget = make_night_light_only_ui (panel);
44c0da
+      goto show_main_widget;
44c0da
+    }
44c0da
+
44c0da
   ensure_monitor_labels (panel);
44c0da
 
44c0da
   if (!priv->current_output)
44c0da
@@ -2121,6 +2143,7 @@ on_screen_changed (CcDisplayPanel *panel)
44c0da
         main_widget = make_multi_output_ui (panel);
44c0da
     }
44c0da
 
44c0da
+ show_main_widget:
44c0da
   gtk_widget_show_all (main_widget);
44c0da
   gtk_stack_add_named (GTK_STACK (priv->stack), main_widget, "main");
44c0da
   gtk_stack_set_visible_child (GTK_STACK (priv->stack), main_widget);
44c0da
-- 
44c0da
2.33.1
44c0da