mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
Add log.c with info() and warn()
This commit is contained in:
parent
5ea1527558
commit
2a17df0f8b
11 changed files with 68 additions and 17 deletions
14
include/common/log.h
Normal file
14
include/common/log.h
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef __LABWC_LOG_H
|
||||||
|
#define __LABWC_LOG_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* info - print info message
|
||||||
|
*/
|
||||||
|
void info(const char *msg, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* warn - print warning
|
||||||
|
*/
|
||||||
|
void warn(const char *err, ...);
|
||||||
|
|
||||||
|
#endif /* __LABWC_LOG_H */
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
|
@ -16,7 +17,6 @@ void action(struct server *server, struct keybind *keybind)
|
||||||
} else if (!strcasecmp(keybind->action, "debug-views")) {
|
} else if (!strcasecmp(keybind->action, "debug-views")) {
|
||||||
dbg_show_views(server);
|
dbg_show_views(server);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "warn: action (%s) not supported\n",
|
warn("action (%s) not supported", keybind->action);
|
||||||
keybind->action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "common/dir.h"
|
#include "common/dir.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
struct dir {
|
struct dir {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
|
@ -84,7 +85,7 @@ char *find_dir(struct ctx *ctx)
|
||||||
/* handle /etc/xdg... */
|
/* handle /etc/xdg... */
|
||||||
ctx->build_path_fn(ctx, NULL, d.path);
|
ctx->build_path_fn(ctx, NULL, d.path);
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "DEBUG: %s\n", ctx->buf);
|
info("%s", ctx->buf);
|
||||||
if (isdir(ctx->buf))
|
if (isdir(ctx->buf))
|
||||||
return ctx->buf;
|
return ctx->buf;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -96,8 +97,7 @@ char *find_dir(struct ctx *ctx)
|
||||||
for (gchar **p = prefixes; *p; p++) {
|
for (gchar **p = prefixes; *p; p++) {
|
||||||
ctx->build_path_fn(ctx, *p, d.path);
|
ctx->build_path_fn(ctx, *p, d.path);
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "DEBUG: %s\n",
|
info("%s", ctx->buf);
|
||||||
ctx->buf);
|
|
||||||
if (isdir(ctx->buf))
|
if (isdir(ctx->buf))
|
||||||
return ctx->buf;
|
return ctx->buf;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
src/common/log.c
Normal file
32
src/common/log.c
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define LABWC_COLOR_YELLOW "\033[0;33m"
|
||||||
|
#define LABWC_COLOR_RED "\033[0;31m"
|
||||||
|
#define LABWC_COLOR_RESET "\033[0m"
|
||||||
|
|
||||||
|
void info(const char *msg, ...)
|
||||||
|
{
|
||||||
|
va_list params;
|
||||||
|
fprintf(stderr, LABWC_COLOR_YELLOW);
|
||||||
|
fprintf(stderr, "[labwc] info: ");
|
||||||
|
va_start(params, msg);
|
||||||
|
vfprintf(stderr, msg, params);
|
||||||
|
va_end(params);
|
||||||
|
fprintf(stderr, LABWC_COLOR_RESET);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void warn(const char *err, ...)
|
||||||
|
{
|
||||||
|
va_list params;
|
||||||
|
fprintf(stderr, LABWC_COLOR_RED);
|
||||||
|
fprintf(stderr, "[labwc] warning: ");
|
||||||
|
va_start(params, err);
|
||||||
|
vfprintf(stderr, err, params);
|
||||||
|
va_end(params);
|
||||||
|
fprintf(stderr, LABWC_COLOR_RESET);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
@ -3,5 +3,6 @@ labwc_sources += files(
|
||||||
'dir.c',
|
'dir.c',
|
||||||
'font.c',
|
'font.c',
|
||||||
'grab-file.c',
|
'grab-file.c',
|
||||||
|
'log.c',
|
||||||
'spawn.c',
|
'spawn.c',
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "config/keybind.h"
|
#include "config/keybind.h"
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
static uint32_t parse_modifier(const char *symname)
|
static uint32_t parse_modifier(const char *symname)
|
||||||
{
|
{
|
||||||
|
|
@ -35,8 +36,7 @@ struct keybind *keybind_add(const char *keybind)
|
||||||
xkb_keysym_t sym = xkb_keysym_from_name(
|
xkb_keysym_t sym = xkb_keysym_from_name(
|
||||||
symname, XKB_KEYSYM_NO_FLAGS);
|
symname, XKB_KEYSYM_NO_FLAGS);
|
||||||
if (sym == XKB_KEY_NoSymbol) {
|
if (sym == XKB_KEY_NoSymbol) {
|
||||||
fprintf(stderr, "unknown keybind (%s)\n",
|
warn("unknown keybind (%s)", symname);
|
||||||
symname);
|
|
||||||
free(k);
|
free(k);
|
||||||
k = NULL;
|
k = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "common/dir.h"
|
#include "common/dir.h"
|
||||||
#include "common/bug-on.h"
|
#include "common/bug-on.h"
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
static bool in_keybind = false;
|
static bool in_keybind = false;
|
||||||
static bool is_attribute = false;
|
static bool is_attribute = false;
|
||||||
|
|
@ -205,7 +206,7 @@ void rcxml_parse_xml(struct buf *b)
|
||||||
{
|
{
|
||||||
xmlDoc *d = xmlParseMemory(b->buf, b->len);
|
xmlDoc *d = xmlParseMemory(b->buf, b->len);
|
||||||
if (!d) {
|
if (!d) {
|
||||||
fprintf(stderr, "fatal: xmlParseMemory()\n");
|
warn("xmlParseMemory()");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
xml_tree_walk(xmlDocGetRootElement(d));
|
xml_tree_walk(xmlDocGetRootElement(d));
|
||||||
|
|
@ -225,7 +226,7 @@ static void bind(const char *binding, const char *action)
|
||||||
struct keybind *k = keybind_add(binding);
|
struct keybind *k = keybind_add(binding);
|
||||||
if (k)
|
if (k)
|
||||||
k->action = strdup(action);
|
k->action = strdup(action);
|
||||||
fprintf(stderr, "binding: %s: %s\n", binding, action);
|
info("binding %s: %s", binding, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_title_height(void)
|
static void set_title_height(void)
|
||||||
|
|
@ -239,7 +240,7 @@ static void set_title_height(void)
|
||||||
static void post_processing(void)
|
static void post_processing(void)
|
||||||
{
|
{
|
||||||
if (!wl_list_length(&rc.keybinds)) {
|
if (!wl_list_length(&rc.keybinds)) {
|
||||||
fprintf(stderr, "info: loading default key bindings\n");
|
info("loading default key bindings");
|
||||||
bind("A-Escape", "Exit");
|
bind("A-Escape", "Exit");
|
||||||
bind("A-Tab", "NextWindow");
|
bind("A-Tab", "NextWindow");
|
||||||
bind("A-F3", "Execute");
|
bind("A-F3", "Execute");
|
||||||
|
|
@ -273,10 +274,10 @@ void rcxml_read(const char *filename)
|
||||||
* unit tests.
|
* unit tests.
|
||||||
*/
|
*/
|
||||||
rcxml_path(rcxml, sizeof(rcxml), filename);
|
rcxml_path(rcxml, sizeof(rcxml), filename);
|
||||||
fprintf(stderr, "info: read config file (%s)\n", rcxml);
|
info("reading config file (%s)", rcxml);
|
||||||
stream = fopen(rcxml, "r");
|
stream = fopen(rcxml, "r");
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
fprintf(stderr, "warn: cannot read '%s'\n", rcxml);
|
warn("cannot read (%s)", rcxml);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
buf_init(&b);
|
buf_init(&b);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
static void keyboard_handle_modifiers(struct wl_listener *listener, void *data)
|
static void keyboard_handle_modifiers(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
|
|
@ -65,8 +66,7 @@ static void keyboard_handle_key(struct wl_listener *listener, void *data)
|
||||||
} else if (event->state == WLR_KEY_PRESSED) {
|
} else if (event->state == WLR_KEY_PRESSED) {
|
||||||
/* cycle to next */
|
/* cycle to next */
|
||||||
server->cycle_view = next_toplevel(server->cycle_view);
|
server->cycle_view = next_toplevel(server->cycle_view);
|
||||||
fprintf(stderr, "cycle_view=%p\n",
|
info("cycle_view=%p", (void *)server->cycle_view);
|
||||||
(void *)server->cycle_view);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "theme/theme.h"
|
#include "theme/theme.h"
|
||||||
#include "common/dir.h"
|
#include "common/dir.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
static int hex_to_dec(char c)
|
static int hex_to_dec(char c)
|
||||||
{
|
{
|
||||||
|
|
@ -96,10 +97,10 @@ void theme_read(const char *theme_name)
|
||||||
char themerc[4096];
|
char themerc[4096];
|
||||||
|
|
||||||
snprintf(themerc, sizeof(themerc), "%s/themerc", theme_dir(theme_name));
|
snprintf(themerc, sizeof(themerc), "%s/themerc", theme_dir(theme_name));
|
||||||
fprintf(stderr, "info: read themerc (%s)\n", themerc);
|
info("reading themerc (%s)", themerc);
|
||||||
stream = fopen(themerc, "r");
|
stream = fopen(themerc, "r");
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
fprintf(stderr, "warn: cannot read (%s)\n", themerc);
|
warn("cannot read (%s)", themerc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (getline(&line, &len, stream) != -1) {
|
while (getline(&line, &len, stream) != -1) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
int xwl_nr_parents(struct view *view)
|
int xwl_nr_parents(struct view *view)
|
||||||
{
|
{
|
||||||
|
|
@ -6,7 +7,7 @@ int xwl_nr_parents(struct view *view)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!s) {
|
if (!s) {
|
||||||
fprintf(stderr, "warn: (%s) no xwayland surface\n", __func__);
|
warn("(%s) no xwayland surface\n", __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (s->parent) {
|
while (s->parent) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ rcxml_lib = static_library(
|
||||||
'../src/common/dir.c',
|
'../src/common/dir.c',
|
||||||
'../src/common/buf.c',
|
'../src/common/buf.c',
|
||||||
'../src/common/font.c',
|
'../src/common/font.c',
|
||||||
|
'../src/common/log.c',
|
||||||
),
|
),
|
||||||
dependencies: labwc_deps,
|
dependencies: labwc_deps,
|
||||||
include_directories: [labwc_inc],
|
include_directories: [labwc_inc],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue