~ubuntu-branches/debian/sid/openbox/sid

« back to all changes in this revision

Viewing changes to openbox/debug.c

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde, Nico Golde, Eugenio Paolantonio
  • Date: 2011-10-03 22:59:30 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20111003225930-tdvyax5tx63dyoez
Tags: 3.5.0-1
[Nico Golde]
* New upstream release (Closes: #638783).
  - Fix crashes in the menu code (Closes: #563891).
* Add Brazilian translation to openbox.desktop,
  thanks Sérgio Cipolla (Closes: #627912).
* Remove 06_fix_swap_byte_order.patch, applied upstream.
* Bump debhelper dependency to >= 7.0.50~ due to override.
* Remove CHANGELOG from openbox.docs to prevent double installation.
* Add 02_fix_freedesktop_compliance.dpatch desktop file to
  /usr/share/applications.

[Eugenio Paolantonio]
* debian/patches:
  - Disabled 03_place_windows_in_quadrants.patch
  - Updated 01_rc.xml.patch and 06_fix_swap_byte_order.patch
  - Removed 04_fix_ftbfs_no-add-needed.patch and 20_24bits_support.patch
* debian/control:
  - Added myself to the Uploaders.
  - Build-Depends: removed libxau-dev, libxft-dev and python-xdg;
    added libimlib2-dev
  - openbox Suggests: added python-xdg
  - libobrender21 renamed to libobrender27
  - libobparser21 renamed to libobt0
* debian/rules:
  - Rewrote using a simpler debhelper syntax
  - Moved the install pass to openbox.install
* debian/*.{install,links,dirs}:
  - Updated.
* debian/openbox.xsession:
  - Removed. Openbox now ships it by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
*/
18
18
 
19
19
#include "debug.h"
 
20
#include "prompt.h"
 
21
#include "openbox.h"
 
22
#include "gettext.h"
 
23
#include "obt/paths.h"
20
24
 
21
25
#include <glib.h>
22
26
#include <stdlib.h>
23
27
#include <stdarg.h>
24
28
#include <stdio.h>
25
 
 
26
 
static gboolean show;
27
 
 
28
 
void ob_debug_show_output(gboolean enable)
29
 
{
30
 
    show = enable;
31
 
}
32
 
 
33
 
void ob_debug(const gchar *a, ...)
34
 
{
35
 
    va_list vl;
36
 
 
37
 
    if (show) {
38
 
        fprintf(stderr, "DEBUG: ");
39
 
        va_start(vl, a);
40
 
        vfprintf(stderr, a, vl);
41
 
        va_end(vl);
42
 
    }
43
 
}
44
 
 
45
 
static gboolean enabled_types[OB_DEBUG_TYPE_NUM] = {FALSE};
 
29
#include <errno.h>
 
30
 
 
31
#ifdef HAVE_UNISTD_H
 
32
#  include <unistd.h>
 
33
#endif
 
34
 
 
35
static gboolean  enabled_types[OB_DEBUG_TYPE_NUM] = {FALSE};
 
36
static FILE     *log_file = NULL;
 
37
static guint     rr_handler_id = 0;
 
38
static guint     obt_handler_id = 0;
 
39
static guint     ob_handler_id = 0;
 
40
static guint     ob_handler_prompt_id = 0;
 
41
 
 
42
static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
 
43
                        const gchar *message, gpointer user_data);
 
44
static void prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
 
45
                           const gchar *message, gpointer user_data);
 
46
 
 
47
void ob_debug_startup(void)
 
48
{
 
49
    ObtPaths *p = obt_paths_new();
 
50
    gchar *dir = g_build_filename(obt_paths_cache_home(p),
 
51
                                  "openbox", NULL);
 
52
 
 
53
    /* log messages to a log file!  fancy, no? */
 
54
    if (!obt_paths_mkdir_path(dir, 0777))
 
55
        g_message(_("Unable to make directory '%s': %s"),
 
56
                  dir, g_strerror(errno));
 
57
    else {
 
58
        gchar *name = g_build_filename(obt_paths_cache_home(p),
 
59
                                       "openbox", "openbox.log", NULL);
 
60
        /* unlink it before opening to remove competition */
 
61
        unlink(name);
 
62
        log_file = fopen(name, "w");
 
63
        g_free(name);
 
64
    }
 
65
 
 
66
    rr_handler_id =
 
67
        g_log_set_handler("ObRender", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
 
68
                          G_LOG_FLAG_RECURSION, log_handler, NULL);
 
69
    obt_handler_id =
 
70
        g_log_set_handler("Obt", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
 
71
                          G_LOG_FLAG_RECURSION, log_handler, NULL);
 
72
    ob_handler_id =
 
73
        g_log_set_handler("Openbox", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
 
74
                          G_LOG_FLAG_RECURSION, log_handler, NULL);
 
75
    ob_handler_prompt_id =
 
76
        g_log_set_handler("Openbox", G_LOG_LEVEL_MASK & ~G_LOG_LEVEL_DEBUG,
 
77
                          prompt_handler, NULL);
 
78
 
 
79
    obt_paths_unref(p);
 
80
    g_free(dir);
 
81
}
 
82
 
 
83
void ob_debug_shutdown(void)
 
84
{
 
85
    g_log_remove_handler("ObRender", rr_handler_id);
 
86
    g_log_remove_handler("Obt", obt_handler_id);
 
87
    g_log_remove_handler("Openbox", ob_handler_id);
 
88
    g_log_remove_handler("Openbox", ob_handler_prompt_id);
 
89
 
 
90
    if (log_file) {
 
91
        fclose(log_file);
 
92
        log_file = NULL;
 
93
    }
 
94
}
46
95
 
47
96
void ob_debug_enable(ObDebugType type, gboolean enable)
48
97
{
50
99
    enabled_types[type] = enable;
51
100
}
52
101
 
 
102
static inline void log_print(FILE *out, const gchar* log_domain,
 
103
                             const gchar *level, const gchar *message)
 
104
{
 
105
    fprintf(out, "%s", log_domain);
 
106
    fprintf(out, "-");
 
107
    fprintf(out, "%s", level);
 
108
    fprintf(out, ": ");
 
109
    fprintf(out, "%s", message);
 
110
    fprintf(out, "\n");
 
111
    fflush(out);
 
112
}
 
113
 
 
114
static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
 
115
                        const gchar *message, gpointer data)
 
116
{
 
117
    FILE *out;
 
118
    const gchar *level;
 
119
 
 
120
    switch (log_level & G_LOG_LEVEL_MASK) {
 
121
    case G_LOG_LEVEL_DEBUG:    level = "Debug";    out = stdout; break;
 
122
    case G_LOG_LEVEL_INFO:     level = "Info";     out = stdout; break;
 
123
    case G_LOG_LEVEL_MESSAGE:  level = "Message";  out = stdout; break;
 
124
    case G_LOG_LEVEL_WARNING:  level = "Warning";  out = stderr; break;
 
125
    case G_LOG_LEVEL_CRITICAL: level = "Critical"; out = stderr; break;
 
126
    case G_LOG_LEVEL_ERROR:    level = "Error";    out = stderr; break;
 
127
    default:                   g_assert_not_reached(); /* invalid level.. */
 
128
    }
 
129
 
 
130
    log_print(out, log_domain, level, message);
 
131
    if (log_file) log_print(log_file, log_domain, level, message);
 
132
}
 
133
 
 
134
static void prompt_handler(const gchar *log_domain, GLogLevelFlags log_level,
 
135
                           const gchar *message, gpointer data)
 
136
{
 
137
    if (ob_state() == OB_STATE_RUNNING)
 
138
        prompt_show_message(message, "Openbox", _("Close"));
 
139
    else
 
140
        log_handler(log_domain, log_level, message, data);
 
141
}
 
142
 
 
143
static inline void log_argv(ObDebugType type,
 
144
                            const gchar *format, va_list args)
 
145
{
 
146
    const gchar *prefix;
 
147
    gchar *message;
 
148
 
 
149
    g_assert(type < OB_DEBUG_TYPE_NUM);
 
150
    if (!enabled_types[type]) return;
 
151
 
 
152
    switch (type) {
 
153
    case OB_DEBUG_FOCUS:    prefix = "(FOCUS) ";           break;
 
154
    case OB_DEBUG_APP_BUGS: prefix = "(APPLICATION BUG) "; break;
 
155
    case OB_DEBUG_SM:       prefix = "(SESSION) ";         break;
 
156
    default:                prefix = NULL;                 break;
 
157
    }
 
158
 
 
159
    message = g_strdup_vprintf(format, args);
 
160
    if (prefix) {
 
161
        gchar *a = message;
 
162
        message = g_strconcat(prefix, message, NULL);
 
163
        g_free(a);
 
164
    }
 
165
 
 
166
    g_debug("%s", message);
 
167
    g_free(message);
 
168
}
 
169
 
 
170
void ob_debug(const gchar *a, ...)
 
171
{
 
172
    va_list vl;
 
173
 
 
174
    va_start(vl, a);
 
175
    log_argv(OB_DEBUG_NORMAL, a, vl);
 
176
    va_end(vl);
 
177
}
 
178
 
53
179
void ob_debug_type(ObDebugType type, const gchar *a, ...)
54
180
{
55
181
    va_list vl;
56
182
 
57
 
    g_assert(type < OB_DEBUG_TYPE_NUM);
58
 
 
59
 
    if (show && enabled_types[type]) {
60
 
        switch (type) {
61
 
        case OB_DEBUG_FOCUS:
62
 
            fprintf(stderr, "FOCUS: ");
63
 
            break;
64
 
        case OB_DEBUG_APP_BUGS:
65
 
            fprintf(stderr, "APPLICATION BUG: ");
66
 
            break;
67
 
        case OB_DEBUG_SM:
68
 
            fprintf(stderr, "SESSION: ");
69
 
            break;
70
 
        default:
71
 
            g_assert_not_reached();
72
 
        }
73
 
 
74
 
        va_start(vl, a);
75
 
        vfprintf(stderr, a, vl);
76
 
        va_end(vl);
77
 
    }
 
183
    va_start(vl, a);
 
184
    log_argv(type, a, vl);
 
185
    va_end(vl);
78
186
}