summaryrefslogtreecommitdiff
path: root/0001-display-Only-display-configuration-options-if-apply-.patch
blob: 54cdd38e4bd752cf8d6e57df4195f72aae674ae4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
From f6e0cba768d376a7f710dd8a69c17ec50c7a13a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
Date: Fri, 4 Feb 2022 11:09:24 +0100
Subject: [PATCH] display: Only display configuration options if apply is
 allowed

org.gnome.Mutter.DisplayConfig contains a new property that tells
whether apply will be allowed to be called or not. Whether it is true or
not depends on policy stored in any of its monitors.xml configuration
files.

In order to make it clearer that configuration is not possible, except
for night light, make sure to hide the unconfigurable parts, leaving
only night light.
---
 .../display/cc-display-config-manager-dbus.c  | 36 +++++++++++++++++++
 panels/display/cc-display-config-manager.c    |  6 ++++
 panels/display/cc-display-config-manager.h    |  3 ++
 panels/display/cc-display-panel.c             | 11 ++++++
 panels/display/cc-display-panel.ui            |  2 +-
 5 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/panels/display/cc-display-config-manager-dbus.c b/panels/display/cc-display-config-manager-dbus.c
index 653bea0b5..392140101 100644
--- a/panels/display/cc-display-config-manager-dbus.c
+++ b/panels/display/cc-display-config-manager-dbus.c
@@ -31,6 +31,8 @@ struct _CcDisplayConfigManagerDBus
   guint monitors_changed_id;
 
   GVariant *current_state;
+
+  gboolean apply_allowed;
 };
 
 G_DEFINE_TYPE (CcDisplayConfigManagerDBus,
@@ -118,6 +120,8 @@ bus_gotten (GObject      *object,
   CcDisplayConfigManagerDBus *self;
   GDBusConnection *connection;
   g_autoptr(GError) error = NULL;
+  g_autoptr(GDBusProxy) proxy = NULL;
+  g_autoptr(GVariant) variant = NULL;
 
   connection = g_bus_get_finish (result, &error);
   if (!connection)
@@ -143,12 +147,35 @@ bus_gotten (GObject      *object,
                                         monitors_changed,
                                         self,
                                         NULL);
+
+  proxy = g_dbus_proxy_new_sync (self->connection,
+                                 G_DBUS_PROXY_FLAGS_NONE,
+                                 NULL,
+                                 "org.gnome.Mutter.DisplayConfig",
+                                 "/org/gnome/Mutter/DisplayConfig",
+                                 "org.gnome.Mutter.DisplayConfig",
+                                 NULL,
+                                 &error);
+  if (!proxy)
+    {
+      g_warning ("Failed to create D-Bus proxy to \"org.gnome.Mutter.DisplayConfig\": %s",
+                 error->message);
+      return;
+    }
+
+  variant = g_dbus_proxy_get_cached_property (proxy, "ApplyMonitorsConfigAllowed");
+  if (variant)
+    self->apply_allowed = g_variant_get_boolean (variant);
+  else
+    g_warning ("Missing property 'ApplyMonitorsConfigAllowed' on DisplayConfig API");
+
   get_current_state (self);
 }
 
 static void
 cc_display_config_manager_dbus_init (CcDisplayConfigManagerDBus *self)
 {
+  self->apply_allowed = TRUE;
   self->cancellable = g_cancellable_new ();
   g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, bus_gotten, self);
 }
@@ -170,6 +197,14 @@ cc_display_config_manager_dbus_finalize (GObject *object)
   G_OBJECT_CLASS (cc_display_config_manager_dbus_parent_class)->finalize (object);
 }
 
+static gboolean
+cc_display_config_manager_dbus_get_apply_allowed (CcDisplayConfigManager *pself)
+{
+  CcDisplayConfigManagerDBus *self = CC_DISPLAY_CONFIG_MANAGER_DBUS (pself);
+
+  return self->apply_allowed;
+}
+
 static void
 cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klass)
 {
@@ -179,6 +214,7 @@ cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klas
   gobject_class->finalize = cc_display_config_manager_dbus_finalize;
 
   parent_class->get_current = cc_display_config_manager_dbus_get_current;
+  parent_class->get_apply_allowed = cc_display_config_manager_dbus_get_apply_allowed;
 }
 
 CcDisplayConfigManager *
diff --git a/panels/display/cc-display-config-manager.c b/panels/display/cc-display-config-manager.c
index 0da298a29..3d683c53d 100644
--- a/panels/display/cc-display-config-manager.c
+++ b/panels/display/cc-display-config-manager.c
@@ -59,3 +59,9 @@ cc_display_config_manager_get_current (CcDisplayConfigManager *self)
 {
   return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_current (self);
 }
+
+gboolean
+cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self)
+{
+  return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_apply_allowed (self);
+}
diff --git a/panels/display/cc-display-config-manager.h b/panels/display/cc-display-config-manager.h
index 1e1b36373..64f0775e9 100644
--- a/panels/display/cc-display-config-manager.h
+++ b/panels/display/cc-display-config-manager.h
@@ -34,10 +34,13 @@ struct _CcDisplayConfigManagerClass
   GObjectClass parent_class;
 
   CcDisplayConfig * (*get_current) (CcDisplayConfigManager *self);
+  gboolean (* get_apply_allowed) (CcDisplayConfigManager *self);
 };
 
 CcDisplayConfig * cc_display_config_manager_get_current (CcDisplayConfigManager *self);
 
+gboolean cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self);
+
 void _cc_display_config_manager_emit_changed (CcDisplayConfigManager *self);
 
 G_END_DECLS
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index 93c983f89..2cfd714d3 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -69,6 +69,8 @@ struct _CcDisplayPanel
 
   gint                  rebuilding_counter;
 
+  GtkWidget *displays_page;
+
   CcDisplayArrangement *arrangement;
   CcDisplaySettings    *settings;
 
@@ -691,6 +693,7 @@ cc_display_panel_class_init (CcDisplayPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, current_output_label);
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_frame);
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, multi_selection_box);
+  gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, displays_page);
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, night_light_page);
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_enabled_switch);
   gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_combo);
@@ -779,8 +782,16 @@ rebuild_ui (CcDisplayPanel *panel)
   GList *outputs, *l;
   CcDisplayConfigType type;
 
+  if (!cc_display_config_manager_get_apply_allowed (panel->manager))
+    {
+      gtk_widget_set_visible (panel->displays_page, FALSE);
+      return;
+    }
+
   panel->rebuilding_counter++;
 
+  gtk_widget_set_visible (panel->displays_page, TRUE);
+
   g_list_store_remove_all (panel->primary_display_list);
   gtk_list_store_clear (panel->output_selection_list);
 
diff --git a/panels/display/cc-display-panel.ui b/panels/display/cc-display-panel.ui
index 855b34814..80fd63ace 100644
--- a/panels/display/cc-display-panel.ui
+++ b/panels/display/cc-display-panel.ui
@@ -47,7 +47,7 @@
 
         <!-- Displays page -->
         <child>
-          <object class="GtkScrolledWindow">
+          <object class="GtkScrolledWindow" id="displays_page">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="hscrollbar_policy">never</property>
-- 
2.33.1