[Xfce4-commits] [panel-plugins/xfce4-timer-plugin] 03/03: Do not recreate box when orientation changes
noreply at xfce.org
noreply at xfce.org
Sat Nov 2 22:45:40 CET 2019
This is an automated email from the git hooks/post-receive script.
a n d r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-timer-plugin.
commit 1cf7ba2f2f8283315f59f50bdc9be14a47142d49
Author: Andre Miranda <andreldm at xfce.org>
Date: Sat Nov 2 18:44:58 2019 -0300
Do not recreate box when orientation changes
And avoid mem leaks
---
panel-plugin/xfcetimer.c | 68 ++++++++++++++++--------------------------------
1 file changed, 22 insertions(+), 46 deletions(-)
diff --git a/panel-plugin/xfcetimer.c b/panel-plugin/xfcetimer.c
index 58e5ec6..73f1194 100644
--- a/panel-plugin/xfcetimer.c
+++ b/panel-plugin/xfcetimer.c
@@ -1078,65 +1078,42 @@ down_clicked (GtkButton *button, gpointer data)
-/**
- * Adds the progressbar, taking into account the orientation
- * pd->pbar is not destroyed, just reparented (saves fraction setting code etc.).
- **/
static void
-add_pbar (XfcePanelPlugin *plugin, plugin_data *pd)
+update_pbar_orientation (XfcePanelPlugin *plugin, plugin_data *pd)
{
-
- gdouble frac;
-
- gtk_widget_hide (GTK_WIDGET (plugin));
-
- /* Always true except at initialization */
- if (pd->box)
- {
- frac = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (pd->pbar));
- gtk_widget_destroy (pd->box);
- pd->pbar = gtk_progress_bar_new ();
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pd->pbar), frac);
- }
-
- /* vertical bar */
if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL)
{
+ /* vertical bar */
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (pd->box),
+ GTK_ORIENTATION_HORIZONTAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (pd->pbar),
+ GTK_ORIENTATION_VERTICAL);
gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR (pd->pbar), TRUE);
-
- pd->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_halign (GTK_WIDGET (pd->pbar), GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (GTK_WIDGET (pd->pbar), TRUE);
- gtk_container_set_border_width (GTK_CONTAINER (pd->box), BORDER / 2);
- gtk_container_add (GTK_CONTAINER (plugin), pd->box);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (pd->pbar),
- GTK_ORIENTATION_VERTICAL);
- gtk_box_pack_start (GTK_BOX (pd->box), pd->pbar, FALSE, FALSE, 0);
-
}
else
- { /* horizontal bar */
- pd->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_set_valign (GTK_WIDGET (pd->pbar), GTK_ALIGN_CENTER);
- gtk_widget_set_vexpand (GTK_WIDGET (pd->pbar), TRUE);
- gtk_container_set_border_width (GTK_CONTAINER (pd->box), BORDER / 2);
- gtk_container_add (GTK_CONTAINER (plugin), pd->box);
+ {
+ /* horizontal bar */
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (pd->box),
+ GTK_ORIENTATION_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (pd->pbar),
GTK_ORIENTATION_HORIZONTAL);
- gtk_box_pack_start (GTK_BOX (pd->box), pd->pbar, FALSE, FALSE, 0);
+ gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR (pd->pbar), FALSE);
+ gtk_widget_set_valign (GTK_WIDGET (pd->pbar), GTK_ALIGN_CENTER);
+ gtk_widget_set_hexpand (GTK_WIDGET (pd->pbar), FALSE);
}
- gtk_widget_show_all (GTK_WIDGET (plugin));
}
-/* Callback for orientation change of panel, just calls add_pbar */
+/* Callback for orientation change of panel */
static void
orient_change (XfcePanelPlugin *plugin, GtkOrientation orient, plugin_data *pd)
{
- add_pbar (plugin, pd);
+ update_pbar_orientation (plugin, pd);
}
@@ -1227,7 +1204,7 @@ load_settings (plugin_data *pd)
10);
}
- add_pbar (pd->base, pd);
+ update_pbar_orientation (pd->base, pd);
xfce_rc_close (rc);
}
@@ -1745,7 +1722,6 @@ Cheng-Chia Tseng <pswo10680 at gmail.com>\n";
static void
create_plugin_control (XfcePanelPlugin *plugin)
{
-
gchar *filename, *pathname;
plugin_data *pd = g_new0 (plugin_data, 1);
GList *list = NULL;
@@ -1760,7 +1736,7 @@ create_plugin_control (XfcePanelPlugin *plugin)
G_TYPE_STRING, /* Column 1: Name */
G_TYPE_STRING, /* Column 2: Timer period/alarm time - info string */
G_TYPE_STRING); /* Command to run */
- pd->box = NULL;
+ pd->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
pd->buttonadd = NULL;
pd->buttonedit = NULL;
pd->buttonremove = NULL;
@@ -1800,13 +1776,13 @@ create_plugin_control (XfcePanelPlugin *plugin)
list = g_list_next (list);
}
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pd->pbar), 0);
+ gtk_container_set_border_width (GTK_CONTAINER (pd->box), BORDER / 2);
+ gtk_container_add (GTK_CONTAINER (plugin), pd->box);
- add_pbar (pd->base, pd);
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pd->pbar), 0);
+ gtk_box_pack_start (GTK_BOX (pd->box), pd->pbar, FALSE, FALSE, 0);
- /* Trying to get a thin box, but no way */
- gtk_widget_set_size_request (GTK_WIDGET (plugin), 10, 10);
- xfce_panel_plugin_set_expand (plugin, FALSE);
+ update_pbar_orientation (pd->base, pd);
g_signal_connect (G_OBJECT (plugin), "button_press_event",
G_CALLBACK (pbar_clicked), pd);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list