shithub: puzzles

Download patch

ref: d44034bcf699661a11b587c884365a8aa4d6bd39
parent: 3d8e7585b7a9d215e4b40d9f83f7fa5a0fd79b43
author: Simon Tatham <anakin@pobox.com>
date: Wed Apr 28 08:34:37 EDT 2004

More robust timer handling in GTK: never create a new timer when one
is already active.

[originally from svn r4159]

--- a/gtk.c
+++ b/gtk.c
@@ -52,7 +52,7 @@
     midend_data *me;
     GdkGC *gc;
     int bbox_l, bbox_r, bbox_u, bbox_d;
-    int timer_active;
+    int timer_active, timer_id;
 };
 
 void frontend_default_colour(frontend *fe, float *output)
@@ -233,12 +233,15 @@
 
 void deactivate_timer(frontend *fe)
 {
+    if (fe->timer_active)
+        gtk_timeout_remove(fe->timer_id);
     fe->timer_active = FALSE;
 }
 
 void activate_timer(frontend *fe)
 {
-    gtk_timeout_add(20, timer_func, fe);
+    if (!fe->timer_active)
+        fe->timer_id = gtk_timeout_add(20, timer_func, fe);
     fe->timer_active = TRUE;
 }
 
@@ -389,6 +392,8 @@
     gtk_box_pack_end(vbox, fe->area, FALSE, FALSE, 0);
 
     fe->pixmap = NULL;
+
+    fe->timer_active = FALSE;
 
     gtk_signal_connect(GTK_OBJECT(fe->window), "destroy",
 		       GTK_SIGNAL_FUNC(destroy), fe);