[Xfce4-commits] <xfce4-settings:bluesabre/display-settings> Restore failsafe to prevent disabling all outputs

Simon Steinbeiss noreply at xfce.org
Mon Oct 15 18:06:02 CEST 2012


Updating branch refs/heads/bluesabre/display-settings
         to 0dc07675830a6622d2600876f20359547fcf07b0 (commit)
       from 0da28cfdb461dd5ad9f4ef4d22d7431887e0339f (commit)

commit 0dc07675830a6622d2600876f20359547fcf07b0
Author: Lionel Le Folgoc <lionel at lefolgoc.net>
Date:   Mon Oct 15 17:12:07 2012 +0200

    Restore failsafe to prevent disabling all outputs
    
    Also improve a bit debugging messages.
    
    Signed-off-by: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>

 xfsettingsd/displays.c |   89 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 58 insertions(+), 31 deletions(-)

diff --git a/xfsettingsd/displays.c b/xfsettingsd/displays.c
index 9a7d441..4101135 100644
--- a/xfsettingsd/displays.c
+++ b/xfsettingsd/displays.c
@@ -234,6 +234,26 @@ xfce_displays_helper_list_crtcs (Display            *xdisplay,
 
 
 
+static XfceRRCrtc *
+xfce_displays_helper_find_crtc_by_id (XRRScreenResources *resources,
+                                      XfceRRCrtc         *crtcs,
+                                      RRCrtc              id)
+{
+    gint n;
+
+    g_assert (resources && crtcs);
+
+    for (n = 0; n < resources->ncrtc; ++n)
+    {
+        if (crtcs[n].id == id)
+            return &crtcs[n];
+    }
+
+    return NULL;
+}
+
+
+
 static void
 xfce_displays_helper_cleanup_crtc (XfceRRCrtc *crtc)
 {
@@ -262,18 +282,22 @@ xfce_displays_helper_free_output (XfceRROutput *output)
 
 static GPtrArray *
 xfce_displays_helper_list_outputs (Display            *xdisplay,
-                                   XRRScreenResources *resources)
+                                   XRRScreenResources *resources,
+                                   XfceRRCrtc         *crtcs,
+                                   gint               *nactive)
 {
     GPtrArray     *outputs;
     XRROutputInfo *info;
     XfceRROutput  *output;
+    XfceRRCrtc    *crtc;
     gint           n;
 
-    g_assert (xdisplay && resources);
+    g_assert (xdisplay && resources && nactive);
 
     outputs = g_ptr_array_new ();
 
     /* get all connected outputs */
+    *nactive = 0;
     for (n = 0; n < resources->noutput; ++n)
     {
         info = XRRGetOutputInfo (xdisplay, resources, resources->outputs[n]);
@@ -288,6 +312,18 @@ xfce_displays_helper_list_outputs (Display            *xdisplay,
         output->id = resources->outputs[n];
         output->info = info;
 
+        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Detected output %lu %s.", output->id,
+                        output->info->name);
+
+        /* track active outputs */
+        crtc = xfce_displays_helper_find_crtc_by_id (resources, crtcs,
+                                                     output->info->crtc);
+        if (crtc && crtc->mode != None)
+        {
+            xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "%s is active.", output->info->name);
+            ++(*nactive);
+        }
+
         /* cache it */
         g_ptr_array_add (outputs, output);
     }
@@ -298,26 +334,6 @@ xfce_displays_helper_list_outputs (Display            *xdisplay,
 
 
 static XfceRRCrtc *
-xfce_displays_helper_find_crtc_by_id (XRRScreenResources *resources,
-                                      XfceRRCrtc         *crtcs,
-                                      RRCrtc              id)
-{
-    gint n;
-
-    g_assert (resources && crtcs);
-
-    for (n = 0; n < resources->ncrtc; ++n)
-    {
-        if (crtcs[n].id == id)
-            return &crtcs[n];
-    }
-
-    return NULL;
-}
-
-
-
-static XfceRRCrtc *
 xfce_displays_helper_find_usable_crtc (XRRScreenResources *resources,
                                        XfceRRCrtc         *crtcs,
                                        XfceRROutput       *output)
@@ -437,7 +453,7 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
     gint                min_width, min_height, max_width, max_height;
     gint                mm_width, mm_height, width, height;
     gint                x, y, min_x, min_y;
-    gint                l, m, int_value;
+    gint                l, m, int_value, nactive;
     guint               n;
     GValue             *value;
     const gchar        *str_value;
@@ -474,7 +490,8 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
     crtcs = xfce_displays_helper_list_crtcs (xdisplay, resources);
 
     /* then all connected outputs */
-    connected_outputs = xfce_displays_helper_list_outputs (xdisplay, resources);
+    connected_outputs = xfce_displays_helper_list_outputs (xdisplay, resources,
+                                                           crtcs, &nactive);
 
     /* finally the list of saved outputs from xfconf */
     g_snprintf (property, sizeof (property), "/%s", scheme);
@@ -521,18 +538,19 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         crtc = xfce_displays_helper_find_usable_crtc (resources, crtcs, output);
         if (!crtc)
         {
-            g_warning ("No available CRTC for output %s, aborting.", output->info->name);
+            g_warning ("No available CRTC for %s, aborting.", output->info->name);
             continue;
         }
-        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "CRTC %lu assigned to output %s.",
-                        crtc->id, output->info->name);
+        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "CRTC %lu assigned to %s.", crtc->id,
+                        output->info->name);
 
         /* disable inactive outputs */
         if (!g_value_get_boolean (value))
         {
             if (crtc->mode != None)
             {
-                xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Output %s will be disabled by configuration.",
+                --nactive;
+                xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "%s will be disabled by configuration.",
                                 output->info->name);
 
                 crtc->mode = None;
@@ -600,6 +618,9 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         }
         else if (crtc->mode != valid_mode)
         {
+            if (crtc->mode == None)
+                ++nactive;
+
             /* update CRTC mode */
             crtc->mode = valid_mode;
             crtc->changed = TRUE;
@@ -688,6 +709,15 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         xfce_displays_helper_set_outputs (crtc, output->id);
     }
 
+    xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Total %d active output(s).", nactive);
+
+    /* safety check */
+    if (nactive < 1)
+    {
+        g_critical ("Stored Xfconf properties disable all outputs, aborting.");
+        goto err_cleanup;
+    }
+
     /* grab server to prevent clients from thinking no output is enabled */
     XGrabServer (xdisplay);
 
@@ -698,10 +728,7 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
 
         /* ignore disabled outputs for size computations */
         if (crtcs[m].mode == None)
-        {
-            xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "CRTC %lu is disabled.", crtcs[m].id);
             continue;
-        }
 
         for (l = 0; l < resources->nmode; ++l)
         {


More information about the Xfce4-commits mailing list