log: Add swayc_log, use at a few key places.

swayc_log works just like sway_log, but appends type and name from given
container to the log output.
This commit is contained in:
S. Christoffer Eliesen 2015-10-25 00:34:57 +02:00
parent c6bb23b7dd
commit 5a70853253
4 changed files with 31 additions and 2 deletions

View file

@ -23,4 +23,6 @@ bool _sway_assert(bool condition, const char* format, ...) __attribute__((format
void error_handler(int sig); void error_handler(int sig);
void layout_log(const swayc_t *c, int depth); void layout_log(const swayc_t *c, int depth);
const char *swayc_type_string(enum swayc_types type);
void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) __attribute__((format(printf,3,4)));
#endif #endif

View file

@ -76,7 +76,7 @@ bool set_focused_container(swayc_t *c) {
if (locked_container_focus || !c) { if (locked_container_focus || !c) {
return false; return false;
} }
sway_log(L_DEBUG, "Setting focus to %p:%ld", c, c->handle); swayc_log(L_DEBUG, c, "Setting focus to %p:%ld", c, c->handle);
// Get workspace for c, get that workspaces current focused container. // Get workspace for c, get that workspaces current focused container.
swayc_t *workspace = swayc_active_workspace_for(c); swayc_t *workspace = swayc_active_workspace_for(c);

View file

@ -349,7 +349,7 @@ void update_geometry(swayc_t *container) {
static void arrange_windows_r(swayc_t *container, double width, double height) { static void arrange_windows_r(swayc_t *container, double width, double height) {
int i; int i;
if (width == -1 || height == -1) { if (width == -1 || height == -1) {
sway_log(L_DEBUG, "Arranging layout for %p", container); swayc_log(L_DEBUG, container, "Arranging layout for %p", container);
width = container->width; width = container->width;
height = container->height; height = container->height;
} }

View file

@ -187,4 +187,31 @@ void layout_log(const swayc_t *c, int depth) {
} }
} }
} }
const char *swayc_type_string(enum swayc_types type) {
return type == C_ROOT ? "ROOT" :
type == C_OUTPUT ? "OUTPUT" :
type == C_WORKSPACE ? "WORKSPACE" :
type == C_CONTAINER ? "CONTAINER" :
type == C_VIEW ? "VIEW" :
"UNKNOWN";
}
// Like sway_log, but also appends some info about given container to log output.
void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) {
sway_assert(cont, "swayc_log: no container ...");
va_list args;
va_start(args, format);
char *txt = malloc(128);
vsprintf(txt, format, args);
va_end(args);
char *debug_txt = malloc(32);
snprintf(debug_txt, 32, "%s '%s'", swayc_type_string(cont->type), cont->name);
sway_log(verbosity, "%s (%s)", txt, debug_txt);
free(txt);
free(debug_txt);
}
/* XXX:DEBUG:XXX */ /* XXX:DEBUG:XXX */