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

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