[hitori] Pause the timer when the window's minimised



commit 87a9e89c87623f721556b7e6dc5f78873a08228f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Oct 31 12:28:11 2010 +0000

    Pause the timer when the window's minimised

 data/hitori.ui  |    1 +
 src/interface.c |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/data/hitori.ui b/data/hitori.ui
index d4d75d8..00a7ee0 100644
--- a/data/hitori.ui
+++ b/data/hitori.ui
@@ -168,6 +168,7 @@
 	<object class="GtkWindow" id="hitori_main_window">
 		<property name="title" translatable="yes">Hitori</property>
 		<signal name="destroy" handler="hitori_destroy_cb"/>
+		<signal name="window-state-event" handler="hitori_window_state_event_cb"/>
 		<child>
 			<object class="GtkVBox" id="vbox1">
 				<child>
diff --git a/src/interface.c b/src/interface.c
index 516291e..78c0157 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -40,6 +40,7 @@
 gboolean hitori_draw_cb (GtkWidget *drawing_area, cairo_t *cr, Hitori *hitori);
 gboolean hitori_button_release_cb (GtkWidget *drawing_area, GdkEventButton *event, Hitori *hitori);
 void hitori_destroy_cb (GtkWindow *window, Hitori *hitori);
+void hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hitori *hitori);
 void hitori_new_game_cb (GtkAction *action, Hitori *hitori);
 void hitori_hint_cb (GtkAction *action, Hitori *hitori);
 void hitori_undo_cb (GtkAction *action, Hitori *hitori);
@@ -305,6 +306,23 @@ hitori_destroy_cb (GtkWindow *window, Hitori *hitori)
 }
 
 void
+hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hitori *hitori)
+{
+	if (hitori->debug)
+		g_debug ("Got window state event: %u (changed: %u)", event->new_window_state, event->changed_mask);
+
+	if (event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN ||
+	    event->new_window_state & GDK_WINDOW_STATE_ICONIFIED ||
+	    event->new_window_state & GDK_WINDOW_STATE_BELOW) {
+		/* Pause the timer */
+		hitori_pause_timer (hitori);
+	} else {
+		/* Re-start the timer */
+		hitori_start_timer (hitori);
+	}
+}
+
+void
 hitori_new_game_cb (GtkAction *action, Hitori *hitori)
 {
 	hitori_new_game (hitori, hitori->board_size);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]