[gnome-settings-daemon/benzea/hide-brightness-if-builtin-disable] power: Define brightness to be -1 if builtin display is disabled



commit 6d3f370cd6ba712bab034e9cc145770fe3f91090
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Sep 28 16:02:22 2018 +0200

    power: Define brightness to be -1 if builtin display is disabled
    
    When the builtin display is disabled, then we don't want to show the
    controls for the backlight. We can detect the case by checking that no
    CRTC has been assigned to the output.
    
    Fixes #81

 plugins/power/gsd-backlight.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
---
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c
index 2159f429..be04e90e 100644
--- a/plugins/power/gsd-backlight.c
+++ b/plugins/power/gsd-backlight.c
@@ -50,6 +50,7 @@ struct _GsdBacklight
 #endif
 
         GnomeRRScreen *rr_screen;
+        gboolean builtin_display_disabled;
 };
 
 enum {
@@ -435,11 +436,17 @@ out:
  * of the async brightness setter. This happens when another set operation was
  * queued after it was already running.
  *
- * Returns: The last stable backlight value.
+ * If the internal display is detected as disabled, then the function will
+ * instead return -1.
+ *
+ * Returns: The last stable backlight value or -1 if the internal display is disabled.
  **/
 gint
 gsd_backlight_get_brightness (GsdBacklight *backlight, gint *target)
 {
+        if (backlight->builtin_display_disabled)
+                return -1;
+
         if (target)
                 *target = ABS_TO_PERCENTAGE (backlight->brightness_min, backlight->brightness_max, 
backlight->brightness_target);
 
@@ -660,6 +667,29 @@ gsd_backlight_get_output_id (GsdBacklight *backlight)
         return gnome_rr_output_get_id (output);
 }
 
+static void
+gsd_backlight_rr_screen_changed_cb (GnomeRRScreen *screen,
+                                    gpointer data)
+{
+        GsdBacklight *backlight = GSD_BACKLIGHT (data);
+        GnomeRROutput *output;
+        gboolean builtin_display_disabled = FALSE;
+
+        /* NOTE: Err on the side of assuming the backlight controlls something
+         *       even if we cannot find the output that belongs to it.
+         *       This might backfire on us obviously if the hardware claims it
+         *       can control a non-existing screen.
+         */
+        output = gsd_backlight_rr_find_output (backlight, FALSE);
+        if (output)
+                builtin_display_disabled = !gnome_rr_output_get_crtc (output);
+
+        if (builtin_display_disabled != backlight->builtin_display_disabled) {
+                backlight->builtin_display_disabled = builtin_display_disabled;
+                g_object_notify_by_pspec (G_OBJECT (backlight), props[PROP_BRIGHTNESS]);
+        }
+}
+
 static void
 gsd_backlight_get_property (GObject    *object,
                             guint       prop_id,
@@ -694,6 +724,12 @@ gsd_backlight_set_property (GObject      *object,
         switch (prop_id) {
         case PROP_RR_SCREEN:
                 backlight->rr_screen = g_value_dup_object (value);
+
+                g_signal_connect_object (backlight->rr_screen, "changed",
+                                         G_CALLBACK (gsd_backlight_rr_screen_changed_cb),
+                                         object, 0);
+                gsd_backlight_rr_screen_changed_cb (backlight->rr_screen, object);
+
                 break;
 
         default:


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