[Xfce4-commits] <xfce4-cpufreq-plugin:master> Replace GtkEventBox with a toggle button.

Harald Judt noreply at xfce.org
Sun Aug 18 11:32:13 CEST 2013


Updating branch refs/heads/master
         to 0257489546053ef5bd952074a59ba5d0513d18a6 (commit)
       from bb6ffb59ab5f1549920652a02066b6ab034a11c4 (commit)

commit 0257489546053ef5bd952074a59ba5d0513d18a6
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Aug 11 00:52:15 2013 +0200

    Replace GtkEventBox with a toggle button.
    
    The panel toggle button provides better UI feedback for the user and
    makes the overview window open or close.

 panel-plugin/xfce4-cpufreq-overview.c |   11 ++++++++++-
 panel-plugin/xfce4-cpufreq-plugin.c   |   19 ++++++++++---------
 panel-plugin/xfce4-cpufreq-plugin.h   |    2 +-
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/panel-plugin/xfce4-cpufreq-overview.c b/panel-plugin/xfce4-cpufreq-overview.c
index c4937bf..c9d5a74 100644
--- a/panel-plugin/xfce4-cpufreq-overview.c
+++ b/panel-plugin/xfce4-cpufreq-overview.c
@@ -175,6 +175,7 @@ cpufreq_overview_response (GtkWidget *dialog, gint response, gpointer data)
 {
 	g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
 	gtk_widget_destroy (dialog);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button), FALSE);
 }
 
 gboolean
@@ -189,8 +190,16 @@ cpufreq_overview (GtkWidget *widget, GdkEventButton *ev, CpuFreqPlugin *cpuFreq)
 
 	window = g_object_get_data (G_OBJECT (cpuFreq->plugin), "overview");
 
-	if (window)
+	if (window) {
+		g_object_set_data (G_OBJECT (cpuFreq->plugin), "overview", NULL);
 		gtk_widget_destroy (window);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button),
+									  FALSE);
+		return TRUE;
+	}
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cpuFreq->button),
+								  TRUE);
 
 	dialog = xfce_titled_dialog_new_with_buttons (_("CPU Information"),
 					NULL,
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index 97b4ee1..dd3449e 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -264,25 +264,26 @@ cpufreq_widgets (void)
 	cpuFreq->icon_size /= xfce_panel_plugin_get_nrows (cpuFreq->plugin);
 	cpuFreq->icon_size -= 2;
 
-	cpuFreq->ebox = gtk_event_box_new ();
-	gtk_event_box_set_visible_window (GTK_EVENT_BOX (cpuFreq->ebox), FALSE);
-	xfce_panel_plugin_add_action_widget (cpuFreq->plugin, cpuFreq->ebox);
-	gtk_container_add (GTK_CONTAINER (cpuFreq->plugin), cpuFreq->ebox);
+	/* create panel toggle button which will contain all other widgets */
+	cpuFreq->button = xfce_create_panel_toggle_button ();
+	xfce_panel_plugin_add_action_widget (cpuFreq->plugin, cpuFreq->button);
+	gtk_container_add (GTK_CONTAINER (cpuFreq->plugin), cpuFreq->button);
 
 	cpuFreq->box = gtk_hbox_new (FALSE, SPACING);
 	gtk_container_set_border_width (GTK_CONTAINER (cpuFreq->box), BORDER);
-	gtk_container_add (GTK_CONTAINER (cpuFreq->ebox), cpuFreq->box);
+	gtk_container_add (GTK_CONTAINER (cpuFreq->button), cpuFreq->box);
 
 	cpufreq_update_icon (cpuFreq);
 
 	cpufreq_prepare_label (cpuFreq);
 
-	g_signal_connect (cpuFreq->ebox, "button-press-event", G_CALLBACK (cpufreq_overview), cpuFreq);
+	g_signal_connect (cpuFreq->button, "button-press-event",
+					  G_CALLBACK (cpufreq_overview), cpuFreq);
 
 	/* activate panel widget tooltip */
 	cpu = g_ptr_array_index (cpuFreq->cpus, cpuFreq->options->show_cpu);
-	g_object_set (G_OBJECT (cpuFreq->ebox), "has-tooltip", TRUE, NULL);
-	g_signal_connect (G_OBJECT (cpuFreq->ebox), "query-tooltip",
+	g_object_set (G_OBJECT (cpuFreq->button), "has-tooltip", TRUE, NULL);
+	g_signal_connect (G_OBJECT (cpuFreq->button), "query-tooltip",
 					  G_CALLBACK (cpufreq_update_tooltip), cpu);
 
 	cpufreq_mode_changed (cpuFreq->plugin,
@@ -290,7 +291,7 @@ cpufreq_widgets (void)
 						  cpuFreq);
 
 	gtk_widget_show (cpuFreq->box);
-	gtk_widget_show (cpuFreq->ebox);
+	gtk_widget_show (cpuFreq->button);
 
 	cpufreq_update_plugin ();
 }
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index bbc5a3e..f976cb9 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -56,7 +56,7 @@ typedef struct
 	GPtrArray *cpus;
 
 	/* Widgets */
-	GtkWidget   *ebox, *box, *icon, *label;
+	GtkWidget *button, *box, *icon, *label;
 
 	gint icon_size;
 


More information about the Xfce4-commits mailing list