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

46fec3
From f6e0cba768d376a7f710dd8a69c17ec50c7a13a9 Mon Sep 17 00:00:00 2001
46fec3
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
46fec3
Date: Fri, 4 Feb 2022 11:09:24 +0100
46fec3
Subject: [PATCH] display: Only display configuration options if apply is
46fec3
 allowed
46fec3
46fec3
org.gnome.Mutter.DisplayConfig contains a new property that tells
46fec3
whether apply will be allowed to be called or not. Whether it is true or
46fec3
not depends on policy stored in any of its monitors.xml configuration
46fec3
files.
46fec3
46fec3
In order to make it clearer that configuration is not possible, except
46fec3
for night light, make sure to hide the unconfigurable parts, leaving
46fec3
only night light.
46fec3
---
46fec3
 .../display/cc-display-config-manager-dbus.c  | 36 +++++++++++++++++++
46fec3
 panels/display/cc-display-config-manager.c    |  6 ++++
46fec3
 panels/display/cc-display-config-manager.h    |  3 ++
46fec3
 panels/display/cc-display-panel.c             | 11 ++++++
46fec3
 panels/display/cc-display-panel.ui            |  2 +-
46fec3
 5 files changed, 57 insertions(+), 1 deletion(-)
46fec3
46fec3
diff --git a/panels/display/cc-display-config-manager-dbus.c b/panels/display/cc-display-config-manager-dbus.c
46fec3
index 653bea0b5..392140101 100644
46fec3
--- a/panels/display/cc-display-config-manager-dbus.c
46fec3
+++ b/panels/display/cc-display-config-manager-dbus.c
46fec3
@@ -31,6 +31,8 @@ struct _CcDisplayConfigManagerDBus
46fec3
   guint monitors_changed_id;
46fec3
 
46fec3
   GVariant *current_state;
46fec3
+
46fec3
+  gboolean apply_allowed;
46fec3
 };
46fec3
 
46fec3
 G_DEFINE_TYPE (CcDisplayConfigManagerDBus,
46fec3
@@ -118,6 +120,8 @@ bus_gotten (GObject      *object,
46fec3
   CcDisplayConfigManagerDBus *self;
46fec3
   GDBusConnection *connection;
46fec3
   g_autoptr(GError) error = NULL;
46fec3
+  g_autoptr(GDBusProxy) proxy = NULL;
46fec3
+  g_autoptr(GVariant) variant = NULL;
46fec3
 
46fec3
   connection = g_bus_get_finish (result, &error);
46fec3
   if (!connection)
46fec3
@@ -143,12 +147,35 @@ bus_gotten (GObject      *object,
46fec3
                                         monitors_changed,
46fec3
                                         self,
46fec3
                                         NULL);
46fec3
+
46fec3
+  proxy = g_dbus_proxy_new_sync (self->connection,
46fec3
+                                 G_DBUS_PROXY_FLAGS_NONE,
46fec3
+                                 NULL,
46fec3
+                                 "org.gnome.Mutter.DisplayConfig",
46fec3
+                                 "/org/gnome/Mutter/DisplayConfig",
46fec3
+                                 "org.gnome.Mutter.DisplayConfig",
46fec3
+                                 NULL,
46fec3
+                                 &error);
46fec3
+  if (!proxy)
46fec3
+    {
46fec3
+      g_warning ("Failed to create D-Bus proxy to \"org.gnome.Mutter.DisplayConfig\": %s",
46fec3
+                 error->message);
46fec3
+      return;
46fec3
+    }
46fec3
+
46fec3
+  variant = g_dbus_proxy_get_cached_property (proxy, "ApplyMonitorsConfigAllowed");
46fec3
+  if (variant)
46fec3
+    self->apply_allowed = g_variant_get_boolean (variant);
46fec3
+  else
46fec3
+    g_warning ("Missing property 'ApplyMonitorsConfigAllowed' on DisplayConfig API");
46fec3
+
46fec3
   get_current_state (self);
46fec3
 }
46fec3
 
46fec3
 static void
46fec3
 cc_display_config_manager_dbus_init (CcDisplayConfigManagerDBus *self)
46fec3
 {
46fec3
+  self->apply_allowed = TRUE;
46fec3
   self->cancellable = g_cancellable_new ();
46fec3
   g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, bus_gotten, self);
46fec3
 }
46fec3
@@ -170,6 +197,14 @@ cc_display_config_manager_dbus_finalize (GObject *object)
46fec3
   G_OBJECT_CLASS (cc_display_config_manager_dbus_parent_class)->finalize (object);
46fec3
 }
46fec3
 
46fec3
+static gboolean
46fec3
+cc_display_config_manager_dbus_get_apply_allowed (CcDisplayConfigManager *pself)
46fec3
+{
46fec3
+  CcDisplayConfigManagerDBus *self = CC_DISPLAY_CONFIG_MANAGER_DBUS (pself);
46fec3
+
46fec3
+  return self->apply_allowed;
46fec3
+}
46fec3
+
46fec3
 static void
46fec3
 cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klass)
46fec3
 {
46fec3
@@ -179,6 +214,7 @@ cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klas
46fec3
   gobject_class->finalize = cc_display_config_manager_dbus_finalize;
46fec3
 
46fec3
   parent_class->get_current = cc_display_config_manager_dbus_get_current;
46fec3
+  parent_class->get_apply_allowed = cc_display_config_manager_dbus_get_apply_allowed;
46fec3
 }
46fec3
 
46fec3
 CcDisplayConfigManager *
46fec3
diff --git a/panels/display/cc-display-config-manager.c b/panels/display/cc-display-config-manager.c
46fec3
index 0da298a29..3d683c53d 100644
46fec3
--- a/panels/display/cc-display-config-manager.c
46fec3
+++ b/panels/display/cc-display-config-manager.c
46fec3
@@ -59,3 +59,9 @@ cc_display_config_manager_get_current (CcDisplayConfigManager *self)
46fec3
 {
46fec3
   return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_current (self);
46fec3
 }
46fec3
+
46fec3
+gboolean
46fec3
+cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self)
46fec3
+{
46fec3
+  return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_apply_allowed (self);
46fec3
+}
46fec3
diff --git a/panels/display/cc-display-config-manager.h b/panels/display/cc-display-config-manager.h
46fec3
index 1e1b36373..64f0775e9 100644
46fec3
--- a/panels/display/cc-display-config-manager.h
46fec3
+++ b/panels/display/cc-display-config-manager.h
46fec3
@@ -34,10 +34,13 @@ struct _CcDisplayConfigManagerClass
46fec3
   GObjectClass parent_class;
46fec3
 
46fec3
   CcDisplayConfig * (*get_current) (CcDisplayConfigManager *self);
46fec3
+  gboolean (* get_apply_allowed) (CcDisplayConfigManager *self);
46fec3
 };
46fec3
 
46fec3
 CcDisplayConfig * cc_display_config_manager_get_current (CcDisplayConfigManager *self);
46fec3
 
46fec3
+gboolean cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self);
46fec3
+
46fec3
 void _cc_display_config_manager_emit_changed (CcDisplayConfigManager *self);
46fec3
 
46fec3
 G_END_DECLS
46fec3
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
46fec3
index 93c983f89..2cfd714d3 100644
46fec3
--- a/panels/display/cc-display-panel.c
46fec3
+++ b/panels/display/cc-display-panel.c
46fec3
@@ -69,6 +69,8 @@ struct _CcDisplayPanel
46fec3
 
46fec3
   gint                  rebuilding_counter;
46fec3
 
46fec3
+  GtkWidget *displays_page;
46fec3
+
46fec3
   CcDisplayArrangement *arrangement;
46fec3
   CcDisplaySettings    *settings;
46fec3
 
46fec3
@@ -691,6 +693,7 @@ cc_display_panel_class_init (CcDisplayPanelClass *klass)
46fec3
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, current_output_label);
46fec3
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_frame);
46fec3
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, multi_selection_box);
46fec3
+  gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, displays_page);
46fec3
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, night_light_page);
46fec3
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_enabled_switch);
46fec3
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_combo);
46fec3
@@ -779,8 +782,16 @@ rebuild_ui (CcDisplayPanel *panel)
46fec3
   GList *outputs, *l;
46fec3
   CcDisplayConfigType type;
46fec3
 
46fec3
+  if (!cc_display_config_manager_get_apply_allowed (panel->manager))
46fec3
+    {
46fec3
+      gtk_widget_set_visible (panel->displays_page, FALSE);
46fec3
+      return;
46fec3
+    }
46fec3
+
46fec3
   panel->rebuilding_counter++;
46fec3
 
46fec3
+  gtk_widget_set_visible (panel->displays_page, TRUE);
46fec3
+
46fec3
   g_list_store_remove_all (panel->primary_display_list);
46fec3
   gtk_list_store_clear (panel->output_selection_list);
46fec3
 
46fec3
diff --git a/panels/display/cc-display-panel.ui b/panels/display/cc-display-panel.ui
46fec3
index 855b34814..80fd63ace 100644
46fec3
--- a/panels/display/cc-display-panel.ui
46fec3
+++ b/panels/display/cc-display-panel.ui
46fec3
@@ -47,7 +47,7 @@
46fec3
 
46fec3
         
46fec3
         <child>
46fec3
-          <object class="GtkScrolledWindow">
46fec3
+          <object class="GtkScrolledWindow" id="displays_page">
46fec3
             <property name="visible">True</property>
46fec3
             <property name="can_focus">False</property>
46fec3
             <property name="hscrollbar_policy">never</property>
46fec3
-- 
46fec3
2.33.1
46fec3