[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Improve the code to find an available crtc

Jérôme Guelfucci noreply at xfce.org
Thu Jun 10 22:26:01 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to 9d3cd50eea8a0fe318d3b4437cbe17f000df950e (commit)
       from 032591e71c96d333aec0a13de307ac0c2105a053 (commit)

commit 9d3cd50eea8a0fe318d3b4437cbe17f000df950e
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Thu Jun 10 19:37:08 2010 +0200

    Improve the code to find an available crtc
    
    Instead of taking the first one (that can be used by another output already),
    check for a possible free crtc.

 xfce4-settings-helper/displays.c |   68 ++++++++++++++++++++++++++++++-------
 1 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/xfce4-settings-helper/displays.c b/xfce4-settings-helper/displays.c
index 6a9d3e7..2a95f2f 100644
--- a/xfce4-settings-helper/displays.c
+++ b/xfce4-settings-helper/displays.c
@@ -165,6 +165,60 @@ xfce_displays_helper_finalize (GObject *object)
 
 
 #ifdef HAS_RANDR_ONE_POINT_TWO
+static RRCrtc
+xfce_displays_helper_find_crtc (Display            *xdisplay,
+                                XRRScreenResources *resources,
+                                XRROutputInfo      *current_output)
+{
+    XRROutputInfo *output_info;
+    gint           m, n, candidate;
+
+    g_return_val_if_fail (current_output != NULL, None);
+
+    /* if there is one already active, return it */
+    if (current_output->crtc != None)
+        return current_output->crtc;
+
+    g_return_val_if_fail (resources != NULL, None);
+
+    /* try to find one that is not already used by another output */
+    for (n = 0; n < current_output->ncrtc; ++n)
+    {
+        candidate = TRUE;
+        for (m = 0; m < resources->noutput; ++m)
+        {
+            output_info = XRRGetOutputInfo (xdisplay, resources, resources->outputs[m]);
+
+            /* go to the next output directly */
+            if (output_info->connection != RR_Connected
+                || g_strcmp0 (output_info->name, current_output->name) == 0)
+            {
+                XRRFreeOutputInfo (output_info);
+                continue;
+            }
+
+            /* crtc already used */
+            if (output_info->crtc == current_output->crtcs[n])
+            {
+                candidate = FALSE;
+                XRRFreeOutputInfo (output_info);
+                break;
+            }
+
+            XRRFreeOutputInfo (output_info);
+        }
+
+        if (candidate)
+            return current_output->crtcs[n];
+    }
+
+    /* none available */
+    g_warning ("No CRTC found for %s.", current_output->name);
+    return None;
+}
+
+
+
 static Status
 xfce_displays_helper_disable_crtc (Display            *xdisplay,
                                    XRRScreenResources *resources,
@@ -339,19 +393,7 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
                 break;
             }
 
-            crtc = None;
-            if (output_info->crtc != None)
-            {
-                /* Good, output already enabled */
-                crtc = output_info->crtc;
-            }
-            else if (output_info->ncrtc > 0)
-            {
-                /* output previously disabled, and the user wants to reenable it */
-                crtc = output_info->crtcs[0];
-            }
-            else
-                g_warning ("No CRTC found for %s.", output_info->name);
+            crtc = xfce_displays_helper_find_crtc (xdisplay, resources, output_info);
 
             if (crtc != None)
             {



More information about the Xfce4-commits mailing list