[mutter] color-manager: Keep track of temperature



commit 16149d7c2577c5aa0e8228fa0be9327a641cfa75
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Sat Dec 4 00:31:43 2021 +0100

    color-manager: Keep track of temperature
    
    It will be used to generate gamma look up tables depending on
    temperature.
    
    The temperature comes from org.gnome.SettingsDaemon.Color and
    depends on the current night light state.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2165>

 src/backends/meta-color-manager.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
---
diff --git a/src/backends/meta-color-manager.c b/src/backends/meta-color-manager.c
index face6abe2f..9ba58565bc 100644
--- a/src/backends/meta-color-manager.c
+++ b/src/backends/meta-color-manager.c
@@ -55,6 +55,8 @@
 #include "meta-dbus-gsd-color.h"
 #include "meta-dbus-gsd-power-screen.h"
 
+#define DEFAULT_TEMPERATURE 6500 /* Kelvin */
+
 enum
 {
   PROP_0,
@@ -83,6 +85,11 @@ typedef struct _MetaColorManagerPrivate
   MetaDbusSettingsDaemonPowerScreen *gsd_power_screen;
 
   gboolean is_ready;
+
+  /* The temperature (in Kelvin) adjustment to apply to the color LUTs;
+   * used to shift the screen towards red for Night Light.
+   */
+  unsigned int temperature;
 } MetaColorManagerPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (MetaColorManager, meta_color_manager, G_TYPE_OBJECT)
@@ -218,6 +225,28 @@ cd_client_connect_cb (GObject      *source_object,
   priv->is_ready = TRUE;
 }
 
+static void
+on_temperature_changed (MetaDbusSettingsDaemonColor *gsd_color,
+                        GParamSpec                  *pspec,
+                        MetaColorManager            *color_manager)
+{
+  MetaColorManagerPrivate *priv =
+    meta_color_manager_get_instance_private (color_manager);
+  unsigned int temperature;
+
+  temperature = meta_dbus_settings_daemon_color_get_temperature (gsd_color);
+  if (priv->temperature == temperature)
+    return;
+
+  if (temperature < 1000 || temperature > 10000)
+    {
+      g_warning ("Invalid temperature from gsd-color: %u K", temperature);
+      return;
+    }
+
+  priv->temperature = temperature;
+}
+
 static void
 on_gsd_color_ready (GObject      *source_object,
                     GAsyncResult *res,
@@ -243,6 +272,10 @@ on_gsd_color_ready (GObject      *source_object,
   meta_topic (META_DEBUG_COLOR,
               "Connection to org.gnome.SettingsDaemon.Color established");
   priv->gsd_color = gsd_color;
+
+  g_signal_connect (gsd_color, "notify::temperature",
+                    G_CALLBACK (on_temperature_changed),
+                    color_manager);
 }
 
 static void
@@ -283,6 +316,7 @@ meta_color_manager_constructed (GObject *object)
   priv->lcms_context = cmsCreateContext (NULL, NULL);
 
   priv->cancellable = g_cancellable_new ();
+  priv->temperature = DEFAULT_TEMPERATURE;
 
   priv->cd_client = cd_client_new ();
   cd_client_connect (priv->cd_client, priv->cancellable, cd_client_connect_cb,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]