Skip to content

Commit

Permalink
Display instance (if present) in nested layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Hummer12007 committed Jan 19, 2017
1 parent e714fbc commit baed3c0
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions sway/border.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b,
}
}

/**
* Generate window title for tabbed/stacked layouts
*/
static char *generate_view_title(swayc_t *view) {
char *title;
size_t len;
if (view->app_id) {
return strdup(view->app_id);
} else if (view->class && view->instance) {
len = strlen(view->class) + strlen(view->instance) + 3;
title = calloc(len + 1, 1);
snprintf(title, len, "%s - %s", view->instance, view->class);
return title;
} else if (view->class) {
return strdup(view->class);
}
return strdup("(null)");
}

/**
* Generate nested container title for tabbed/stacked layouts
*/
Expand Down Expand Up @@ -252,9 +271,9 @@ static char *generate_container_title(swayc_t *container) {
for (i = 0; i < container->children->length; ++i) {
prev_name = name;
swayc_t* child = container->children->items[i];
const char *title = NULL;
char *title = NULL;
if (child->type == C_VIEW) {
title = child->app_id ? child->app_id : (child->class ? child->class : "(null)");
title = generate_view_title(child);
} else { //child->type == C_CONTAINER
title = generate_container_title(child);
}
Expand All @@ -267,6 +286,9 @@ static char *generate_container_title(swayc_t *container) {
name = malloc(len * sizeof(char));
if (!name) {
free(prev_name);
if (child->type == C_VIEW) {
free(title);
}
sway_log(L_ERROR, "Unable to allocate container title");
return NULL;
}
Expand All @@ -275,6 +297,9 @@ static char *generate_container_title(swayc_t *container) {
} else {
snprintf(name, len, "%s%s", prev_name, title);
}
if (child->type == C_VIEW) {
free(title);
}
free(prev_name);
}

Expand Down

0 comments on commit baed3c0

Please sign in to comment.