From: Dana Jansens Date: Fri, 14 Oct 2011 23:53:06 +0000 (-0400) Subject: Add an action for toggling debug output. X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=4597db12831ce0b712d261d656fc379c21208c05;p=dana%2Fopenbox.git Add an action for toggling debug output. - Rename "Debug" action to "Print" for displaying text. - Add "Debug" action that sets/toggles showing debug messages. It has the standard set: argument where is on/off/toggle. --- diff --git a/openbox/actions/debug.c b/openbox/actions/debug.c index 90b57b66..3b2ce4c7 100644 --- a/openbox/actions/debug.c +++ b/openbox/actions/debug.c @@ -1,30 +1,44 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- */ + #include "openbox/action.h" #include "openbox/action_list_run.h" #include "openbox/config_value.h" #include "openbox/client_set.h" +#include "openbox/debug.h" #include typedef struct { gchar *str; -} Options; +} PrintOptions; + +typedef struct { + gboolean toggle; + gboolean set; +} DebugOptions; -static gpointer setup_func(GHashTable *config); -static void free_func(gpointer options); -static gboolean run_func(const ObClientSet *set, - const ObActionListRun *data, gpointer options); +static gpointer setup_print_func(GHashTable *config); +static void free_print_func(gpointer options); +static gboolean run_print_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); +static gpointer setup_debug_func(GHashTable *config); +static void free_debug_func(gpointer options); +static gboolean run_debug_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options); void action_debug_startup(void) { + action_register("Print", OB_ACTION_DEFAULT_FILTER_EMPTY, + setup_print_func, free_print_func, run_print_func); action_register("Debug", OB_ACTION_DEFAULT_FILTER_EMPTY, - setup_func, free_func, run_func); + setup_debug_func, free_debug_func, run_debug_func); } -static gpointer setup_func(GHashTable *config) +static gpointer setup_print_func(GHashTable *config) { ObConfigValue *v; - Options *o; + PrintOptions *o; - o = g_slice_new0(Options); + o = g_slice_new0(PrintOptions); v = g_hash_table_lookup(config, "string"); if (v && config_value_is_string(v)) @@ -32,20 +46,57 @@ static gpointer setup_func(GHashTable *config) return o; } -static void free_func(gpointer options) +static void free_print_func(gpointer options) { - Options *o = options; + PrintOptions *o = options; g_free(o->str); - g_slice_free(Options, o); + g_slice_free(PrintOptions, o); } /* Always return FALSE because its not interactive */ -static gboolean run_func(const ObClientSet *set, +static gboolean run_print_func(const ObClientSet *set, const ObActionListRun *data, gpointer options) { - Options *o = options; - + PrintOptions *o = options; if (o->str) g_print("%s\n", o->str); - return FALSE; } + +static gpointer setup_debug_func(GHashTable *config) +{ + ObConfigValue *v; + DebugOptions *o; + + o = g_slice_new0(DebugOptions); + o->toggle = TRUE; + o->set = TRUE; + + v = g_hash_table_lookup(config, "set"); + if (v && config_value_is_string(v)) { + const gchar *s = config_value_string(v); + if (!g_ascii_strcasecmp(s, "on")) + o->toggle = FALSE; + else if (!g_ascii_strcasecmp(s, "off")) { + o->toggle = FALSE; + o->set = FALSE; + } + } + + return o; +} + +static void free_debug_func(gpointer o) +{ + g_slice_free(DebugOptions, o); +} + +/* Always return FALSE because its not interactive */ +static gboolean run_debug_func(const ObClientSet *set, + const ObActionListRun *data, gpointer options) +{ + gboolean toggle = !ob_debug_get_enabled(OB_DEBUG_NORMAL); + if (!toggle) ob_debug("Debugging output disabled"); + ob_debug_enable(OB_DEBUG_NORMAL, toggle); + if (toggle) ob_debug("Debugging output enabled"); + return FALSE; +} diff --git a/openbox/debug.c b/openbox/debug.c index ad083b17..4c66f964 100644 --- a/openbox/debug.c +++ b/openbox/debug.c @@ -101,6 +101,12 @@ void ob_debug_enable(ObDebugType type, gboolean enable) enabled_types[type] = enable; } +gboolean ob_debug_get_enabled(ObDebugType type) +{ + g_assert(type < OB_DEBUG_TYPE_NUM); + return enabled_types[type]; +} + static inline void log_print(FILE *out, const gchar* log_domain, const gchar *level, const gchar *message) { diff --git a/openbox/debug.h b/openbox/debug.h index 13c55988..eafd223b 100644 --- a/openbox/debug.h +++ b/openbox/debug.h @@ -38,6 +38,8 @@ void ob_debug_type(ObDebugType type, const gchar *a, ...); void ob_debug_enable(ObDebugType type, gboolean enable); +gboolean ob_debug_get_enabled(ObDebugType type); + void ob_debug_show_prompts(void); #endif