*/
#include "debug.h"
+#include "prompt.h"
+#include "openbox.h"
#include "gettext.h"
#include "obt/paths.h"
#include <stdio.h>
#include <errno.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
static gboolean enabled_types[OB_DEBUG_TYPE_NUM] = {FALSE};
static FILE *log_file = NULL;
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 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 prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data);
void ob_debug_startup(void)
{
ob_handler_id =
g_log_set_handler("Openbox", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
G_LOG_FLAG_RECURSION, log_handler, NULL);
+ ob_handler_prompt_id =
+ g_log_set_handler("Openbox", G_LOG_LEVEL_MASK & ~G_LOG_LEVEL_DEBUG,
+ prompt_handler, NULL);
obt_paths_unref(p);
g_free(dir);
g_log_remove_handler("ObRender", rr_handler_id);
g_log_remove_handler("Obt", obt_handler_id);
g_log_remove_handler("Openbox", ob_handler_id);
+ g_log_remove_handler("Openbox", ob_handler_prompt_id);
if (log_file) {
fclose(log_file);
static inline void log_print(FILE *out, const gchar* log_domain,
const gchar *level, const gchar *message)
{
- fprintf(out, log_domain);
+ fprintf(out, "%s", log_domain);
fprintf(out, "-");
- fprintf(out, level);
+ fprintf(out, "%s", level);
fprintf(out, ": ");
- fprintf(out, message);
+ fprintf(out, "%s", message);
fprintf(out, "\n");
fflush(out);
}
if (log_file) log_print(log_file, log_domain, level, message);
}
+static void prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer data)
+{
+ 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);
+}
+
static inline void log_argv(ObDebugType type,
const gchar *format, va_list args)
{
g_free(a);
}
- g_debug(message);
+ g_debug("%s", message);
g_free(message);
}
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;
+ }
+}