summaryrefslogtreecommitdiff
path: root/display-infobar-if-night-light-unsupported.patch
blob: 62a3e2b58aac71469021d705b4acae79802ff593 (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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
From c999bade4d27e0384b6495ee3bbf88df1b9e256b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
Date: Thu, 24 Feb 2022 12:30:23 +0100
Subject: [PATCH 1/2] display: Add 'NightLightSupported' property support

---
 panels/display/cc-display-config-manager-dbus.c | 17 +++++++++++++++++
 panels/display/cc-display-config-manager.c      |  6 ++++++
 panels/display/cc-display-config-manager.h      |  3 +++
 3 files changed, 26 insertions(+)

diff --git a/panels/display/cc-display-config-manager-dbus.c b/panels/display/cc-display-config-manager-dbus.c
index 392140101..678b696db 100644
--- a/panels/display/cc-display-config-manager-dbus.c
+++ b/panels/display/cc-display-config-manager-dbus.c
@@ -33,6 +33,7 @@ struct _CcDisplayConfigManagerDBus
   GVariant *current_state;
 
   gboolean apply_allowed;
+  gboolean night_light_supported;
 };
 
 G_DEFINE_TYPE (CcDisplayConfigManagerDBus,
@@ -169,6 +170,12 @@ bus_gotten (GObject      *object,
   else
     g_warning ("Missing property 'ApplyMonitorsConfigAllowed' on DisplayConfig API");
 
+  variant = g_dbus_proxy_get_cached_property (proxy, "NightLightSupported");
+  if (variant)
+    self->night_light_supported = g_variant_get_boolean (variant);
+  else
+    g_warning ("Missing property 'NightLightSupported' on DisplayConfig API");
+
   get_current_state (self);
 }
 
@@ -176,6 +183,7 @@ static void
 cc_display_config_manager_dbus_init (CcDisplayConfigManagerDBus *self)
 {
   self->apply_allowed = TRUE;
+  self->night_light_supported = TRUE;
   self->cancellable = g_cancellable_new ();
   g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, bus_gotten, self);
 }
@@ -205,6 +213,14 @@ cc_display_config_manager_dbus_get_apply_allowed (CcDisplayConfigManager *pself)
   return self->apply_allowed;
 }
 
+static gboolean
+cc_display_config_manager_dbus_get_night_light_supported (CcDisplayConfigManager *pself)
+{
+  CcDisplayConfigManagerDBus *self = CC_DISPLAY_CONFIG_MANAGER_DBUS (pself);
+
+  return self->night_light_supported;
+}
+
 static void
 cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klass)
 {
@@ -215,6 +231,7 @@ cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klas
 
   parent_class->get_current = cc_display_config_manager_dbus_get_current;
   parent_class->get_apply_allowed = cc_display_config_manager_dbus_get_apply_allowed;
+  parent_class->get_night_light_supported = cc_display_config_manager_dbus_get_night_light_supported;
 }
 
 CcDisplayConfigManager *
diff --git a/panels/display/cc-display-config-manager.c b/panels/display/cc-display-config-manager.c
index 3d683c53d..f231edd69 100644
--- a/panels/display/cc-display-config-manager.c
+++ b/panels/display/cc-display-config-manager.c
@@ -65,3 +65,9 @@ cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self)
 {
   return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_apply_allowed (self);
 }
+
+gboolean
+cc_display_config_manager_get_night_light_supported (CcDisplayConfigManager *self)
+{
+  return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_night_light_supported (self);
+}
diff --git a/panels/display/cc-display-config-manager.h b/panels/display/cc-display-config-manager.h
index 64f0775e9..ab1e84f85 100644
--- a/panels/display/cc-display-config-manager.h
+++ b/panels/display/cc-display-config-manager.h
@@ -35,12 +35,15 @@ struct _CcDisplayConfigManagerClass
 
   CcDisplayConfig * (*get_current) (CcDisplayConfigManager *self);
   gboolean (* get_apply_allowed) (CcDisplayConfigManager *self);
+  gboolean (* get_night_light_supported) (CcDisplayConfigManager *self);
 };
 
 CcDisplayConfig * cc_display_config_manager_get_current (CcDisplayConfigManager *self);
 
 gboolean cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self);
 
+gboolean cc_display_config_manager_get_night_light_supported (CcDisplayConfigManager *self);
+
 void _cc_display_config_manager_emit_changed (CcDisplayConfigManager *self);
 
 G_END_DECLS
-- 
2.34.1


From 414e23272f89198efc452a4f8d50442c72a07956 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
Date: Thu, 24 Feb 2022 12:31:00 +0100
Subject: [PATCH 2/2] display: Show infobar if night light isn't supported

This may be the case on e.g. fully remote / headless sessions, or as of
now, when using the NVIDIA driver to run a Wayland session.

Closes: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1659
---
 panels/display/cc-night-light-page.c  | 153 +++++++++++++++-----------
 panels/display/cc-night-light-page.ui |  41 ++++++-
 2 files changed, 129 insertions(+), 65 deletions(-)

diff --git a/panels/display/cc-night-light-page.c b/panels/display/cc-night-light-page.c
index f51b0ba69..482b90fea 100644
--- a/panels/display/cc-night-light-page.c
+++ b/panels/display/cc-night-light-page.c
@@ -29,15 +29,18 @@
 #include "list-box-helper.h"
 
 #include "shell/cc-object-storage.h"
+#include "cc-display-config-manager-dbus.h"
 
 struct _CcNightLightPage {
   GtkBin               parent;
 
+  GtkWidget           *night_light_settings;
   GtkWidget           *box_manual;
   GtkButton           *button_from_am;
   GtkButton           *button_from_pm;
   GtkButton           *button_to_am;
   GtkButton           *button_to_pm;
+  GtkWidget           *infobar_unsupported;
   GtkWidget           *infobar_disabled;
   GtkListBox          *listbox;
   GtkWidget           *scale_color_temperature;
@@ -64,6 +67,8 @@ struct _CcNightLightPage {
   gboolean             ignore_value_changed;
   guint                timer_id;
   GDesktopClockFormat  clock_format;
+
+  CcDisplayConfigManager *config_manager;
 };
 
 G_DEFINE_TYPE (CcNightLightPage, cc_night_light_page, GTK_TYPE_BIN);
@@ -122,88 +127,97 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self,
 static void
 dialog_update_state (CcNightLightPage *self)
 {
-  gboolean automatic;
-  gboolean disabled_until_tomorrow = FALSE;
-  gboolean enabled;
-  gdouble value = 0.f;
-
-  /* only show the infobar if we are disabled */
-  if (self->proxy_color != NULL)
+  if (cc_display_config_manager_get_night_light_supported (self->config_manager))
     {
-      g_autoptr(GVariant) disabled = NULL;
-      disabled = g_dbus_proxy_get_cached_property (self->proxy_color,
-                                                   "DisabledUntilTomorrow");
-      if (disabled != NULL)
-        disabled_until_tomorrow = g_variant_get_boolean (disabled);
-    }
-  gtk_widget_set_visible (self->infobar_disabled, disabled_until_tomorrow);
+      gboolean automatic;
+      gboolean disabled_until_tomorrow = FALSE;
+      gboolean enabled;
+      gdouble value = 0.f;
 
-  /* make things insensitive if the switch is disabled */
-  enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
-  automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
+      /* only show the infobar if we are disabled */
+      if (self->proxy_color != NULL)
+        {
+          g_autoptr(GVariant) disabled = NULL;
+          disabled = g_dbus_proxy_get_cached_property (self->proxy_color,
+                                                       "DisabledUntilTomorrow");
+          if (disabled != NULL)
+            disabled_until_tomorrow = g_variant_get_boolean (disabled);
+        }
+      gtk_widget_set_visible (self->infobar_disabled, disabled_until_tomorrow);
 
-  gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
+      /* make things insensitive if the switch is disabled */
+      enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
+      automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
 
-  gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
+      gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
 
-  /* set from */
-  if (automatic && self->proxy_color != NULL)
-    {
-      g_autoptr(GVariant) sunset = NULL;
-      sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunset");
-      if (sunset != NULL)
+      gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
+
+      /* set from */
+      if (automatic && self->proxy_color != NULL)
         {
-          value = g_variant_get_double (sunset);
+          g_autoptr(GVariant) sunset = NULL;
+          sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunset");
+          if (sunset != NULL)
+            {
+              value = g_variant_get_double (sunset);
+            }
+          else
+            {
+              value = 16.0f;
+              g_warning ("no sunset data, using %02.2f", value);
+            }
         }
       else
         {
-          value = 16.0f;
-          g_warning ("no sunset data, using %02.2f", value);
+          value = g_settings_get_double (self->settings_display, "night-light-schedule-from");
+          value = fmod (value, 24.f);
         }
-    }
-  else
-    {
-      value = g_settings_get_double (self->settings_display, "night-light-schedule-from");
-      value = fmod (value, 24.f);
-    }
-  dialog_adjustments_set_frac_hours (self, value,
-                                     self->adjustment_from_hours,
-                                     self->adjustment_from_minutes,
-                                     self->stack_from,
-                                     self->button_from_am,
-                                     self->button_from_pm);
-
-  /* set to */
-  if (automatic && self->proxy_color != NULL)
-    {
-      g_autoptr(GVariant) sunset = NULL;
-      sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunrise");
-      if (sunset != NULL)
+      dialog_adjustments_set_frac_hours (self, value,
+                                         self->adjustment_from_hours,
+                                         self->adjustment_from_minutes,
+                                         self->stack_from,
+                                         self->button_from_am,
+                                         self->button_from_pm);
+
+      /* set to */
+      if (automatic && self->proxy_color != NULL)
         {
-          value = g_variant_get_double (sunset);
+          g_autoptr(GVariant) sunset = NULL;
+          sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunrise");
+          if (sunset != NULL)
+            {
+              value = g_variant_get_double (sunset);
+            }
+          else
+            {
+              value = 8.0f;
+              g_warning ("no sunrise data, using %02.2f", value);
+            }
         }
       else
         {
-          value = 8.0f;
-          g_warning ("no sunrise data, using %02.2f", value);
+          value = g_settings_get_double (self->settings_display, "night-light-schedule-to");
+          value = fmod (value, 24.f);
         }
+      dialog_adjustments_set_frac_hours (self, value,
+                                         self->adjustment_to_hours,
+                                         self->adjustment_to_minutes,
+                                         self->stack_to,
+                                         self->button_to_am,
+                                         self->button_to_pm);
+
+      self->ignore_value_changed = TRUE;
+      value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
+      gtk_adjustment_set_value (self->adjustment_color_temperature, value);
+      self->ignore_value_changed = FALSE;
     }
   else
     {
-      value = g_settings_get_double (self->settings_display, "night-light-schedule-to");
-      value = fmod (value, 24.f);
+      gtk_widget_set_visible (self->infobar_unsupported, TRUE);
+      gtk_widget_set_visible (self->infobar_disabled, FALSE);
+      gtk_widget_set_sensitive (self->night_light_settings, FALSE);
     }
-  dialog_adjustments_set_frac_hours (self, value,
-                                     self->adjustment_to_hours,
-                                     self->adjustment_to_minutes,
-                                     self->stack_to,
-                                     self->button_to_am,
-                                     self->button_to_pm);
-
-  self->ignore_value_changed = TRUE;
-  value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
-  gtk_adjustment_set_value (self->adjustment_color_temperature, value);
-  self->ignore_value_changed = FALSE;
 }
 
 static void
@@ -549,6 +563,13 @@ dialog_am_pm_to_button_clicked_cb (GtkButton        *button,
   g_debug ("new value = %.3f", value);
 }
 
+static void
+config_manager_changed_cb (CcDisplayConfigManager *config_manager,
+                           CcNightLightPage       *self)
+{
+  dialog_update_state (self);
+}
+
 /* GObject overrides */
 static void
 cc_night_light_page_finalize (GObject *object)
@@ -583,11 +604,13 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_hours);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_minutes);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_color_temperature);
+  gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_settings);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_manual);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_am);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_pm);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm);
+  gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_unsupported);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch);
@@ -700,6 +723,10 @@ cc_night_light_page_init (CcNightLightPage *self)
                            G_CALLBACK (dialog_clock_settings_changed_cb),
                            self, G_CONNECT_SWAPPED);
 
+  self->config_manager = cc_display_config_manager_dbus_new ();
+  g_signal_connect (self->config_manager, "changed",
+                    G_CALLBACK (config_manager_changed_cb), self);
+
   dialog_update_state (self);
 }
 
diff --git a/panels/display/cc-night-light-page.ui b/panels/display/cc-night-light-page.ui
index 02b14f731..cb18837ad 100644
--- a/panels/display/cc-night-light-page.ui
+++ b/panels/display/cc-night-light-page.ui
@@ -6,9 +6,45 @@
       <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="halign">center</property>
         <property name="valign">start</property>
         <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkInfoBar" id="infobar_unsupported">
+            <property name="visible">False</property>
+            <property name="name">infobar_unsupported</property>
+            <property name="message-type">warning</property>
+            <child internal-child="content_area">
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="hexpand">True</property>
+                <property name="spacing">16</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="halign">start</property>
+                    <property name="margin-start">6</property>
+                    <property name="hexpand">False</property>
+                    <property name="label" translatable="yes">Night Light unavailable</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="halign">start</property>
+                    <property name="margin-start">6</property>
+                    <property name="hexpand">False</property>
+                    <property name="label" translatable="yes">This could be the result of the graphics driver being used, or the desktop being used remotely</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+
         <child>
           <object class="GtkInfoBar" id="infobar_disabled">
             <property name="name">infobar_disabled</property>
@@ -70,8 +106,9 @@
         </child>
 
         <child>
-          <object class="GtkBox">
+          <object class="GtkBox" id="night_light_settings">
             <property name="visible">True</property>
+            <property name="halign">center</property>
             <property name="can_focus">False</property>
             <property name="margin_top">30</property>
             <property name="margin_end">12</property>
-- 
2.34.1