Blob Blame History Raw
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