Don't show prompts inside the message handler to prevent recursion
authorDana Jansens <danakj@orodu.net>
Thu, 6 Oct 2011 14:03:52 +0000 (10:03 -0400)
committerDana Jansens <danakj@orodu.net>
Thu, 6 Oct 2011 16:01:30 +0000 (12:01 -0400)
Showing prompts causes messages to be created which causes the glib message
handler to abort().  Save the messages and show them when done all other
processing for the current event.

openbox/debug.c
openbox/debug.h
openbox/event.c

index 358b090..ad083b1 100644 (file)
@@ -38,6 +38,8 @@ static guint     rr_handler_id = 0;
 static guint     obt_handler_id = 0;
 static guint     ob_handler_id = 0;
 static guint     ob_handler_prompt_id = 0;
 static guint     obt_handler_id = 0;
 static guint     ob_handler_id = 0;
 static guint     ob_handler_prompt_id = 0;
+static GList    *prompt_queue = NULL;
+static gboolean  allow_prompts = TRUE;
 
 static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
                         const gchar *message, gpointer user_data);
 
 static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
                         const gchar *message, gpointer user_data);
@@ -134,8 +136,8 @@ static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
 static void prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
                            const gchar *message, gpointer data)
 {
 static void prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
                            const gchar *message, gpointer data)
 {
-    if (ob_state() == OB_STATE_RUNNING)
-        prompt_show_message(message, "Openbox", _("Close"));
+    if (ob_state() == OB_STATE_RUNNING && allow_prompts)
+        prompt_queue = g_list_prepend(prompt_queue, g_strdup(message));
     else
         log_handler(log_domain, log_level, message, data);
 }
     else
         log_handler(log_domain, log_level, message, data);
 }
@@ -184,3 +186,16 @@ void ob_debug_type(ObDebugType type, const gchar *a, ...)
     log_argv(type, a, vl);
     va_end(vl);
 }
     log_argv(type, a, vl);
     va_end(vl);
 }
+
+void ob_debug_show_prompts(void)
+{
+    if (prompt_queue) {
+        allow_prompts = FALSE; /* avoid recursive prompts */
+        while (prompt_queue) {
+            prompt_show_message(prompt_queue->data, "Openbox", _("Close"));
+            g_free(prompt_queue->data);
+            prompt_queue = g_list_delete_link(prompt_queue, prompt_queue);
+        }
+        allow_prompts = TRUE;
+    }
+}
index a24e66e..13c5598 100644 (file)
@@ -38,4 +38,6 @@ void ob_debug_type(ObDebugType type, const gchar *a, ...);
 
 void ob_debug_enable(ObDebugType type, gboolean enable);
 
 
 void ob_debug_enable(ObDebugType type, gboolean enable);
 
+void ob_debug_show_prompts(void);
+
 #endif
 #endif
index ba156da..b9ec1c5 100644 (file)
@@ -736,6 +736,9 @@ static void event_process(const XEvent *ec, gpointer data)
             used = event_handle_prompt(prompt, e);
     }
 
             used = event_handle_prompt(prompt, e);
     }
 
+    /* show any debug prompts that are queued */
+    ob_debug_show_prompts();
+
     /* if something happens and it's not from an XEvent, then we don't know
        the time, so clear it here until the next event is handled */
     event_curtime = event_sourcetime = CurrentTime;
     /* if something happens and it's not from an XEvent, then we don't know
        the time, so clear it here until the next event is handled */
     event_curtime = event_sourcetime = CurrentTime;