Print logging output consistently to stderr
jump to
@@ -68,7 +68,7 @@ static struct uevent_notify psy_change = {UEVENT_CHANGE, "power_supply", NULL, uevent_battery_update};
static void uevent_battery_plug() { - printf("reinitialize batteries after HW change\n"); + fprintf(stderr, "reinitialize batteries after HW change\n"); reinit_battery(); } static struct uevent_notify psy_plug = {UEVENT_ADD | UEVENT_REMOVE, "power_supply", NULL, uevent_battery_plug};
@@ -18,16 +18,17 @@ #include "version.h"
void print_usage() { - printf("Usage: tint2 [OPTION...]\n" - "\n" - "Options:\n" - " -c path_to_config_file Loads the configuration file from a\n" - " custom location.\n" - " -v, --version Prints version information and exits.\n" - " -h, --help Display this help and exits.\n" - "\n" - "For more information, run `man tint2` or visit the project page\n" - "<https://gitlab.com/o9000/tint2>.\n"); + fprintf(stdout, + "Usage: tint2 [OPTION...]\n" + "\n" + "Options:\n" + " -c path_to_config_file Loads the configuration file from a\n" + " custom location.\n" + " -v, --version Prints version information and exits.\n" + " -h, --help Display this help and exits.\n" + "\n" + "For more information, run `man tint2` or visit the project page\n" + "<https://gitlab.com/o9000/tint2>.\n"); } void handle_cli_arguments(int argc, char **argv)@@ -39,7 +40,7 @@ if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_usage(); exit(0); } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { - printf("tint2 version %s\n", VERSION_STRING); + fprintf(stdout, "tint2 version %s\n", VERSION_STRING); exit(0); } else if (strcmp(argv[i], "-c") == 0) { if (i + 1 < argc) {
@@ -126,14 +126,14 @@ // lang_index_default is a constant that encodes the Name key without a language
int lang_index_default = 1; #define LANG_DBG 0 if (LANG_DBG) - printf("Languages:"); + fprintf(stderr, "Languages:"); for (int i = 0; languages[i]; i++) { lang_index_default = i + 1; if (LANG_DBG) - printf(" %s", languages[i]); + fprintf(stderr, " %s", languages[i]); } if (LANG_DBG) - printf("\n"); + fprintf(stderr, "\n"); // we currently do not know about any Name key at all, so use an invalid index int lang_index_name = lang_index_default + 1; int lang_index_generic_name = lang_index_default + 1;@@ -281,7 +281,7 @@ {
fprintf(stdout, "\033[1;33m"); DesktopEntry entry; read_desktop_file("/usr/share/applications/firefox.desktop", &entry); - printf("Name:%s GenericName:%s Icon:%s Exec:%s\n", entry.name, entry.generic_name, entry.icon, entry.exec); + fprintf(stderr, "Name:%s GenericName:%s Icon:%s Exec:%s\n", entry.name, entry.generic_name, entry.icon, entry.exec); fprintf(stdout, "\033[0m"); }
@@ -330,19 +330,19 @@ {
fprintf(stdout, "\033[1;33m"); IconTheme *theme = load_theme("oxygen"); if (!theme) { - printf("Could not load theme\n"); + fprintf(stderr, "Could not load theme\n"); return; } - printf("Loaded theme: %s\n", theme->name); + fprintf(stderr, "Loaded theme: %s\n", theme->name); GSList *item = theme->list_inherits; while (item != NULL) { - printf("Inherits:%s\n", (char *)item->data); + fprintf(stderr, "Inherits:%s\n", (char *)item->data); item = g_slist_next(item); } item = theme->list_directories; while (item != NULL) { IconThemeDir *dir = item->data; - printf("Dir:%s Size=%d MinSize=%d MaxSize=%d Threshold=%d Type=%s\n", + fprintf(stderr, "Dir:%s Size=%d MinSize=%d MaxSize=%d Threshold=%d Type=%s\n", dir->name, dir->size, dir->min_size,@@ -623,10 +623,10 @@ file_name[0] = 0;
// filename = directory/$(themename)/subdirectory/iconname.extension sprintf(file_name, "%s/%s/%s/%s%s", base_name, theme_name, dir_name, icon_name, extension); if (debug_icons) - printf("Checking %s\n", file_name); + fprintf(stderr, "Checking %s\n", file_name); if (g_file_test(file_name, G_FILE_TEST_EXISTS)) { if (debug_icons) - printf("Found potential match: %s\n", file_name); + fprintf(stderr, "Found potential match: %s\n", file_name); // Closest match if (directory_size_distance((IconThemeDir *)dir->data, size) < minimal_size && (!best_file_theme ? 1 : theme == best_file_theme)) {@@ -638,7 +638,7 @@ best_file_name = strdup(file_name);
minimal_size = directory_size_distance((IconThemeDir *)dir->data, size); best_file_theme = theme; if (debug_icons) - printf("best_file_name = %s; minimal_size = %d\n", best_file_name, minimal_size); + fprintf(stderr, "best_file_name = %s; minimal_size = %d\n", best_file_name, minimal_size); } // Next larger match if (((IconThemeDir *)dir->data)->size >= size &&@@ -652,7 +652,7 @@ next_larger = strdup(file_name);
next_larger_size = ((IconThemeDir *)dir->data)->size; next_larger_theme = theme; if (debug_icons) - printf("next_larger = %s; next_larger_size = %d\n", next_larger, next_larger_size); + fprintf(stderr, "next_larger = %s; next_larger_size = %d\n", next_larger, next_larger_size); } } }@@ -683,10 +683,10 @@ file_name = calloc(strlen(base_name) + strlen(icon_name) + strlen(extension) + 100, 1);
// filename = directory/iconname.extension sprintf(file_name, "%s/%s%s", base_name, icon_name, extension); if (debug_icons) - printf("Checking %s\n", file_name); + fprintf(stderr, "Checking %s\n", file_name); if (g_file_test(file_name, G_FILE_TEST_EXISTS)) { if (debug_icons) - printf("Found %s\n", file_name); + fprintf(stderr, "Found %s\n", file_name); g_slist_free(extensions); return file_name; } else {
@@ -297,7 +297,7 @@ i++;
launcherIcon->y = posy; launcherIcon->x = posx; launcher_icon_on_change_layout(launcherIcon); - // printf("launcher %d : %d,%d\n", i, posx, posy); + // fprintf(stderr, "launcher %d : %d,%d\n", i, posx, posy); if (panel_horizontal) { if (i % icons_per_column) { posy += launcher->icon_size + launcher->area.paddingx;
@@ -420,7 +420,7 @@
check_manager_window(client); if (client->manager_window == None) { - printf("No XSETTINGS manager, tint2 uses config option 'launcher_icon_theme'.\n"); + fprintf(stderr, "No XSETTINGS manager, tint2 uses config option 'launcher_icon_theme'.\n"); free(client); return NULL; } else {
@@ -256,7 +256,7 @@ }
} return; } - // printf("atom root_win = %s, %s\n", XGetAtomName(server.display, at), task->title); + // fprintf(stderr, "atom root_win = %s, %s\n", XGetAtomName(server.display, at), task->title); // Window title changed if (at == server.atom._NET_WM_VISIBLE_NAME || at == server.atom._NET_WM_NAME || at == server.atom.WM_NAME) {@@ -305,7 +305,7 @@ }
// Window desktop changed else if (at == server.atom._NET_WM_DESKTOP) { int desktop = get_window_desktop(win); - // printf(" Window desktop changed %d, %d\n", task->desktop, desktop); + // fprintf(stderr, " Window desktop changed %d, %d\n", task->desktop, desktop); // bug in windowmaker : send unecessary 'desktop changed' when focus changed if (desktop != task->desktop) { task_update_desktop(task);
@@ -209,7 +209,7 @@ memcpy(&panels[i], &panel_config, sizeof(Panel));
} fprintf(stderr, - "tint2 : nb monitor %d, nb monitor used %d, nb desktop %d\n", + "tint2 : nb monitors %d, nb monitors used %d, nb desktops %d\n", server.num_monitors, num_panels, server.num_desktops);@@ -289,7 +289,7 @@ if (!server.gc) {
XGCValues gcv; server.gc = XCreateGC(server.display, p->main_win, 0, &gcv); } - // printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height); + // fprintf(stderr, "panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height); set_panel_properties(p); set_panel_background(p); if (!snapshot_path) {@@ -322,7 +322,7 @@ panel->area.width = (server.monitors[panel->monitor].width - panel->marginx) * panel->area.width / 100;
if (panel->fractional_height) panel->area.height = (server.monitors[panel->monitor].height - panel->marginy) * panel->area.height / 100; if (panel->area.bg->border.radius > panel->area.height / 2) { - printf("panel_background_id rounded is too big... please fix your tint2rc\n"); + fprintf(stderr, "panel_background_id rounded is too big... please fix your tint2rc\n"); g_array_append_val(backgrounds, *panel->area.bg); panel->area.bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); panel->area.bg->border.radius = panel->area.height / 2;@@ -348,7 +348,7 @@ else
panel->area.width = old_panel_height; if (panel->area.bg->border.radius > panel->area.width / 2) { - printf("panel_background_id rounded is too big... please fix your tint2rc\n"); + fprintf(stderr, "panel_background_id rounded is too big... please fix your tint2rc\n"); g_array_append_val(backgrounds, *panel->area.bg); panel->area.bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); panel->area.bg->border.radius = panel->area.width / 2;@@ -401,7 +401,7 @@ } else {
panel->hidden_width = panel->area.width - diff; panel->hidden_height = panel->area.height; } - // printf("panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, + // fprintf(stderr, "panel : posx %d, posy %d, width %d, height %d\n", panel->posx, panel->posy, panel->area.width, // panel->area.height); }@@ -416,7 +416,7 @@ {
Panel *panel = (Panel *)obj; relayout_with_constraint(&panel->area, 0); - // printf("resize_panel\n"); + // fprintf(stderr, "resize_panel\n"); if (taskbar_mode != MULTI_DESKTOP && taskbar_enabled) { // propagate width/height on hidden taskbar int width = panel->taskbar[server.desktop].area.width;
@@ -425,14 +425,14 @@ RROutput primary_output = XRRGetOutputPrimary(server.display, server.root_win);
if (res && res->ncrtc >= num_monitors) { // use xrandr to identify monitors (does not work with proprietery nvidia drivers) - printf("xRandr: Found crtc's: %d\n", res->ncrtc); + fprintf(stderr, "xRandr: Found crtc's: %d\n", res->ncrtc); server.monitors = calloc(res->ncrtc, sizeof(Monitor)); num_monitors = 0; for (int i = 0; i < res->ncrtc; ++i) { XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(server.display, res, res->crtcs[i]); // Ignore empty crtc if (!crtc_info->width || !crtc_info->height) { - printf("xRandr: crtc %d seems disabled\n", i); + fprintf(stderr, "xRandr: crtc %d seems disabled\n", i); XRRFreeCrtcInfo(crtc_info); continue; }@@ -445,7 +445,7 @@ server.monitors[i_monitor].height = crtc_info->height;
server.monitors[i_monitor].names = calloc((crtc_info->noutput + 1), sizeof(gchar *)); for (int j = 0; j < crtc_info->noutput; ++j) { XRROutputInfo *output_info = XRRGetOutputInfo(server.display, res, crtc_info->outputs[j]); - printf("xRandr: Linking output %s with crtc %d\n", output_info->name, i); + fprintf(stderr, "xRandr: Linking output %s with crtc %d\n", output_info->name, i); server.monitors[i_monitor].names[j] = g_strdup(output_info->name); XRRFreeOutputInfo(output_info); server.monitors[i_monitor].primary = crtc_info->outputs[j] == primary_output;@@ -702,14 +702,14 @@ XChangeWindowAttributes(server.display, server.composite_manager, CWEventMask, &attrs);
server.real_transparency = TRUE; server.depth = 32; - printf("real transparency on... depth: %d\n", server.depth); + fprintf(stderr, "real transparency on... depth: %d\n", server.depth); server.colormap = XCreateColormap(server.display, server.root_win, visual, AllocNone); server.visual = visual; } else { // no composite manager or snapshot mode => fake transparency server.real_transparency = FALSE; server.depth = DefaultDepth(server.display, server.screen); - printf("real transparency off.... depth: %d\n", server.depth); + fprintf(stderr, "real transparency off.... depth: %d\n", server.depth); server.colormap = DefaultColormap(server.display, server.screen); server.visual = DefaultVisual(server.display, server.screen); }@@ -732,7 +732,7 @@ // icewm doesn't open under the mouse.
// and xfce doesn't open at all. e->xbutton.x = e->xbutton.x_root; e->xbutton.y = e->xbutton.y_root; - // printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y); + // fprintf(stderr, "**** %d, %d\n", e->xbutton.x, e->xbutton.y); // XSetInputFocus(server.display, e->xbutton.window, RevertToParent, e->xbutton.time); XSendEvent(server.display, e->xbutton.window, False, ButtonPressMask, e); }
@@ -198,7 +198,7 @@ Window win = task->win;
// free title and icon just for the first task // even with task_on_all_desktop and with task_on_all_panel - // printf("remove_task %s %d\n", task->title, task->desktop); + // fprintf(stderr, "remove_task %s %d\n", task->title, task->desktop); if (task->title) free(task->title); task_remove_icon(task);@@ -591,7 +591,7 @@ active_task = NULL;
} Window w1 = get_active_window(); - // printf("Change active task %ld\n", w1); + // fprintf(stderr, "Change active task %ld\n", w1); if (w1) { if (!get_task_buttons(w1)) {
@@ -267,7 +267,7 @@ for (int j = 0; j < TASK_STATE_COUNT; ++j) {
if (!panel->g_task.background[j]) panel->g_task.background[j] = &g_array_index(backgrounds, Background, 0); if (panel->g_task.background[j]->border.radius > panel->g_task.area.height / 2) { - printf("task%sbackground_id has a too large rounded value. Please fix your tint2rc\n", + fprintf(stderr, "task%sbackground_id has a too large rounded value. Please fix your tint2rc\n", j == 0 ? "_" : j == 1 ? "_active_" : j == 2 ? "_iconified_" : "_urgent_"); g_array_append_val(backgrounds, *panel->g_task.background[j]); panel->g_task.background[j] = &g_array_index(backgrounds, Background, backgrounds->len - 1);@@ -432,7 +432,7 @@ {
Taskbar *taskbar = (Taskbar *)obj; Panel *panel = (Panel *)taskbar->area.panel; - // printf("resize_taskbar %d %d\n", taskbar->area.posx, taskbar->area.posy); + // fprintf(stderr, "resize_taskbar %d %d\n", taskbar->area.posx, taskbar->area.posy); if (panel_horizontal) { relayout_with_constraint(&taskbar->area, panel->g_task.maximum_width);
@@ -1839,7 +1839,7 @@ -1);
if (pixbuf) g_object_unref(pixbuf); } else { - printf("Could not load %s\n", file); + fprintf(stderr, "Could not load %s\n", file); GdkPixbuf *pixbuf = load_icon(DEFAULT_ICON); GtkTreeIter iter; gtk_list_store_append(store, &iter);@@ -1897,7 +1897,7 @@ process_events();
DesktopEntry *entry = calloc(1, sizeof(DesktopEntry)); if (!read_desktop_file(file, entry)) - printf("Could not load %s\n", file); + fprintf(stderr, "Could not load %s\n", file); if (entry->hidden_from_menus) { free(entry); return;
@@ -981,7 +981,7 @@ }
void config_save_file(const char *path) { - printf("config_save_file : %s\n", path); + fprintf(stderr, "config_save_file : %s\n", path); FILE *fp; if ((fp = fopen(path, "w+t")) == NULL)
@@ -223,7 +223,7 @@ }
while ((nb = fread(buffer, 1, sizeof(buffer), file_src)) > 0) { if (nb != fwrite(buffer, 1, nb, file_dest)) { - printf("Error while copying file %s to %s\n", path_src, path_dest); + fprintf(stderr, "Error while copying file %s to %s\n", path_src, path_dest); } }@@ -931,7 +931,7 @@ pango_layout_get_pixel_extents(layout, &rect_ink, &rect);
*height_ink = rect_ink.height; *height = rect.height; *width = rect.width; - // printf("dimension : %d - %d\n", rect_ink.height, rect.height); + // fprintf(stderr, "dimension : %d - %d\n", rect_ink.height, rect.height); g_object_unref(layout); cairo_destroy(c);
@@ -194,7 +194,7 @@ fprintf(stderr, "Bind failed\n");
return -1; } - printf("Kernel uevent interface initialized...\n"); + fprintf(stderr, "Kernel uevent interface initialized...\n"); return uevent_fd; }