[gtk+] widget-factory: Don't pulse dead widgets
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] widget-factory: Don't pulse dead widgets
- Date: Fri, 19 Dec 2014 18:50:55 +0000 (UTC)
commit f0a40b1a2365e3357803342c29b89d215a1efe79
Author: Benjamin Otte <otte redhat com>
Date: Tue Dec 16 19:10:53 2014 +0100
widget-factory: Don't pulse dead widgets
Causes crashes at cleanup and we don't want those.
Also, code gets simpler.
demos/widget-factory/widget-factory.c | 25 ++++++++++---------------
1 files changed, 10 insertions(+), 15 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 4829925..c4542d9 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -159,6 +159,12 @@ spin_value_reset (GtkWidget *button, GtkAdjustment *adjustment)
static gint pulse_time = 250;
static gint pulse_entry_mode = 0;
+static void
+remove_pulse (gpointer pulse_id)
+{
+ g_source_remove (GPOINTER_TO_UINT (pulse_id));
+}
+
static gboolean
pulse_it (GtkWidget *widget)
{
@@ -170,7 +176,7 @@ pulse_it (GtkWidget *widget)
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (widget));
pulse_id = g_timeout_add (pulse_time, (GSourceFunc)pulse_it, widget);
- g_object_set_data (G_OBJECT (widget), "pulse_id", GUINT_TO_POINTER (pulse_id));
+ g_object_set_data_full (G_OBJECT (widget), "pulse_id", GUINT_TO_POINTER (pulse_id), remove_pulse);
return G_SOURCE_REMOVE;
}
@@ -190,18 +196,14 @@ update_pulse_time (GtkAdjustment *adjustment, GtkWidget *widget)
if (value == 100)
{
- if (pulse_id != 0)
- {
- g_source_remove (pulse_id);
- g_object_set_data (G_OBJECT (widget), "pulse_id", NULL);
- }
+ g_object_set_data (G_OBJECT (widget), "pulse_id", NULL);
}
else if (value < 100)
{
if (pulse_id == 0 && (GTK_IS_PROGRESS_BAR (widget) || pulse_entry_mode % 3 == 2))
{
pulse_id = g_timeout_add (pulse_time, (GSourceFunc)pulse_it, widget);
- g_object_set_data (G_OBJECT (widget), "pulse_id", GUINT_TO_POINTER (pulse_id));
+ g_object_set_data_full (G_OBJECT (widget), "pulse_id", GUINT_TO_POINTER (pulse_id), remove_pulse);
}
}
}
@@ -212,8 +214,6 @@ on_entry_icon_release (GtkEntry *entry,
GdkEvent *event,
gpointer user_data)
{
- guint pulse_id;
-
if (icon_pos != GTK_ENTRY_ICON_SECONDARY)
return;
@@ -221,12 +221,7 @@ on_entry_icon_release (GtkEntry *entry,
if (pulse_entry_mode % 3 == 0)
{
- pulse_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (entry), "pulse_id"));
- if (pulse_id != 0)
- {
- g_source_remove (pulse_id);
- g_object_set_data (G_OBJECT (entry), "pulse_id", NULL);
- }
+ g_object_set_data (G_OBJECT (entry), "pulse_id", NULL);
gtk_entry_set_progress_fraction (entry, 0);
}
else if (pulse_entry_mode % 3 == 1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]