[Xfce4-commits] <xfce4-settings:master> Super simplification of minimal dialog and code.

Nick Schermer noreply at xfce.org
Sun Oct 28 10:44:30 CET 2012


Updating branch refs/heads/master
         to 1499a6c1cc8cf74dd4b5b453830cd9b25302d8fe (commit)
       from 07b666ad15773ed01ecc742a4305c2c8368927b9 (commit)

commit 1499a6c1cc8cf74dd4b5b453830cd9b25302d8fe
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Thu Oct 4 14:03:25 2012 -0400

    Super simplification of minimal dialog and code.

 dialogs/display-settings/main.c                    |  225 ++++++--------------
 .../display-settings/minimal-display-dialog.glade  |  161 ++++++++-------
 2 files changed, 147 insertions(+), 239 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index e57ba21..03ebbc5 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -1367,158 +1367,86 @@ display_settings_dialog_new (GtkBuilder *builder)
 
 static void
 display_settings_minimal_only_display1_toggled (GtkToggleButton *button,
-                                              GtkBuilder *builder)
+                                                GtkBuilder      *builder)
 {
-    GObject *mirror_displays, *extend_right, *only_display2;
+    GObject *buttons;
     
-    mirror_displays = gtk_builder_get_object(builder, "mirror");
-    extend_right = gtk_builder_get_object(builder, "extend_right");
-    only_display2 = gtk_builder_get_object(builder, "display2");
-
-    /* Lock everything in the dialog to prevent bad things from happening */
-    g_object_disconnect (mirror_displays, "any_signal::toggled",
-                         display_settings_minimal_mirror_displays_toggled,
-                         builder, NULL);
-    g_object_disconnect (extend_right, "any_signal::toggled",
-                         display_settings_minimal_extend_right_toggled,
-                         builder, NULL);
-    g_object_disconnect (only_display2, "any_signal::toggled",
-                         display_settings_minimal_only_display2_toggled,
-                         builder, NULL);
-                         
-    gtk_widget_set_sensitive( GTK_WIDGET(mirror_displays), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(extend_right), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display2), FALSE );
-
-    gtk_toggle_button_set_active (button, TRUE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(mirror_displays), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(extend_right), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(only_display2), FALSE);
+    if ( !gtk_toggle_button_get_active(button) ) 
+        return;
     
     if (!xfce_randr)
         return;
 
     if (xfce_randr->noutput <= 1)
         return;
+        
+    buttons = gtk_builder_get_object(builder, "buttons");
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), FALSE );
 
-    if (gtk_toggle_button_get_active (button))
-    {
-		/* Put Display1 in its preferred mode and deactivate Display2 */
-        XFCE_RANDR_MODE (xfce_randr) = xfce_randr_preferred_mode (xfce_randr, 0);
-        xfce_randr->active_output = 1;
-        XFCE_RANDR_MODE (xfce_randr) = None;
-        /* Apply the changes */
-        xfce_randr_save_output (xfce_randr, "Default", display_channel,0);
-        xfce_randr_save_output (xfce_randr, "Default", display_channel,1);
-        xfce_randr_apply (xfce_randr, "Default", display_channel);
-    }
+	/* Put Display1 in its preferred mode and deactivate Display2 */
+    XFCE_RANDR_MODE (xfce_randr) = xfce_randr_preferred_mode (xfce_randr, 0);
+    xfce_randr->active_output = 1;
+    XFCE_RANDR_MODE (xfce_randr) = None;
     
-    gtk_widget_set_sensitive( GTK_WIDGET(mirror_displays), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(extend_right), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display2), TRUE );
-
-    /* Reconnect the signals */
-    g_signal_connect (mirror_displays, "toggled", G_CALLBACK (display_settings_minimal_mirror_displays_toggled),
-                      builder);
-    g_signal_connect (extend_right, "toggled", G_CALLBACK (display_settings_minimal_extend_right_toggled),
-                      builder);
-    g_signal_connect (only_display2, "toggled", G_CALLBACK (display_settings_minimal_only_display2_toggled),
-                      builder);
+    /* Apply the changes */
+    xfce_randr_save_output (xfce_randr, "Default", display_channel,0);
+    xfce_randr_save_output (xfce_randr, "Default", display_channel,1);
+    xfce_randr_apply (xfce_randr, "Default", display_channel);
+    
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), TRUE );
 }
 
 static void
 display_settings_minimal_only_display2_toggled (GtkToggleButton *button,
-                                              GtkBuilder *builder)
+                                                GtkBuilder      *builder)
 {
-    GObject *mirror_displays, *extend_right, *only_display1;
+    GObject *buttons;
     
-    mirror_displays = gtk_builder_get_object(builder, "mirror");
-    extend_right = gtk_builder_get_object(builder, "extend_right");
-    only_display1 = gtk_builder_get_object(builder, "display1");
-
-    /* Lock everything in the dialog to prevent bad things from happening */
-    g_object_disconnect (mirror_displays, "any_signal::toggled",
-                         display_settings_minimal_mirror_displays_toggled,
-                         builder, NULL);
-    g_object_disconnect (extend_right, "any_signal::toggled",
-                         display_settings_minimal_extend_right_toggled,
-                         builder, NULL);
-    g_object_disconnect (only_display1, "any_signal::toggled",
-                         display_settings_minimal_only_display1_toggled,
-                         builder, NULL);
-                         
-    gtk_widget_set_sensitive( GTK_WIDGET(mirror_displays), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(extend_right), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display1), FALSE );
-
-    gtk_toggle_button_set_active (button, TRUE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(mirror_displays), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(extend_right), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(only_display1), FALSE);
+    if ( !gtk_toggle_button_get_active(button) ) 
+        return;
     
     if (!xfce_randr)
         return;
 
     if (xfce_randr->noutput <= 1)
         return;
+        
+    buttons = gtk_builder_get_object(builder, "buttons");
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), FALSE );
 
-    if (gtk_toggle_button_get_active (button))
-    {
-        /* Put Display2 in its preferred mode and deactivate Display1 */
-        XFCE_RANDR_MODE (xfce_randr) = xfce_randr_preferred_mode (xfce_randr, 1);
-        xfce_randr->active_output = 0;
-        XFCE_RANDR_MODE (xfce_randr) = None;
-        /* Apply the changes */
-        xfce_randr_save_output (xfce_randr, "Default", display_channel,0);
-        xfce_randr_save_output (xfce_randr, "Default", display_channel,1);
-        xfce_randr_apply (xfce_randr, "Default", display_channel);
-    }
+    /* Put Display2 in its preferred mode and deactivate Display1 */
+    XFCE_RANDR_MODE (xfce_randr) = xfce_randr_preferred_mode (xfce_randr, 1);
+    xfce_randr->active_output = 0;
+    XFCE_RANDR_MODE (xfce_randr) = None;
     
-    gtk_widget_set_sensitive( GTK_WIDGET(mirror_displays), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(extend_right), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display1), TRUE );
-
-    /* Reconnect the signals */
-    g_signal_connect (mirror_displays, "toggled", G_CALLBACK (display_settings_minimal_mirror_displays_toggled),
-                      builder);
-    g_signal_connect (extend_right, "toggled", G_CALLBACK (display_settings_minimal_extend_right_toggled),
-                      builder);
-    g_signal_connect (only_display1, "toggled", G_CALLBACK (display_settings_minimal_only_display1_toggled),
-                      builder);
+    /* Apply the changes */
+    xfce_randr_save_output (xfce_randr, "Default", display_channel,0);
+    xfce_randr_save_output (xfce_randr, "Default", display_channel,1);
+    xfce_randr_apply (xfce_randr, "Default", display_channel);
+    
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), TRUE );
 }
 
 static void
 display_settings_minimal_mirror_displays_toggled (GtkToggleButton *button,
-                                              GtkBuilder *builder)
+                                                  GtkBuilder      *builder)
 {
-    GObject *extend_right, *only_display1, *only_display2;
+    GObject *buttons;
     
     gint selected_x, selected_y;
     guint n;
-    
-    only_display1 = gtk_builder_get_object(builder, "display1");
-    only_display2 = gtk_builder_get_object(builder, "display2");
-    extend_right = gtk_builder_get_object(builder, "extend_right");
 
-    /* Lock everything in the dialog to prevent bad things from happening */
-    g_object_disconnect (only_display1, "any_signal::toggled",
-                         display_settings_minimal_only_display1_toggled,
-                         builder, NULL);
-    g_object_disconnect (only_display2, "any_signal::toggled",
-                         display_settings_minimal_only_display2_toggled,
-                         builder, NULL);
-    g_object_disconnect (extend_right, "any_signal::toggled",
-                         display_settings_minimal_extend_right_toggled,
-                         builder, NULL);
-                         
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display1), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display2), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(extend_right), FALSE );
+    if ( !gtk_toggle_button_get_active(button) ) 
+        return;
+    
+    if (!xfce_randr)
+        return;
 
-    gtk_toggle_button_set_active (button, TRUE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(only_display1), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(only_display2), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(extend_right), FALSE);
+    if (xfce_randr->noutput <= 1)
+        return;
+        
+    buttons = gtk_builder_get_object(builder, "buttons");
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), FALSE );
 
 	/* Activate all inactive displays */
 	for (n = 0; n < xfce_randr->noutput; ++n)
@@ -1544,51 +1472,30 @@ display_settings_minimal_mirror_displays_toggled (GtkToggleButton *button,
     /* Apply all changes */
     xfce_randr_apply (xfce_randr, "Default", display_channel);
     
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display1), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display2), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(extend_right), TRUE );
-
-    /* Reconnect the signals */
-    g_signal_connect (only_display1, "toggled", G_CALLBACK (display_settings_minimal_only_display1_toggled),
-                      builder);
-    g_signal_connect (only_display2, "toggled", G_CALLBACK (display_settings_minimal_only_display2_toggled),
-                      builder);
-    g_signal_connect (extend_right, "toggled", G_CALLBACK (display_settings_minimal_extend_right_toggled),
-                      builder);
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), TRUE );
 }
 
 static void
 display_settings_minimal_extend_right_toggled (GtkToggleButton *button,
                                               GtkBuilder *builder)
 {
-    GObject *mirror_displays, *only_display1, *only_display2;
+    GObject *buttons;
+
     guint n;
-    
+        
     XfceRRMode   *current_mode;
     
-    mirror_displays = gtk_builder_get_object(builder, "mirror");
-    only_display1 = gtk_builder_get_object(builder, "display1");
-    only_display2 = gtk_builder_get_object(builder, "display2");
-
-    /* Lock everything in the dialog to prevent bad things from happening */
-    g_object_disconnect (mirror_displays, "any_signal::toggled",
-                         display_settings_minimal_mirror_displays_toggled,
-                         builder, NULL);
-    g_object_disconnect (only_display1, "any_signal::toggled",
-                         display_settings_minimal_only_display1_toggled,
-                         builder, NULL);
-    g_object_disconnect (only_display2, "any_signal::toggled",
-                         display_settings_minimal_only_display2_toggled,
-                         builder, NULL);
-                         
-    gtk_widget_set_sensitive( GTK_WIDGET(mirror_displays), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display1), FALSE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display2), FALSE );
+    if ( !gtk_toggle_button_get_active(button) ) 
+        return;
     
-    gtk_toggle_button_set_active (button, TRUE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(mirror_displays), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(only_display1), FALSE);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(only_display2), FALSE);
+    if (!xfce_randr)
+        return;
+
+    if (xfce_randr->noutput <= 1)
+        return;
+        
+    buttons = gtk_builder_get_object(builder, "buttons");
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), FALSE );
 
 	/* Activate all inactive displays */
 	for (n = 0; n < xfce_randr->noutput; ++n)
@@ -1620,17 +1527,7 @@ display_settings_minimal_extend_right_toggled (GtkToggleButton *button,
     /* Apply all changes */
     xfce_randr_apply (xfce_randr, "Default", display_channel);
 
-    /* Unlock the dialog and reconnect the signals */    
-    gtk_widget_set_sensitive( GTK_WIDGET(mirror_displays), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display1), TRUE );
-    gtk_widget_set_sensitive( GTK_WIDGET(only_display2), TRUE );
-
-    g_signal_connect (mirror_displays, "toggled", G_CALLBACK (display_settings_minimal_mirror_displays_toggled),
-                      builder);
-    g_signal_connect (only_display1, "toggled", G_CALLBACK (display_settings_minimal_only_display1_toggled),
-                      builder);
-    g_signal_connect (only_display2, "toggled", G_CALLBACK (display_settings_minimal_only_display2_toggled),
-                      builder);
+    gtk_widget_set_sensitive( GTK_WIDGET(buttons), TRUE );
 }
 
 
diff --git a/dialogs/display-settings/minimal-display-dialog.glade b/dialogs/display-settings/minimal-display-dialog.glade
index 6e6b1d9..abaf02a 100644
--- a/dialogs/display-settings/minimal-display-dialog.glade
+++ b/dialogs/display-settings/minimal-display-dialog.glade
@@ -16,7 +16,7 @@
         <property name="border_width">6</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkTable" id="table1">
+          <object class="GtkTable" id="buttons">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="n_rows">2</property>
@@ -24,79 +24,57 @@
             <property name="column_spacing">24</property>
             <property name="row_spacing">3</property>
             <child>
-              <object class="GtkToggleButton" id="display1">
-                <property name="width_request">128</property>
-                <property name="height_request">128</property>
+              <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <child>
-                  <object class="GtkImage" id="image1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="pixbuf">display1.png</property>
-                  </object>
-                </child>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Only Display 1</property>
               </object>
               <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options">GTK_FILL</property>
               </packing>
             </child>
             <child>
-              <object class="GtkToggleButton" id="mirror">
-                <property name="width_request">128</property>
-                <property name="height_request">128</property>
+              <object class="GtkLabel" id="label2">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <child>
-                  <object class="GtkImage" id="image2">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="pixbuf">mirror.png</property>
-                  </object>
-                </child>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Mirror Displays</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options">GTK_FILL</property>
               </packing>
             </child>
             <child>
-              <object class="GtkToggleButton" id="extend_right">
-                <property name="width_request">128</property>
-                <property name="height_request">128</property>
+              <object class="GtkLabel" id="label3">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <child>
-                  <object class="GtkImage" id="image3">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="pixbuf">extend-right.png</property>
-                  </object>
-                </child>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Extend to the right</property>
               </object>
               <packing>
                 <property name="left_attach">2</property>
                 <property name="right_attach">3</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options">GTK_FILL</property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label1">
+              <object class="GtkLabel" id="label4">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Only Display 1</property>
+                <property name="label" translatable="yes">Only Display 2</property>
               </object>
               <packing>
+                <property name="left_attach">3</property>
+                <property name="right_attach">4</property>
                 <property name="top_attach">1</property>
                 <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
@@ -104,71 +82,104 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label2">
+              <object class="GtkRadioButton" id="display1">
+                <property name="width_request">128</property>
+                <property name="height_request">128</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Mirror Displays</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">False</property>
+                <child>
+                  <object class="GtkImage" id="image1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="pixbuf">display1.png</property>
+                  </object>
+                </child>
               </object>
               <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options">GTK_FILL</property>
+                <property name="x_options"></property>
+                <property name="y_options"></property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label3">
+              <object class="GtkRadioButton" id="mirror">
+                <property name="width_request">128</property>
+                <property name="height_request">128</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Extend to the right</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">False</property>
+                <property name="group">display1</property>
+                <child>
+                  <object class="GtkImage" id="image2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="pixbuf">mirror.png</property>
+                  </object>
+                </child>
               </object>
               <packing>
-                <property name="left_attach">2</property>
-                <property name="right_attach">3</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options">GTK_FILL</property>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="x_options"></property>
+                <property name="y_options"></property>
               </packing>
             </child>
             <child>
-              <object class="GtkToggleButton" id="display2">
+              <object class="GtkRadioButton" id="extend_right">
                 <property name="width_request">128</property>
                 <property name="height_request">128</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
+                <property name="receives_default">False</property>
                 <property name="use_action_appearance">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">False</property>
+                <property name="group">display1</property>
                 <child>
-                  <object class="GtkImage" id="image4">
+                  <object class="GtkImage" id="image3">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="pixbuf">display2.png</property>
+                    <property name="pixbuf">extend-right.png</property>
                   </object>
                 </child>
               </object>
               <packing>
-                <property name="left_attach">3</property>
-                <property name="right_attach">4</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options">GTK_FILL</property>
+                <property name="left_attach">2</property>
+                <property name="right_attach">3</property>
+                <property name="x_options"></property>
+                <property name="y_options"></property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label4">
+              <object class="GtkRadioButton" id="display2">
+                <property name="width_request">128</property>
+                <property name="height_request">128</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Only Display 2</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">False</property>
+                <property name="group">display1</property>
+                <child>
+                  <object class="GtkImage" id="image4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="pixbuf">display2.png</property>
+                  </object>
+                </child>
               </object>
               <packing>
                 <property name="left_attach">3</property>
                 <property name="right_attach">4</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options">GTK_FILL</property>
+                <property name="x_options"></property>
+                <property name="y_options"></property>
               </packing>
             </child>
           </object>


More information about the Xfce4-commits mailing list