Blame SOURCES/0001-monitor-manager-Add-NightLightSupported-property-to-.patch

5c9faf
From f21c8614daeb70a021c128b97c000a92652cf6f8 Mon Sep 17 00:00:00 2001
5c9faf
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
5c9faf
Date: Thu, 24 Feb 2022 12:32:27 +0100
5c9faf
Subject: [PATCH] monitor-manager: Add NightLightSupported property to
5c9faf
 DisplayConfig
5c9faf
5c9faf
This checks whether it's possible to set a CRTC GAMMA_LUT, which is what
5c9faf
is necessary to implement night light.
5c9faf
---
5c9faf
 src/backends/meta-monitor-manager.c           | 76 ++++++++++++++++---
5c9faf
 .../native/meta-monitor-manager-native.c      | 25 ++++--
5c9faf
 .../x11/meta-monitor-manager-xrandr.c         |  9 ++-
5c9faf
 src/org.gnome.Mutter.DisplayConfig.xml        |  7 ++
5c9faf
 4 files changed, 99 insertions(+), 18 deletions(-)
5c9faf
5c9faf
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
5c9faf
index 75146950c3..0f30b3de25 100644
5c9faf
--- a/src/backends/meta-monitor-manager.c
5c9faf
+++ b/src/backends/meta-monitor-manager.c
5c9faf
@@ -952,6 +952,59 @@ update_panel_orientation_managed (MetaMonitorManager *manager)
5c9faf
     handle_orientation_change (orientation_manager, manager);
5c9faf
 }
5c9faf
 
5c9faf
+static void
5c9faf
+meta_monitor_manager_get_crtc_gamma (MetaMonitorManager  *manager,
5c9faf
+                                     MetaCrtc            *crtc,
5c9faf
+                                     size_t              *size,
5c9faf
+                                     unsigned short     **red,
5c9faf
+                                     unsigned short     **green,
5c9faf
+                                     unsigned short     **blue)
5c9faf
+{
5c9faf
+  MetaMonitorManagerClass *klass = META_MONITOR_MANAGER_GET_CLASS (manager);
5c9faf
+
5c9faf
+  if (klass->get_crtc_gamma)
5c9faf
+    {
5c9faf
+      klass->get_crtc_gamma (manager, crtc, size, red, green, blue);
5c9faf
+    }
5c9faf
+  else
5c9faf
+    {
5c9faf
+      if (size)
5c9faf
+        *size = 0;
5c9faf
+      if (red)
5c9faf
+        *red = NULL;
5c9faf
+      if (green)
5c9faf
+        *green = NULL;
5c9faf
+      if (blue)
5c9faf
+        *blue = NULL;
5c9faf
+    }
5c9faf
+}
5c9faf
+
5c9faf
+static gboolean
5c9faf
+is_night_light_supported (MetaMonitorManager *manager)
5c9faf
+{
5c9faf
+  GList *l;
5c9faf
+
5c9faf
+  for (l = meta_backend_get_gpus (manager->backend); l; l = l->next)
5c9faf
+    {
5c9faf
+      MetaGpu *gpu = l->data;
5c9faf
+      GList *l_crtc;
5c9faf
+
5c9faf
+      for (l_crtc = meta_gpu_get_crtcs (gpu); l_crtc; l_crtc = l_crtc->next)
5c9faf
+        {
5c9faf
+          MetaCrtc *crtc = l_crtc->data;
5c9faf
+          size_t gamma_lut_size;
5c9faf
+
5c9faf
+          meta_monitor_manager_get_crtc_gamma (manager, crtc,
5c9faf
+                                               &gamma_lut_size,
5c9faf
+                                               NULL, NULL, NULL);
5c9faf
+          if (gamma_lut_size > 0)
5c9faf
+            return TRUE;
5c9faf
+        }
5c9faf
+    }
5c9faf
+
5c9faf
+  return FALSE;
5c9faf
+}
5c9faf
+
5c9faf
 void
5c9faf
 meta_monitor_manager_setup (MetaMonitorManager *manager)
5c9faf
 {
5c9faf
@@ -967,7 +1020,6 @@ meta_monitor_manager_setup (MetaMonitorManager *manager)
5c9faf
   meta_dbus_display_config_set_apply_monitors_config_allowed (manager->display_config,
5c9faf
                                                               policy->enable_dbus);
5c9faf
 
5c9faf
-
5c9faf
   meta_monitor_manager_read_current_state (manager);
5c9faf
 
5c9faf
   meta_monitor_manager_ensure_initial_config (manager);
5c9faf
@@ -2445,7 +2497,6 @@ meta_monitor_manager_handle_get_crtc_gamma  (MetaDBusDisplayConfig *skeleton,
5c9faf
                                              guint                  crtc_id,
5c9faf
                                              MetaMonitorManager    *manager)
5c9faf
 {
5c9faf
-  MetaMonitorManagerClass *klass;
5c9faf
   GList *combined_crtcs;
5c9faf
   MetaCrtc *crtc;
5c9faf
   gsize size;
5c9faf
@@ -2476,14 +2527,8 @@ meta_monitor_manager_handle_get_crtc_gamma  (MetaDBusDisplayConfig *skeleton,
5c9faf
   crtc = g_list_nth_data (combined_crtcs, crtc_id);
5c9faf
   g_list_free (combined_crtcs);
5c9faf
 
5c9faf
-  klass = META_MONITOR_MANAGER_GET_CLASS (manager);
5c9faf
-  if (klass->get_crtc_gamma)
5c9faf
-    klass->get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
5c9faf
-  else
5c9faf
-    {
5c9faf
-      size = 0;
5c9faf
-      red = green = blue = NULL;
5c9faf
-    }
5c9faf
+  meta_monitor_manager_get_crtc_gamma (manager, crtc,
5c9faf
+                                       &size, &red, &green, &blue);
5c9faf
 
5c9faf
   red_bytes = g_bytes_new_take (red, size * sizeof (unsigned short));
5c9faf
   green_bytes = g_bytes_new_take (green, size * sizeof (unsigned short));
5c9faf
@@ -3078,6 +3123,16 @@ meta_monitor_manager_is_transform_handled (MetaMonitorManager  *manager,
5c9faf
   return manager_class->is_transform_handled (manager, crtc, transform);
5c9faf
 }
5c9faf
 
5c9faf
+static void
5c9faf
+update_night_light_supported (MetaMonitorManager *manager)
5c9faf
+{
5c9faf
+  gboolean night_light_supported;
5c9faf
+
5c9faf
+  night_light_supported = is_night_light_supported (manager);
5c9faf
+  meta_dbus_display_config_set_night_light_supported (manager->display_config,
5c9faf
+                                                      night_light_supported);
5c9faf
+}
5c9faf
+
5c9faf
 static void
5c9faf
 meta_monitor_manager_real_read_current_state (MetaMonitorManager *manager)
5c9faf
 {
5c9faf
@@ -3098,6 +3153,7 @@ meta_monitor_manager_real_read_current_state (MetaMonitorManager *manager)
5c9faf
     }
5c9faf
 
5c9faf
   rebuild_monitors (manager);
5c9faf
+  update_night_light_supported (manager);
5c9faf
 }
5c9faf
 
5c9faf
 void
5c9faf
diff --git a/src/backends/native/meta-monitor-manager-native.c b/src/backends/native/meta-monitor-manager-native.c
5c9faf
index fd5e7784ff..37a50f1d6f 100644
5c9faf
--- a/src/backends/native/meta-monitor-manager-native.c
5c9faf
+++ b/src/backends/native/meta-monitor-manager-native.c
5c9faf
@@ -381,15 +381,30 @@ meta_monitor_manager_native_get_crtc_gamma (MetaMonitorManager  *manager,
5c9faf
   MetaKmsCrtc *kms_crtc;
5c9faf
   const MetaKmsCrtcState *crtc_state;
5c9faf
 
5c9faf
-  g_return_if_fail (META_IS_CRTC_KMS (crtc));
5c9faf
+  if (!META_IS_CRTC_KMS (crtc))
5c9faf
+    {
5c9faf
+      if (size)
5c9faf
+        *size = 0;
5c9faf
+      if (red)
5c9faf
+        *red = NULL;
5c9faf
+      if (green)
5c9faf
+        *green = NULL;
5c9faf
+      if (blue)
5c9faf
+        *blue = NULL;
5c9faf
+      return;
5c9faf
+    }
5c9faf
 
5c9faf
   kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (crtc));
5c9faf
   crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
5c9faf
 
5c9faf
-  *size = crtc_state->gamma.size;
5c9faf
-  *red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
5c9faf
-  *green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
5c9faf
-  *blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
5c9faf
+  if (size)
5c9faf
+    *size = crtc_state->gamma.size;
5c9faf
+  if (red)
5c9faf
+    *red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
5c9faf
+  if (green)
5c9faf
+    *green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
5c9faf
+  if (blue)
5c9faf
+    *blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
5c9faf
 }
5c9faf
 
5c9faf
 static char *
5c9faf
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
5c9faf
index 98eb080b6b..865f4e5800 100644
5c9faf
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
5c9faf
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
5c9faf
@@ -707,9 +707,12 @@ meta_monitor_manager_xrandr_get_crtc_gamma (MetaMonitorManager  *manager,
5c9faf
                            (XID) meta_crtc_get_id (crtc));
5c9faf
 
5c9faf
   *size = gamma->size;
5c9faf
-  *red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
5c9faf
-  *green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
5c9faf
-  *blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
5c9faf
+  if (red)
5c9faf
+    *red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
5c9faf
+  if (green)
5c9faf
+    *green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
5c9faf
+  if (blue)
5c9faf
+    *blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
5c9faf
 
5c9faf
   XRRFreeGamma (gamma);
5c9faf
 }
5c9faf
diff --git a/src/org.gnome.Mutter.DisplayConfig.xml b/src/org.gnome.Mutter.DisplayConfig.xml
5c9faf
index c6859c2c09..5f85c5e271 100644
5c9faf
--- a/src/org.gnome.Mutter.DisplayConfig.xml
5c9faf
+++ b/src/org.gnome.Mutter.DisplayConfig.xml
5c9faf
@@ -297,6 +297,13 @@
5c9faf
     -->
5c9faf
     <property name="ApplyMonitorsConfigAllowed" type="b" access="read" />
5c9faf
 
5c9faf
+    
5c9faf
+        NightLightSupported:
5c9faf
+
5c9faf
+        Whether night light is supported by this system.
5c9faf
+    -->
5c9faf
+    <property name="NightLightSupported" type="b" access="read" />
5c9faf
+
5c9faf
     
5c9faf
         MonitorsChanged:
5c9faf
 
5c9faf
-- 
5c9faf
2.37.1
5c9faf