[gnome-flashback] monitor-manager: add NightLightSupported property to DisplayConfig



commit 3a7c1c166e91ab09b9cbb58342b7548b84c1b1dc
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Aug 13 16:09:27 2022 +0300

    monitor-manager: add NightLightSupported property to DisplayConfig
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/8fdb80a7180203a53685

 backends/gf-monitor-manager-xrandr.c        | 15 ++++--
 backends/gf-monitor-manager.c               | 84 ++++++++++++++++++++++++-----
 backends/org.gnome.Mutter.DisplayConfig.xml |  7 +++
 3 files changed, 90 insertions(+), 16 deletions(-)
---
diff --git a/backends/gf-monitor-manager-xrandr.c b/backends/gf-monitor-manager-xrandr.c
index eece357..9786852 100644
--- a/backends/gf-monitor-manager-xrandr.c
+++ b/backends/gf-monitor-manager-xrandr.c
@@ -831,10 +831,17 @@ gf_monitor_manager_xrandr_get_crtc_gamma (GfMonitorManager  *manager,
   xrandr = GF_MONITOR_MANAGER_XRANDR (manager);
   gamma = XRRGetCrtcGamma (xrandr->xdisplay, (XID) gf_crtc_get_id (crtc));
 
-  *size = gamma->size;
-  *red = g_memdup2 (gamma->red, sizeof (gushort) * gamma->size);
-  *green = g_memdup2 (gamma->green, sizeof (gushort) * gamma->size);
-  *blue = g_memdup2 (gamma->blue, sizeof (gushort) * gamma->size);
+  if (size)
+    *size = gamma->size;
+
+  if (red)
+    *red = g_memdup2 (gamma->red, sizeof (gushort) * gamma->size);
+
+  if (green)
+    *green = g_memdup2 (gamma->green, sizeof (gushort) * gamma->size);
+
+  if (blue)
+    *blue = g_memdup2 (gamma->blue, sizeof (gushort) * gamma->size);
 
   XRRFreeGamma (gamma);
 }
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index eb558db..75cf43c 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -1298,6 +1298,71 @@ combine_gpu_lists (GfMonitorManager *manager,
   return list;
 }
 
+static void
+gf_monitor_manager_get_crtc_gamma (GfMonitorManager  *self,
+                                   GfCrtc            *crtc,
+                                   gsize             *size,
+                                   gushort          **red,
+                                   gushort          **green,
+                                   gushort          **blue)
+{
+  GfMonitorManagerClass *manager_class;
+
+  manager_class = GF_MONITOR_MANAGER_GET_CLASS (self);
+
+  if (manager_class->get_crtc_gamma)
+    {
+      manager_class->get_crtc_gamma (self, crtc, size, red, green, blue);
+    }
+  else
+    {
+      if (size)
+        *size = 0;
+
+      if (red)
+        *red = NULL;
+
+      if (green)
+        *green = NULL;
+
+      if (blue)
+        *blue = NULL;
+    }
+}
+
+static gboolean
+is_night_light_supported (GfMonitorManager *self)
+{
+  GfMonitorManagerPrivate *priv;
+  GList *l;
+
+  priv = gf_monitor_manager_get_instance_private (self);
+
+  for (l = gf_backend_get_gpus (priv->backend); l; l = l->next)
+    {
+      GfGpu *gpu = l->data;
+      GList *l_crtc;
+
+      for (l_crtc = gf_gpu_get_crtcs (gpu); l_crtc; l_crtc = l_crtc->next)
+        {
+          GfCrtc *crtc = l_crtc->data;
+          size_t gamma_lut_size;
+
+          gf_monitor_manager_get_crtc_gamma (self,
+                                             crtc,
+                                             &gamma_lut_size,
+                                             NULL,
+                                             NULL,
+                                             NULL);
+
+          if (gamma_lut_size > 0)
+            return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
 static gboolean
 gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig   *skeleton,
                                          GDBusMethodInvocation *invocation,
@@ -1624,7 +1689,6 @@ gf_monitor_manager_handle_get_crtc_gamma (GfDBusDisplayConfig   *skeleton,
                                           guint                  crtc_id,
                                           GfMonitorManager      *manager)
 {
-  GfMonitorManagerClass *manager_class;
   GList *combined_crtcs;
   GfCrtc *crtc;
   gsize size;
@@ -1638,8 +1702,6 @@ gf_monitor_manager_handle_get_crtc_gamma (GfDBusDisplayConfig   *skeleton,
   GVariant *green_v;
   GVariant *blue_v;
 
-  manager_class = GF_MONITOR_MANAGER_GET_CLASS (manager);
-
   if (serial != manager->serial)
     {
       g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
@@ -1662,15 +1724,7 @@ gf_monitor_manager_handle_get_crtc_gamma (GfDBusDisplayConfig   *skeleton,
   crtc = g_list_nth_data (combined_crtcs, crtc_id);
   g_list_free (combined_crtcs);
 
-  if (manager_class->get_crtc_gamma)
-    {
-      manager_class->get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
-    }
-  else
-    {
-      size = 0;
-      red = green = blue = NULL;
-    }
+  gf_monitor_manager_get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
 
   red_bytes = g_bytes_new_take (red, size * sizeof (gushort));
   green_bytes = g_bytes_new_take (green, size * sizeof (gushort));
@@ -2558,6 +2612,7 @@ gf_monitor_manager_setup (GfMonitorManager *manager)
   GfMonitorManagerClass *manager_class;
   GfMonitorConfigStore *config_store;
   const GfMonitorConfigPolicy *policy;
+  gboolean night_light_supported;
 
   manager_class = GF_MONITOR_MANAGER_GET_CLASS (manager);
 
@@ -2574,6 +2629,11 @@ gf_monitor_manager_setup (GfMonitorManager *manager)
   gf_dbus_display_config_set_apply_monitors_config_allowed (manager->display_config,
                                                             policy->enable_dbus);
 
+  night_light_supported = is_night_light_supported (manager);
+
+  gf_dbus_display_config_set_night_light_supported (manager->display_config,
+                                                    night_light_supported);
+
   manager->in_init = FALSE;
 }
 
diff --git a/backends/org.gnome.Mutter.DisplayConfig.xml b/backends/org.gnome.Mutter.DisplayConfig.xml
index 33dcbd6..1f3b7a4 100644
--- a/backends/org.gnome.Mutter.DisplayConfig.xml
+++ b/backends/org.gnome.Mutter.DisplayConfig.xml
@@ -238,6 +238,13 @@
     -->
     <property name="ApplyMonitorsConfigAllowed" type="b" access="read" />
 
+    <!--
+        NightLightSupported:
+
+        Whether night light is supported by this system.
+    -->
+    <property name="NightLightSupported" type="b" access="read" />
+
     <!--
         MonitorsChanged:
 


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