[gnome-nibbles] Pause game when viewing preferences or scores



commit 35e8c481bfa71261acfc9ccdb150487403b59943
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Fri Feb 27 23:36:56 2015 +0200

    Pause game when viewing preferences or scores
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737051

 src/gnibbles.c    |    2 ++
 src/main.c        |   37 ++++++++++++++++++++++++++++++++++++-
 src/main.h        |    3 +++
 src/preferences.c |    2 ++
 4 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/src/gnibbles.c b/src/gnibbles.c
index 20053d2..975cba8 100644
--- a/src/gnibbles.c
+++ b/src/gnibbles.c
@@ -357,6 +357,8 @@ gnibbles_show_scores (GtkWidget * window, gint pos)
   }
 
   gtk_dialog_run (GTK_DIALOG (scoresdialog));
+  if (menu_item_opened)
+    menu_item_pause_toggle ();
   gtk_widget_hide (scoresdialog);
 }
 
diff --git a/src/main.c b/src/main.c
index c2b4aeb..3859968 100644
--- a/src/main.c
+++ b/src/main.c
@@ -92,6 +92,7 @@ gint restart_id = 0;
 gint current_level;
 
 gboolean is_paused;
+gboolean menu_item_opened = FALSE;
 static gboolean new_game_2_cb (GtkWidget * widget, gpointer data);
 
 static gint add_bonus_cb (gpointer data);
@@ -101,7 +102,7 @@ static GSimpleAction *pause_action;
 gint
 game_running (void)
 {
-  return (main_id || dummy_id || restart_id || is_paused);
+  return (main_id || dummy_id || restart_id || is_paused || menu_item_opened);
 }
 
 /* Avoid a race condition where a redraw is attempted
@@ -162,6 +163,36 @@ change_pause_state (GSimpleAction *action,
   g_simple_action_set_state (action, g_variant_new_boolean (is_paused));
 }
 
+void
+menu_item_pause_toggle (void)
+{
+
+  if (!g_action_get_enabled (G_ACTION (pause_action)))
+    return;
+
+  if (!menu_item_opened) {
+    menu_item_opened = TRUE;
+    if (main_id || restart_id || dummy_id) {
+      if (main_id) {
+        g_source_remove (main_id);
+        main_id = 0;
+      }
+      if (keyboard_id) {
+        g_signal_handler_disconnect (G_OBJECT (stage), keyboard_id);
+        keyboard_id = 0;
+      }
+      if (add_bonus_id) {
+        g_source_remove (add_bonus_id);
+        add_bonus_id = 0;
+      }
+    }
+  }
+  else {
+    menu_item_opened = FALSE;
+    if (!is_paused)
+      dummy_id = g_timeout_add (500, (GSourceFunc) new_game_2_cb, NULL);
+  }
+}
 
 static void
 newgame_activated (GSimpleAction *action,
@@ -176,6 +207,8 @@ scores_activated (GSimpleAction *action,
                 GVariant      *parameter,
                 gpointer       user_data)
 {
+  if (!menu_item_opened)
+    menu_item_pause_toggle ();
   gnibbles_show_scores (window, 0);
 }
 
@@ -184,6 +217,8 @@ preferences_activated (GSimpleAction *action,
                 GVariant      *parameter,
                 gpointer       user_data)
 {
+  if (!menu_item_opened)
+    menu_item_pause_toggle ();
   gnibbles_preferences_cb (window, user_data);
 }
 
diff --git a/src/main.h b/src/main.h
index 62f9687..053f6b8 100644
--- a/src/main.h
+++ b/src/main.h
@@ -34,6 +34,9 @@ int num_players;
 int seat;
 int seats[NUMWORMS];
 char names[NUMWORMS][17];
+extern gboolean menu_item_opened;
+
+void menu_item_pause_toggle (void);
 
 gboolean game_running (void);
 void end_game (void);
diff --git a/src/preferences.c b/src/preferences.c
index 31f32bf..ee48858 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -46,6 +46,8 @@ GtkWidget *num_human, *num_ai;
 static void
 destroy_cb (GtkWidget * widget, gpointer data)
 {
+  if (menu_item_opened)
+    menu_item_pause_toggle ();
   pref_dialog = NULL;
 }
 


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