[gnome-control-center] display: Use new GtkSwitch for display switching



commit 5b7132bacf0682c383a60f19d10b8205e2f6f208
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Nov 29 14:56:31 2010 +0000

    display: Use new GtkSwitch for display switching
    
    Instead of 2 radio buttons.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=636065

 configure.ac                      |    2 +-
 panels/display/display-capplet.ui |   21 +----------------
 panels/display/xrandr-capplet.c   |   46 +++++++++++++-----------------------
 3 files changed, 19 insertions(+), 50 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 60ed520..13de79d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,7 +76,7 @@ dnl Check that we meet the  dependencies
 dnl ==============================================
 
 GLIB_REQUIRED_VERSION=2.25.11
-GTK_REQUIRED_VERSION=2.91.3
+GTK_REQUIRED_VERSION=2.91.5
 DESKTOP_SCHEMAS_REQUIRED_VERSION=0.1.2
 PA_REQUIRED_VERSION=0.9.16
 CANBERRA_REQUIRED_VERSION=0.13
diff --git a/panels/display/display-capplet.ui b/panels/display/display-capplet.ui
index 3036b4d..4c0a7d8 100644
--- a/panels/display/display-capplet.ui
+++ b/panels/display/display-capplet.ui
@@ -80,14 +80,11 @@
                         <property name="visible">True</property>
                         <property name="spacing">12</property>
                         <child>
-                          <object class="GtkRadioButton" id="monitor_on_radio">
-                            <property name="label" translatable="yes">On</property>
+                          <object class="GtkSwitch" id="monitor_switch">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
-                            <property name="use_underline">True</property>
                             <property name="active">True</property>
-                            <property name="draw_indicator">True</property>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -95,22 +92,6 @@
                             <property name="position">0</property>
                           </packing>
                         </child>
-                        <child>
-                          <object class="GtkRadioButton" id="monitor_off_radio">
-                            <property name="label" translatable="yes">Off</property>
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_underline">True</property>
-                            <property name="draw_indicator">True</property>
-                            <property name="group">monitor_on_radio</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
diff --git a/panels/display/xrandr-capplet.c b/panels/display/xrandr-capplet.c
index ded4a8e..cc7d122 100644
--- a/panels/display/xrandr-capplet.c
+++ b/panels/display/xrandr-capplet.c
@@ -55,8 +55,7 @@ struct App
   GtkWidget      *panel;
   GtkWidget      *current_monitor_event_box;
   GtkWidget      *current_monitor_label;
-  GtkWidget      *monitor_on_radio;
-  GtkWidget      *monitor_off_radio;
+  GtkWidget      *monitor_switch;
   GtkListStore   *resolution_store;
   GtkWidget      *resolution_combo;
   GtkWidget      *rotation_combo;
@@ -87,7 +86,7 @@ static void rebuild_gui (App *app);
 static void on_clone_changed (GtkWidget *box, gpointer data);
 static gboolean output_overlaps (GnomeOutputInfo *output, GnomeRRConfig *config);
 static void select_current_output_from_dialog_position (App *app);
-static void monitor_on_off_toggled_cb (GtkToggleButton *toggle, gpointer data);
+static void monitor_switch_active_cb (GObject *object, GParamSpec *pspec, gpointer data);
 static void get_geometry (GnomeOutputInfo *output, int *w, int *h);
 static void apply_configuration_returned_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, void *data);
 static gboolean get_clone_size (GnomeRRScreen *screen, int *width, int *height);
@@ -504,8 +503,7 @@ rebuild_on_off_radios (App *app)
   gboolean on_active;
   gboolean off_active;
 
-  g_signal_handlers_block_by_func (app->monitor_on_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
-  g_signal_handlers_block_by_func (app->monitor_off_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
+  g_signal_handlers_block_by_func (app->monitor_switch, G_CALLBACK (monitor_switch_active_cb), app);
 
   sensitive = FALSE;
   on_active = FALSE;
@@ -522,14 +520,11 @@ rebuild_on_off_radios (App *app)
       off_active = !on_active;
     }
 
-  gtk_widget_set_sensitive (app->monitor_on_radio, sensitive);
-  gtk_widget_set_sensitive (app->monitor_off_radio, sensitive);
+  gtk_widget_set_sensitive (app->monitor_switch, sensitive);
 
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->monitor_on_radio), on_active);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->monitor_off_radio), off_active);
+  gtk_switch_set_active (GTK_SWITCH (app->monitor_switch), on_active);
 
-  g_signal_handlers_unblock_by_func (app->monitor_on_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
-  g_signal_handlers_unblock_by_func (app->monitor_off_radio, G_CALLBACK (monitor_on_off_toggled_cb), app);
+  g_signal_handlers_unblock_by_func (app->monitor_switch, G_CALLBACK (monitor_switch_active_cb), app);
 }
 
 static char *
@@ -749,31 +744,28 @@ select_resolution_for_current_output (App *app)
 }
 
 static void
-monitor_on_off_toggled_cb (GtkToggleButton *toggle, gpointer data)
+monitor_switch_active_cb (GObject    *object,
+                          GParamSpec *pspec,
+                          gpointer    data)
 {
   App *app = data;
+  gboolean value;
 
   if (!app->current_output)
     return;
 
-  if (!gtk_toggle_button_get_active (toggle))
-    return;
+  value = gtk_switch_get_active (GTK_SWITCH (object));
 
-  if (GTK_WIDGET (toggle) == app->monitor_on_radio)
+  if (value)
     {
       app->current_output->on = TRUE;
       select_resolution_for_current_output (app);
     }
-  else if (GTK_WIDGET (toggle) == app->monitor_off_radio)
+  else
     {
       app->current_output->on = FALSE;
       gnome_rr_config_ensure_primary (app->current_configuration);
     }
-  else
-    {
-      g_assert_not_reached ();
-      return;
-    }
 
   rebuild_gui (app);
   foo_scroll_area_invalidate (FOO_SCROLL_AREA (app->area));
@@ -2522,14 +2514,10 @@ run_application (void)
   app->current_monitor_label = _gtk_builder_get_widget (builder,
                                                         "current_monitor_label");
 
-  app->monitor_on_radio = _gtk_builder_get_widget (builder,
-                                                   "monitor_on_radio");
-  app->monitor_off_radio = _gtk_builder_get_widget (builder,
-                                                    "monitor_off_radio");
-  g_signal_connect (app->monitor_on_radio, "toggled",
-                    G_CALLBACK (monitor_on_off_toggled_cb), app);
-  g_signal_connect (app->monitor_off_radio, "toggled",
-                    G_CALLBACK (monitor_on_off_toggled_cb), app);
+  app->monitor_switch = _gtk_builder_get_widget (builder,
+                                                 "monitor_switch");
+  g_signal_connect (app->monitor_switch, "notify::active",
+                    G_CALLBACK (monitor_switch_active_cb), app);
 
   app->resolution_combo = _gtk_builder_get_widget (builder,
                                                    "resolution_combo");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]