[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Fall back to similar modes if no clone mode is available

Jérôme Guelfucci noreply at xfce.org
Mon Jun 21 11:46:06 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to 2d024516e3806a3f9955b96ea098e6872031dc86 (commit)
       from 92e59e7cf2122df7d5ee91e3d5167ea04fd91f0f (commit)

commit 2d024516e3806a3f9955b96ea098e6872031dc86
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Sun Jun 20 18:17:20 2010 +0200

    Fall back to similar modes if no clone mode is available
    
    In the minimal dialog, if no clone mode is available (same resolution and same
    rate), try to find a similar one (same res), to "emulate" cloned outputs.
    Also fix indentation to be consistent with the rest of the file.

 dialogs/display-settings/main.c |  153 ++++++++++++++++++++++-----------------
 1 files changed, 88 insertions(+), 65 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 9473c76..65be68c 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -848,71 +848,94 @@ display_settings_minimal_dialog_response (GtkDialog  *dialog,
                                           gint        response_id,
                                           GtkBuilder *builder)
 {
-  if (response_id == 1)
-  {
-      /* OK */
-      GObject  *first_screen_radio;
-      GObject  *second_screen_radio;
-      GObject  *both_radio;
-      gboolean  use_first_screen;
-      gboolean  use_second_screen;
-      gboolean  use_both;
-      gint      first;
-      gint      second;
-      gint      n;
-
-      first = second = -1;
-
-      for (n = 0; n < xfce_randr->resources->noutput; n++)
-      {
-          if (xfce_randr->status[n] != XFCE_OUTPUT_STATUS_NONE)
-          {
-              if (first < 0)
-                  first = n;
-              else if (second < 0)
-                  second = n;
-              else
-                  break;
-          }
-      }
-
-      first_screen_radio = gtk_builder_get_object (builder, "radiobutton1");
-      second_screen_radio = gtk_builder_get_object (builder, "radiobutton2");
-      both_radio = gtk_builder_get_object (builder, "radiobutton3");
-
-      use_first_screen =
-          gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (first_screen_radio));
-      use_second_screen =
-          gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (second_screen_radio));
-      use_both =
-          gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (both_radio));
-
-      if (use_first_screen)
-      {
-          xfce_randr->mode[first] = xfce_randr->preferred_mode[first];
-          xfce_randr->mode[second] = None;
-      }
-      else if (use_second_screen)
-      {
-          xfce_randr->mode[second] = xfce_randr->preferred_mode[second];
-          xfce_randr->mode[first] = None;
-      }
-      else
-      {
-          if (xfce_randr->clone_modes[0] != None)
-          {
-              xfce_randr->mode[first] = xfce_randr->clone_modes[0];
-              xfce_randr->mode[second] = xfce_randr->clone_modes[0];
-          }
-      }
-
-      xfce_randr_save (xfce_randr, "AutoConfigSecondary", display_channel);
-      gtk_main_quit ();
-  }
-  else
-  {
-      gtk_main_quit ();
-  }
+    GObject    *first_screen_radio;
+    GObject    *second_screen_radio;
+    GObject    *both_radio;
+    XfceRRMode *mode1, *mode2;
+    gboolean    use_first_screen;
+    gboolean    use_second_screen;
+    gboolean    use_both;
+    gint        first, second;
+    gint        m, n, found;
+
+    if (response_id == 1)
+    {
+        /* OK */
+
+        first = second = -1;
+
+        for (n = 0; n < xfce_randr->resources->noutput; n++)
+        {
+            if (xfce_randr->status[n] != XFCE_OUTPUT_STATUS_NONE)
+            {
+                if (first < 0)
+                    first = n;
+                else if (second < 0)
+                    second = n;
+                else
+                    break;
+            }
+        }
+
+        first_screen_radio = gtk_builder_get_object (builder, "radiobutton1");
+        second_screen_radio = gtk_builder_get_object (builder, "radiobutton2");
+        both_radio = gtk_builder_get_object (builder, "radiobutton3");
+
+        use_first_screen =
+            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (first_screen_radio));
+        use_second_screen =
+            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (second_screen_radio));
+        use_both =
+            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (both_radio));
+
+        if (use_first_screen)
+        {
+            xfce_randr->mode[first] = xfce_randr->preferred_mode[first];
+            xfce_randr->mode[second] = None;
+        }
+        else if (use_second_screen)
+        {
+            xfce_randr->mode[second] = xfce_randr->preferred_mode[second];
+            xfce_randr->mode[first] = None;
+        }
+        else
+        {
+            if (xfce_randr->clone_modes[0] != None)
+            {
+                xfce_randr->mode[first] = xfce_randr->clone_modes[0];
+                xfce_randr->mode[second] = xfce_randr->clone_modes[0];
+            }
+            else
+            {
+                found = FALSE;
+                /* no clone mode available, try to find a "similar" mode */
+                for (n = 0; n < xfce_randr->output_info[first]->nmode; ++n)
+                {
+                    mode1 = &xfce_randr->modes[first][n];
+                    for (m = 0; m < xfce_randr->output_info[second]->nmode; ++m)
+                    {
+                        mode2 = &xfce_randr->modes[second][m];
+                        /* "similar" means same resolution */
+                        if (mode1->width == mode2->width
+                            && mode1->height == mode2->height)
+                        {
+                            xfce_randr->mode[first] = mode1->id;
+                            xfce_randr->mode[second] = mode2->id;
+                            found = TRUE;
+                            break;
+                        }
+                    }
+
+                    if (found)
+                        break;
+                }
+            }
+        }
+
+        xfce_randr_save (xfce_randr, "AutoConfigSecondary", display_channel);
+    }
+
+    gtk_main_quit ();
 }
 #endif
 



More information about the Xfce4-commits mailing list