[hitori] core: Fix timer pausing when winning the game
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hitori] core: Fix timer pausing when winning the game
- Date: Fri, 2 Aug 2013 08:39:12 +0000 (UTC)
commit be2ba012e75546b09e9938b7386adbd721a9cab8
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Aug 2 10:38:24 2013 +0200
core: Fix timer pausing when winning the game
The ‘congratulations’ dialogue was changing the focus state of the main window
which was causing the timer to get un-paused after winning.
src/interface.c | 14 ++++++++++----
src/main.c | 4 +++-
2 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/interface.c b/src/interface.c
index a9128a2..eb5a40c 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -381,15 +381,21 @@ hitori_destroy_cb (GtkWindow *window, Hitori *hitori)
void
hitori_window_state_event_cb (GtkWindow *window, GdkEventWindowState *event, Hitori *hitori)
{
+ gboolean timer_was_running = FALSE;
+
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) {
+ timer_was_running = (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window),
"hitori-timer-was-running")) > 0) ? TRUE : FALSE;
+
+ if (!(event->new_window_state & GDK_WINDOW_STATE_FOCUSED)) {
/* Pause the timer */
+ if (hitori->timeout_id > 0) {
+ g_object_set_data (G_OBJECT (window), "hitori-timer-was-running", GUINT_TO_POINTER
((hitori->timeout_id > 0) ? TRUE : FALSE));
+ }
+
hitori_pause_timer (hitori);
- } else {
+ } else if (timer_was_running == TRUE) {
/* Re-start the timer */
hitori_start_timer (hitori);
}
diff --git a/src/main.c b/src/main.c
index 45d2804..56c3b1b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -395,8 +395,10 @@ hitori_start_timer (Hitori *hitori)
void
hitori_pause_timer (Hitori *hitori)
{
- if (hitori->timeout_id > 0)
+ if (hitori->timeout_id > 0) {
g_source_remove (hitori->timeout_id);
+ hitori->timeout_id = 0;
+ }
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]