[Xfce4-commits] <xfce4-settings:bluesabre/display-settings> Simplify dimensions' calculation

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


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

commit d151c850deaa6639262d707f9de6c026f7515b27
Author: Lionel Le Folgoc <lionel at lefolgoc.net>
Date:   Mon Oct 15 17:33:19 2012 +0200

    Simplify dimensions' calculation
    
    Signed-off-by: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>

 xfsettingsd/displays.c |  153 +++++++++++++++++++++++-------------------------
 1 files changed, 74 insertions(+), 79 deletions(-)

diff --git a/xfsettingsd/displays.c b/xfsettingsd/displays.c
index 4101135..d5a7799 100644
--- a/xfsettingsd/displays.c
+++ b/xfsettingsd/displays.c
@@ -83,6 +83,8 @@ struct _XfceRRCrtc
     RRMode    mode;
     Rotation  rotation;
     Rotation  rotations;
+    gint      width;
+    gint      height;
     gint      x;
     gint      y;
     gint      noutput;
@@ -210,6 +212,8 @@ xfce_displays_helper_list_crtcs (Display            *xdisplay,
         crtcs[n].mode = crtc_info->mode;
         crtcs[n].rotation = crtc_info->rotation;
         crtcs[n].rotations = crtc_info->rotations;
+        crtcs[n].width = crtc_info->width;
+        crtcs[n].height = crtc_info->height;
         crtcs[n].x = crtc_info->x;
         crtcs[n].y = crtc_info->y;
 
@@ -561,6 +565,56 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
             continue;
         }
 
+        /* rotation */
+        g_snprintf (property, sizeof (property), "/%s/%s/Rotation", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_INT (value))
+            int_value = g_value_get_int (value);
+        else
+            int_value = 0;
+
+        /* convert to a Rotation */
+        switch (int_value)
+        {
+            case 90:  rot = RR_Rotate_90;  break;
+            case 180: rot = RR_Rotate_180; break;
+            case 270: rot = RR_Rotate_270; break;
+            default:  rot = RR_Rotate_0;   break;
+        }
+
+        /* reflection */
+        g_snprintf (property, sizeof (property), "/%s/%s/Reflection", scheme,
+                    output->info->name);
+        value = g_hash_table_lookup (saved_outputs, property);
+        if (G_VALUE_HOLDS_STRING (value))
+            str_value = g_value_get_string (value);
+        else
+            str_value = "0";
+
+        /* convert to a Rotation */
+        if (g_strcmp0 (str_value, "X") == 0)
+            rot |= RR_Reflect_X;
+        else if (g_strcmp0 (str_value, "Y") == 0)
+            rot |= RR_Reflect_Y;
+        else if (g_strcmp0 (str_value, "XY") == 0)
+            rot |= (RR_Reflect_X|RR_Reflect_Y);
+
+        /* check rotation support */
+        if ((crtc->rotations & rot) == 0)
+        {
+            g_warning ("Unsupported rotation for %s. Fallback to RR_Rotate_0.",
+                       output->info->name);
+            rot = RR_Rotate_0;
+        }
+
+        /* update CRTC rotation */
+        if (crtc->rotation != rot)
+        {
+            crtc->rotation = rot;
+            crtc->changed = TRUE;
+        }
+
         /* resolution */
         g_snprintf (property, sizeof (property), "/%s/%s/Resolution",
                     scheme, output->info->name);
@@ -586,21 +640,19 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
             /* walk all modes */
             for (l = 0; l < resources->nmode; ++l)
             {
-                /* get the mode info */
-                XRRModeInfo *mode_info = &resources->modes[l];
-
                 /* does the mode info match the mode we seek? */
-                if (mode_info->id != output->info->modes[m])
+                if (resources->modes[l].id != output->info->modes[m])
                     continue;
 
                 /* calculate the refresh rate */
-                rate = (gdouble) mode_info->dotClock / ((gdouble) mode_info->hTotal * (gdouble) mode_info->vTotal);
+                rate = (gdouble) resources->modes[l].dotClock /
+                        ((gdouble) resources->modes[l].hTotal * (gdouble) resources->modes[l].vTotal);
 
                 /* find the mode corresponding to the saved values */
                 if (rint (rate) == rint (output_rate)
-                    && (g_strcmp0 (mode_info->name, str_value) == 0))
+                    && (g_strcmp0 (resources->modes[l].name, str_value) == 0))
                 {
-                    valid_mode = mode_info->id;
+                    valid_mode = resources->modes[l].id;
                     break;
                 }
             }
@@ -624,56 +676,18 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
             /* update CRTC mode */
             crtc->mode = valid_mode;
             crtc->changed = TRUE;
-        }
 
-        /* rotation */
-        g_snprintf (property, sizeof (property), "/%s/%s/Rotation", scheme,
-                    output->info->name);
-        value = g_hash_table_lookup (saved_outputs, property);
-        if (G_VALUE_HOLDS_INT (value))
-            int_value = g_value_get_int (value);
-        else
-            int_value = 0;
-
-        /* convert to a Rotation */
-        switch (int_value)
-        {
-            case 90:  rot = RR_Rotate_90;  break;
-            case 180: rot = RR_Rotate_180; break;
-            case 270: rot = RR_Rotate_270; break;
-            default:  rot = RR_Rotate_0;   break;
-        }
-
-        /* reflection */
-        g_snprintf (property, sizeof (property), "/%s/%s/Reflection", scheme,
-                    output->info->name);
-        value = g_hash_table_lookup (saved_outputs, property);
-        if (G_VALUE_HOLDS_STRING (value))
-            str_value = g_value_get_string (value);
-        else
-            str_value = "0";
-
-        /* convert to a Rotation */
-        if (g_strcmp0 (str_value, "X") == 0)
-            rot |= RR_Reflect_X;
-        else if (g_strcmp0 (str_value, "Y") == 0)
-            rot |= RR_Reflect_Y;
-        else if (g_strcmp0 (str_value, "XY") == 0)
-            rot |= (RR_Reflect_X|RR_Reflect_Y);
-
-        /* check rotation support */
-        if ((crtc->rotations & rot) == 0)
-        {
-            g_warning ("Unsupported rotation for %s. Fallback to RR_Rotate_0.",
-                       output->info->name);
-            rot = RR_Rotate_0;
-        }
-
-        /* update CRTC rotation */
-        if (crtc->rotation != rot)
-        {
-            crtc->rotation = rot;
-            crtc->changed = TRUE;
+            /* recompute dimensions according to the selected rotation */
+            if ((crtc->rotation & (RR_Rotate_90|RR_Rotate_270)) != 0)
+            {
+                crtc->width = resources->modes[l].height;
+                crtc->height = resources->modes[l].width;
+            }
+            else
+            {
+                crtc->width = resources->modes[l].width;
+                crtc->height = resources->modes[l].height;
+            }
         }
 
         /* position, x */
@@ -724,24 +738,10 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
     /* second loop, normalization and global settings */
     for (m = 0; m < resources->ncrtc; ++m)
     {
-        gint mode_height = 0, mode_width = 0;
-
         /* ignore disabled outputs for size computations */
         if (crtcs[m].mode == None)
             continue;
 
-        for (l = 0; l < resources->nmode; ++l)
-        {
-            /* does the mode info match the mode we seek? */
-            if (resources->modes[l].id != crtcs[m].mode)
-                continue;
-
-            /* store the dimensions */
-            mode_height = resources->modes[l].height;
-            mode_width = resources->modes[l].width;
-            break;
-        }
-
         /* normalize positions to ensure the upper left corner is at (0,0) */
         if (min_x || min_y)
         {
@@ -751,17 +751,12 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         }
 
         xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Normalized CRTC %lu: size=%dx%d, pos=%dx%d.",
-                        crtcs[m].id, mode_width, mode_height, crtcs[m].x, crtcs[m].y);
+                        crtcs[m].id, crtcs[m].width, crtcs[m].height, crtcs[m].x, crtcs[m].y);
 
         /* calculate the total screen size */
-        if ((crtcs[m].rotation & (RR_Rotate_90|RR_Rotate_270)) != 0)
-            xfce_displays_helper_process_screen_size (mode_height, mode_width,
-                                                      crtcs[m].x, crtcs[m].y, &width,
-                                                      &height, &mm_width, &mm_height);
-        else
-            xfce_displays_helper_process_screen_size (mode_width, mode_height,
-                                                      crtcs[m].x, crtcs[m].y, &width,
-                                                      &height, &mm_width, &mm_height);
+        xfce_displays_helper_process_screen_size (crtcs[m].width, crtcs[m].height,
+                                                  crtcs[m].x, crtcs[m].y, &width,
+                                                  &height, &mm_width, &mm_height);
 
         /* disable the CRTC, it will be reenabled after size calculation */
         if (xfce_displays_helper_disable_crtc (xdisplay, resources, crtcs[m].id) == RRSetConfigSuccess)


More information about the Xfce4-commits mailing list