summaryrefslogtreecommitdiff
path: root/cpufreq
diff options
context:
space:
mode:
authorAlberts Muktupāvels <[email protected]>2018-03-12 00:50:02 +0200
committerRobert Antoni Buj Gelonch <[email protected]>2020-08-01 23:08:45 +0200
commit3b8e2111a4484c8450297d6764d1e3c30b3327c8 (patch)
tree21e3d3048d07d1efaeb939c941b2f469798142d1 /cpufreq
parenta6c4459ad5d4b2ccb3eb8c330f024a49869442ed (diff)
downloadmate-applets-3b8e2111a4484c8450297d6764d1e3c30b3327c8.tar.bz2
mate-applets-3b8e2111a4484c8450297d6764d1e3c30b3327c8.tar.xz
cpufreq: create all needed widgets only once
origin commit: https://gitlab.gnome.org/GNOME/gnome-applets/-/commit/8951c6f
Diffstat (limited to 'cpufreq')
-rw-r--r--cpufreq/src/cpufreq-applet.c102
1 files changed, 49 insertions, 53 deletions
diff --git a/cpufreq/src/cpufreq-applet.c b/cpufreq/src/cpufreq-applet.c
index 3d90e5e9..10671882 100644
--- a/cpufreq/src/cpufreq-applet.c
+++ b/cpufreq/src/cpufreq-applet.c
@@ -56,12 +56,13 @@ struct _CPUFreqApplet {
MatePanelAppletOrient orient;
gint size;
- GtkWidget *label;
- GtkWidget *unit_label;
- GtkWidget *icon;
+ GtkWidget *container;
GtkWidget *box;
+ GtkWidget *icon;
GtkWidget *labels_box;
- GtkWidget *container;
+ GtkWidget *label;
+ GtkWidget *unit_label;
+
cairo_surface_t *surfaces[5];
gboolean need_refresh;
@@ -172,11 +173,6 @@ cpufreq_applet_init (CPUFreqApplet *applet)
applet->popup = NULL;
applet->monitor = NULL;
- applet->label = gtk_label_new (NULL);
- applet->unit_label = gtk_label_new (NULL);
- applet->icon = gtk_image_new ();
- applet->box = NULL;
-
applet->show_mode = CPUFREQ_MODE_BOTH;
applet->show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT;
@@ -201,6 +197,25 @@ cpufreq_applet_init (CPUFreqApplet *applet)
gtk_container_add (GTK_CONTAINER (applet), applet->container);
gtk_widget_show (applet->container);
+
+ applet->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+ gtk_container_add (GTK_CONTAINER (applet->container), applet->box);
+ gtk_widget_show (applet->box);
+
+ applet->icon = gtk_image_new ();
+ gtk_box_pack_start (GTK_BOX (applet->box), applet->icon, FALSE, FALSE, 0);
+
+ applet->labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+ gtk_box_pack_start (GTK_BOX (applet->box), applet->labels_box, FALSE, FALSE, 0);
+ gtk_widget_show (applet->labels_box);
+
+ applet->label = gtk_label_new (NULL);
+ gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->label,
+ FALSE, FALSE, 0);
+
+ applet->unit_label = gtk_label_new (NULL);
+ gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->unit_label,
+ FALSE, FALSE, 0);
}
static void
@@ -705,7 +720,6 @@ cpufreq_applet_refresh (CPUFreqApplet *applet)
gint unit_label_size, pixmap_size;
gint size_step = 12;
gboolean horizontal;
- gboolean do_unref = FALSE;
panel_size = applet->size - 1; /* 1 pixel margin */
@@ -724,52 +738,34 @@ cpufreq_applet_refresh (CPUFreqApplet *applet)
gtk_widget_get_preferred_width (GTK_WIDGET (applet->icon), &pixmap_size, NULL);
total_size += pixmap_size;
- if (applet->box) {
- do_unref = TRUE;
- g_object_ref (applet->icon);
- gtk_container_remove (GTK_CONTAINER (applet->box), applet->icon);
- if (applet->labels_box) {
- g_object_ref (applet->label);
- gtk_container_remove (GTK_CONTAINER (applet->labels_box), applet->label);
- g_object_ref (applet->unit_label);
- gtk_container_remove (GTK_CONTAINER (applet->labels_box), applet->unit_label);
+ if (horizontal) {
+ if ((label_size + pixmap_size) <= panel_size) {
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->box),
+ GTK_ORIENTATION_VERTICAL);
+ } else {
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->box),
+ GTK_ORIENTATION_HORIZONTAL);
}
- gtk_widget_destroy (applet->box);
- }
- if (horizontal) {
- applet->labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
- if ((label_size + pixmap_size) <= panel_size)
- applet->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
- else
- applet->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->labels_box),
+ GTK_ORIENTATION_HORIZONTAL);
} else {
- if (total_size <= panel_size) {
- applet->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
- applet->labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
- } else if ((label_size + unit_label_size) <= (panel_size - size_step)) {
- applet->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
- applet->labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
- } else {
- applet->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
- applet->labels_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
- }
- }
-
- gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->label, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->unit_label, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (applet->box), applet->icon, FALSE, FALSE, 0);
-
- gtk_box_pack_start (GTK_BOX (applet->box), applet->labels_box, FALSE, FALSE, 0);
- gtk_widget_show (applet->labels_box);
-
- gtk_container_add (GTK_CONTAINER (applet->container), applet->box);
- gtk_widget_show (applet->box);
-
- if (do_unref) {
- g_object_unref (applet->label);
- g_object_unref (applet->unit_label);
- g_object_unref (applet->icon);
+ if (total_size <= panel_size) {
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->box),
+ GTK_ORIENTATION_HORIZONTAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->labels_box),
+ GTK_ORIENTATION_HORIZONTAL);
+ } else if ((label_size + unit_label_size) <= (panel_size - size_step)) {
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->box),
+ GTK_ORIENTATION_VERTICAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->labels_box),
+ GTK_ORIENTATION_HORIZONTAL);
+ } else {
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->box),
+ GTK_ORIENTATION_VERTICAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (applet->labels_box),
+ GTK_ORIENTATION_VERTICAL);
+ }
}
}