Blame SOURCES/display-infobar-if-night-light-unsupported.patch

0a6c47
From c999bade4d27e0384b6495ee3bbf88df1b9e256b Mon Sep 17 00:00:00 2001
0a6c47
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
0a6c47
Date: Thu, 24 Feb 2022 12:30:23 +0100
0a6c47
Subject: [PATCH 1/2] display: Add 'NightLightSupported' property support
0a6c47
0a6c47
---
0a6c47
 panels/display/cc-display-config-manager-dbus.c | 17 +++++++++++++++++
0a6c47
 panels/display/cc-display-config-manager.c      |  6 ++++++
0a6c47
 panels/display/cc-display-config-manager.h      |  3 +++
0a6c47
 3 files changed, 26 insertions(+)
0a6c47
0a6c47
diff --git a/panels/display/cc-display-config-manager-dbus.c b/panels/display/cc-display-config-manager-dbus.c
0a6c47
index 392140101..678b696db 100644
0a6c47
--- a/panels/display/cc-display-config-manager-dbus.c
0a6c47
+++ b/panels/display/cc-display-config-manager-dbus.c
0a6c47
@@ -33,6 +33,7 @@ struct _CcDisplayConfigManagerDBus
0a6c47
   GVariant *current_state;
0a6c47
 
0a6c47
   gboolean apply_allowed;
0a6c47
+  gboolean night_light_supported;
0a6c47
 };
0a6c47
 
0a6c47
 G_DEFINE_TYPE (CcDisplayConfigManagerDBus,
0a6c47
@@ -169,6 +170,12 @@ bus_gotten (GObject      *object,
0a6c47
   else
0a6c47
     g_warning ("Missing property 'ApplyMonitorsConfigAllowed' on DisplayConfig API");
0a6c47
 
0a6c47
+  variant = g_dbus_proxy_get_cached_property (proxy, "NightLightSupported");
0a6c47
+  if (variant)
0a6c47
+    self->night_light_supported = g_variant_get_boolean (variant);
0a6c47
+  else
0a6c47
+    g_warning ("Missing property 'NightLightSupported' on DisplayConfig API");
0a6c47
+
0a6c47
   get_current_state (self);
0a6c47
 }
0a6c47
 
0a6c47
@@ -176,6 +183,7 @@ static void
0a6c47
 cc_display_config_manager_dbus_init (CcDisplayConfigManagerDBus *self)
0a6c47
 {
0a6c47
   self->apply_allowed = TRUE;
0a6c47
+  self->night_light_supported = TRUE;
0a6c47
   self->cancellable = g_cancellable_new ();
0a6c47
   g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, bus_gotten, self);
0a6c47
 }
0a6c47
@@ -205,6 +213,14 @@ cc_display_config_manager_dbus_get_apply_allowed (CcDisplayConfigManager *pself)
0a6c47
   return self->apply_allowed;
0a6c47
 }
0a6c47
 
0a6c47
+static gboolean
0a6c47
+cc_display_config_manager_dbus_get_night_light_supported (CcDisplayConfigManager *pself)
0a6c47
+{
0a6c47
+  CcDisplayConfigManagerDBus *self = CC_DISPLAY_CONFIG_MANAGER_DBUS (pself);
0a6c47
+
0a6c47
+  return self->night_light_supported;
0a6c47
+}
0a6c47
+
0a6c47
 static void
0a6c47
 cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klass)
0a6c47
 {
0a6c47
@@ -215,6 +231,7 @@ cc_display_config_manager_dbus_class_init (CcDisplayConfigManagerDBusClass *klas
0a6c47
 
0a6c47
   parent_class->get_current = cc_display_config_manager_dbus_get_current;
0a6c47
   parent_class->get_apply_allowed = cc_display_config_manager_dbus_get_apply_allowed;
0a6c47
+  parent_class->get_night_light_supported = cc_display_config_manager_dbus_get_night_light_supported;
0a6c47
 }
0a6c47
 
0a6c47
 CcDisplayConfigManager *
0a6c47
diff --git a/panels/display/cc-display-config-manager.c b/panels/display/cc-display-config-manager.c
0a6c47
index 3d683c53d..f231edd69 100644
0a6c47
--- a/panels/display/cc-display-config-manager.c
0a6c47
+++ b/panels/display/cc-display-config-manager.c
0a6c47
@@ -65,3 +65,9 @@ cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self)
0a6c47
 {
0a6c47
   return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_apply_allowed (self);
0a6c47
 }
0a6c47
+
0a6c47
+gboolean
0a6c47
+cc_display_config_manager_get_night_light_supported (CcDisplayConfigManager *self)
0a6c47
+{
0a6c47
+  return CC_DISPLAY_CONFIG_MANAGER_GET_CLASS (self)->get_night_light_supported (self);
0a6c47
+}
0a6c47
diff --git a/panels/display/cc-display-config-manager.h b/panels/display/cc-display-config-manager.h
0a6c47
index 64f0775e9..ab1e84f85 100644
0a6c47
--- a/panels/display/cc-display-config-manager.h
0a6c47
+++ b/panels/display/cc-display-config-manager.h
0a6c47
@@ -35,12 +35,15 @@ struct _CcDisplayConfigManagerClass
0a6c47
 
0a6c47
   CcDisplayConfig * (*get_current) (CcDisplayConfigManager *self);
0a6c47
   gboolean (* get_apply_allowed) (CcDisplayConfigManager *self);
0a6c47
+  gboolean (* get_night_light_supported) (CcDisplayConfigManager *self);
0a6c47
 };
0a6c47
 
0a6c47
 CcDisplayConfig * cc_display_config_manager_get_current (CcDisplayConfigManager *self);
0a6c47
 
0a6c47
 gboolean cc_display_config_manager_get_apply_allowed (CcDisplayConfigManager *self);
0a6c47
 
0a6c47
+gboolean cc_display_config_manager_get_night_light_supported (CcDisplayConfigManager *self);
0a6c47
+
0a6c47
 void _cc_display_config_manager_emit_changed (CcDisplayConfigManager *self);
0a6c47
 
0a6c47
 G_END_DECLS
0a6c47
-- 
0a6c47
2.34.1
0a6c47
0a6c47
0a6c47
From 414e23272f89198efc452a4f8d50442c72a07956 Mon Sep 17 00:00:00 2001
0a6c47
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
0a6c47
Date: Thu, 24 Feb 2022 12:31:00 +0100
0a6c47
Subject: [PATCH 2/2] display: Show infobar if night light isn't supported
0a6c47
0a6c47
This may be the case on e.g. fully remote / headless sessions, or as of
0a6c47
now, when using the NVIDIA driver to run a Wayland session.
0a6c47
0a6c47
Closes: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1659
0a6c47
---
0a6c47
 panels/display/cc-night-light-page.c  | 153 +++++++++++++++-----------
0a6c47
 panels/display/cc-night-light-page.ui |  41 ++++++-
0a6c47
 2 files changed, 129 insertions(+), 65 deletions(-)
0a6c47
0a6c47
diff --git a/panels/display/cc-night-light-page.c b/panels/display/cc-night-light-page.c
0a6c47
index f51b0ba69..482b90fea 100644
0a6c47
--- a/panels/display/cc-night-light-page.c
0a6c47
+++ b/panels/display/cc-night-light-page.c
0a6c47
@@ -29,15 +29,18 @@
0a6c47
 #include "list-box-helper.h"
0a6c47
 
0a6c47
 #include "shell/cc-object-storage.h"
0a6c47
+#include "cc-display-config-manager-dbus.h"
0a6c47
 
0a6c47
 struct _CcNightLightPage {
0a6c47
   GtkBin               parent;
0a6c47
 
0a6c47
+  GtkWidget           *night_light_settings;
0a6c47
   GtkWidget           *box_manual;
0a6c47
   GtkButton           *button_from_am;
0a6c47
   GtkButton           *button_from_pm;
0a6c47
   GtkButton           *button_to_am;
0a6c47
   GtkButton           *button_to_pm;
0a6c47
+  GtkWidget           *infobar_unsupported;
0a6c47
   GtkWidget           *infobar_disabled;
0a6c47
   GtkListBox          *listbox;
0a6c47
   GtkWidget           *scale_color_temperature;
0a6c47
@@ -64,6 +67,8 @@ struct _CcNightLightPage {
0a6c47
   gboolean             ignore_value_changed;
0a6c47
   guint                timer_id;
0a6c47
   GDesktopClockFormat  clock_format;
0a6c47
+
0a6c47
+  CcDisplayConfigManager *config_manager;
0a6c47
 };
0a6c47
 
0a6c47
 G_DEFINE_TYPE (CcNightLightPage, cc_night_light_page, GTK_TYPE_BIN);
0a6c47
@@ -122,88 +127,97 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self,
0a6c47
 static void
0a6c47
 dialog_update_state (CcNightLightPage *self)
0a6c47
 {
0a6c47
-  gboolean automatic;
0a6c47
-  gboolean disabled_until_tomorrow = FALSE;
0a6c47
-  gboolean enabled;
0a6c47
-  gdouble value = 0.f;
0a6c47
-
0a6c47
-  /* only show the infobar if we are disabled */
0a6c47
-  if (self->proxy_color != NULL)
0a6c47
+  if (cc_display_config_manager_get_night_light_supported (self->config_manager))
0a6c47
     {
0a6c47
-      g_autoptr(GVariant) disabled = NULL;
0a6c47
-      disabled = g_dbus_proxy_get_cached_property (self->proxy_color,
0a6c47
-                                                   "DisabledUntilTomorrow");
0a6c47
-      if (disabled != NULL)
0a6c47
-        disabled_until_tomorrow = g_variant_get_boolean (disabled);
0a6c47
-    }
0a6c47
-  gtk_widget_set_visible (self->infobar_disabled, disabled_until_tomorrow);
0a6c47
+      gboolean automatic;
0a6c47
+      gboolean disabled_until_tomorrow = FALSE;
0a6c47
+      gboolean enabled;
0a6c47
+      gdouble value = 0.f;
0a6c47
 
0a6c47
-  /* make things insensitive if the switch is disabled */
0a6c47
-  enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
0a6c47
-  automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
0a6c47
+      /* only show the infobar if we are disabled */
0a6c47
+      if (self->proxy_color != NULL)
0a6c47
+        {
0a6c47
+          g_autoptr(GVariant) disabled = NULL;
0a6c47
+          disabled = g_dbus_proxy_get_cached_property (self->proxy_color,
0a6c47
+                                                       "DisabledUntilTomorrow");
0a6c47
+          if (disabled != NULL)
0a6c47
+            disabled_until_tomorrow = g_variant_get_boolean (disabled);
0a6c47
+        }
0a6c47
+      gtk_widget_set_visible (self->infobar_disabled, disabled_until_tomorrow);
0a6c47
 
0a6c47
-  gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
0a6c47
+      /* make things insensitive if the switch is disabled */
0a6c47
+      enabled = g_settings_get_boolean (self->settings_display, "night-light-enabled");
0a6c47
+      automatic = g_settings_get_boolean (self->settings_display, "night-light-schedule-automatic");
0a6c47
 
0a6c47
-  gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
0a6c47
+      gtk_widget_set_sensitive (self->box_manual, enabled && !automatic);
0a6c47
 
0a6c47
-  /* set from */
0a6c47
-  if (automatic && self->proxy_color != NULL)
0a6c47
-    {
0a6c47
-      g_autoptr(GVariant) sunset = NULL;
0a6c47
-      sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunset");
0a6c47
-      if (sunset != NULL)
0a6c47
+      gtk_combo_box_set_active_id (self->schedule_type_combo, automatic ? "automatic" : "manual");
0a6c47
+
0a6c47
+      /* set from */
0a6c47
+      if (automatic && self->proxy_color != NULL)
0a6c47
         {
0a6c47
-          value = g_variant_get_double (sunset);
0a6c47
+          g_autoptr(GVariant) sunset = NULL;
0a6c47
+          sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunset");
0a6c47
+          if (sunset != NULL)
0a6c47
+            {
0a6c47
+              value = g_variant_get_double (sunset);
0a6c47
+            }
0a6c47
+          else
0a6c47
+            {
0a6c47
+              value = 16.0f;
0a6c47
+              g_warning ("no sunset data, using %02.2f", value);
0a6c47
+            }
0a6c47
         }
0a6c47
       else
0a6c47
         {
0a6c47
-          value = 16.0f;
0a6c47
-          g_warning ("no sunset data, using %02.2f", value);
0a6c47
+          value = g_settings_get_double (self->settings_display, "night-light-schedule-from");
0a6c47
+          value = fmod (value, 24.f);
0a6c47
         }
0a6c47
-    }
0a6c47
-  else
0a6c47
-    {
0a6c47
-      value = g_settings_get_double (self->settings_display, "night-light-schedule-from");
0a6c47
-      value = fmod (value, 24.f);
0a6c47
-    }
0a6c47
-  dialog_adjustments_set_frac_hours (self, value,
0a6c47
-                                     self->adjustment_from_hours,
0a6c47
-                                     self->adjustment_from_minutes,
0a6c47
-                                     self->stack_from,
0a6c47
-                                     self->button_from_am,
0a6c47
-                                     self->button_from_pm);
0a6c47
-
0a6c47
-  /* set to */
0a6c47
-  if (automatic && self->proxy_color != NULL)
0a6c47
-    {
0a6c47
-      g_autoptr(GVariant) sunset = NULL;
0a6c47
-      sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunrise");
0a6c47
-      if (sunset != NULL)
0a6c47
+      dialog_adjustments_set_frac_hours (self, value,
0a6c47
+                                         self->adjustment_from_hours,
0a6c47
+                                         self->adjustment_from_minutes,
0a6c47
+                                         self->stack_from,
0a6c47
+                                         self->button_from_am,
0a6c47
+                                         self->button_from_pm);
0a6c47
+
0a6c47
+      /* set to */
0a6c47
+      if (automatic && self->proxy_color != NULL)
0a6c47
         {
0a6c47
-          value = g_variant_get_double (sunset);
0a6c47
+          g_autoptr(GVariant) sunset = NULL;
0a6c47
+          sunset = g_dbus_proxy_get_cached_property (self->proxy_color, "Sunrise");
0a6c47
+          if (sunset != NULL)
0a6c47
+            {
0a6c47
+              value = g_variant_get_double (sunset);
0a6c47
+            }
0a6c47
+          else
0a6c47
+            {
0a6c47
+              value = 8.0f;
0a6c47
+              g_warning ("no sunrise data, using %02.2f", value);
0a6c47
+            }
0a6c47
         }
0a6c47
       else
0a6c47
         {
0a6c47
-          value = 8.0f;
0a6c47
-          g_warning ("no sunrise data, using %02.2f", value);
0a6c47
+          value = g_settings_get_double (self->settings_display, "night-light-schedule-to");
0a6c47
+          value = fmod (value, 24.f);
0a6c47
         }
0a6c47
+      dialog_adjustments_set_frac_hours (self, value,
0a6c47
+                                         self->adjustment_to_hours,
0a6c47
+                                         self->adjustment_to_minutes,
0a6c47
+                                         self->stack_to,
0a6c47
+                                         self->button_to_am,
0a6c47
+                                         self->button_to_pm);
0a6c47
+
0a6c47
+      self->ignore_value_changed = TRUE;
0a6c47
+      value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
0a6c47
+      gtk_adjustment_set_value (self->adjustment_color_temperature, value);
0a6c47
+      self->ignore_value_changed = FALSE;
0a6c47
     }
0a6c47
   else
0a6c47
     {
0a6c47
-      value = g_settings_get_double (self->settings_display, "night-light-schedule-to");
0a6c47
-      value = fmod (value, 24.f);
0a6c47
+      gtk_widget_set_visible (self->infobar_unsupported, TRUE);
0a6c47
+      gtk_widget_set_visible (self->infobar_disabled, FALSE);
0a6c47
+      gtk_widget_set_sensitive (self->night_light_settings, FALSE);
0a6c47
     }
0a6c47
-  dialog_adjustments_set_frac_hours (self, value,
0a6c47
-                                     self->adjustment_to_hours,
0a6c47
-                                     self->adjustment_to_minutes,
0a6c47
-                                     self->stack_to,
0a6c47
-                                     self->button_to_am,
0a6c47
-                                     self->button_to_pm);
0a6c47
-
0a6c47
-  self->ignore_value_changed = TRUE;
0a6c47
-  value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
0a6c47
-  gtk_adjustment_set_value (self->adjustment_color_temperature, value);
0a6c47
-  self->ignore_value_changed = FALSE;
0a6c47
 }
0a6c47
 
0a6c47
 static void
0a6c47
@@ -549,6 +563,13 @@ dialog_am_pm_to_button_clicked_cb (GtkButton        *button,
0a6c47
   g_debug ("new value = %.3f", value);
0a6c47
 }
0a6c47
 
0a6c47
+static void
0a6c47
+config_manager_changed_cb (CcDisplayConfigManager *config_manager,
0a6c47
+                           CcNightLightPage       *self)
0a6c47
+{
0a6c47
+  dialog_update_state (self);
0a6c47
+}
0a6c47
+
0a6c47
 /* GObject overrides */
0a6c47
 static void
0a6c47
 cc_night_light_page_finalize (GObject *object)
0a6c47
@@ -583,11 +604,13 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_hours);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_minutes);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_color_temperature);
0a6c47
+  gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_settings);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_manual);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_am);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_pm);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm);
0a6c47
+  gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_unsupported);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox);
0a6c47
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch);
0a6c47
@@ -700,6 +723,10 @@ cc_night_light_page_init (CcNightLightPage *self)
0a6c47
                            G_CALLBACK (dialog_clock_settings_changed_cb),
0a6c47
                            self, G_CONNECT_SWAPPED);
0a6c47
 
0a6c47
+  self->config_manager = cc_display_config_manager_dbus_new ();
0a6c47
+  g_signal_connect (self->config_manager, "changed",
0a6c47
+                    G_CALLBACK (config_manager_changed_cb), self);
0a6c47
+
0a6c47
   dialog_update_state (self);
0a6c47
 }
0a6c47
 
0a6c47
diff --git a/panels/display/cc-night-light-page.ui b/panels/display/cc-night-light-page.ui
0a6c47
index 02b14f731..cb18837ad 100644
0a6c47
--- a/panels/display/cc-night-light-page.ui
0a6c47
+++ b/panels/display/cc-night-light-page.ui
0a6c47
@@ -6,9 +6,45 @@
0a6c47
       <object class="GtkBox">
0a6c47
         <property name="visible">True</property>
0a6c47
         <property name="can_focus">False</property>
0a6c47
-        <property name="halign">center</property>
0a6c47
         <property name="valign">start</property>
0a6c47
         <property name="orientation">vertical</property>
0a6c47
+        <child>
0a6c47
+          <object class="GtkInfoBar" id="infobar_unsupported">
0a6c47
+            <property name="visible">False</property>
0a6c47
+            <property name="name">infobar_unsupported</property>
0a6c47
+            <property name="message-type">warning</property>
0a6c47
+            <child internal-child="content_area">
0a6c47
+              <object class="GtkBox">
0a6c47
+                <property name="visible">True</property>
0a6c47
+                <property name="orientation">vertical</property>
0a6c47
+                <property name="hexpand">True</property>
0a6c47
+                <property name="spacing">16</property>
0a6c47
+                <child>
0a6c47
+                  <object class="GtkLabel">
0a6c47
+                    <property name="visible">True</property>
0a6c47
+                    <property name="halign">start</property>
0a6c47
+                    <property name="margin-start">6</property>
0a6c47
+                    <property name="hexpand">False</property>
0a6c47
+                    <property name="label" translatable="yes">Night Light unavailable</property>
0a6c47
+                    <attributes>
0a6c47
+                      <attribute name="weight" value="bold"/>
0a6c47
+                    </attributes>
0a6c47
+                  </object>
0a6c47
+                </child>
0a6c47
+                <child>
0a6c47
+                  <object class="GtkLabel">
0a6c47
+                    <property name="visible">True</property>
0a6c47
+                    <property name="halign">start</property>
0a6c47
+                    <property name="margin-start">6</property>
0a6c47
+                    <property name="hexpand">False</property>
0a6c47
+                    <property name="label" translatable="yes">This could be the result of the graphics driver being used, or the desktop being used remotely</property>
0a6c47
+                  </object>
0a6c47
+                </child>
0a6c47
+              </object>
0a6c47
+            </child>
0a6c47
+          </object>
0a6c47
+        </child>
0a6c47
+
0a6c47
         <child>
0a6c47
           <object class="GtkInfoBar" id="infobar_disabled">
0a6c47
             <property name="name">infobar_disabled</property>
0a6c47
@@ -70,8 +106,9 @@
0a6c47
         </child>
0a6c47
 
0a6c47
         <child>
0a6c47
-          <object class="GtkBox">
0a6c47
+          <object class="GtkBox" id="night_light_settings">
0a6c47
             <property name="visible">True</property>
0a6c47
+            <property name="halign">center</property>
0a6c47
             <property name="can_focus">False</property>
0a6c47
             <property name="margin_top">30</property>
0a6c47
             <property name="margin_end">12</property>
0a6c47
-- 
0a6c47
2.34.1
0a6c47