Add title to nested tabbed/stacked containers
This commit is contained in:
parent
5492277f0c
commit
6c7ed7e7cb
|
@ -203,6 +203,62 @@ void map_update_view_border(swayc_t *view, void *data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate nested container title for tabbed/stacked layouts
|
||||||
|
*/
|
||||||
|
static char *generate_container_title(swayc_t *container) {
|
||||||
|
char layout = 'H';
|
||||||
|
char *name, *prev_name = NULL;
|
||||||
|
switch (container->layout) {
|
||||||
|
case L_TABBED:
|
||||||
|
layout = 'T';
|
||||||
|
break;
|
||||||
|
case L_STACKED:
|
||||||
|
layout = 'S';
|
||||||
|
break;
|
||||||
|
case L_VERT:
|
||||||
|
layout = 'V';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
layout = 'H';
|
||||||
|
}
|
||||||
|
int len = 9;
|
||||||
|
name = malloc(len * sizeof(char));
|
||||||
|
snprintf(name, len, "sway: %c[", layout);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
|
prev_name = name;
|
||||||
|
swayc_t* child = container->children->items[i];
|
||||||
|
const char *title = child->name;
|
||||||
|
if (child->type == C_CONTAINER) {
|
||||||
|
title = generate_container_title(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = strlen(name) + strlen(title) + 1;
|
||||||
|
if (i < container->children->length-1) {
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = malloc(len * sizeof(char));
|
||||||
|
if (i < container->children->length-1) {
|
||||||
|
snprintf(name, len, "%s%s ", prev_name, title);
|
||||||
|
} else {
|
||||||
|
snprintf(name, len, "%s%s", prev_name, title);
|
||||||
|
}
|
||||||
|
free(prev_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_name = name;
|
||||||
|
len = strlen(name) + 2;
|
||||||
|
name = malloc(len * sizeof(char));
|
||||||
|
snprintf(name, len, "%s]", prev_name);
|
||||||
|
free(prev_name);
|
||||||
|
free(container->name);
|
||||||
|
container->name = name;
|
||||||
|
return container->name + 6; // don't include "sway: "
|
||||||
|
}
|
||||||
|
|
||||||
void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometry *g, swayc_t *focused, swayc_t *focused_inactive) {
|
void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometry *g, swayc_t *focused, swayc_t *focused_inactive) {
|
||||||
if (c->type == C_CONTAINER) {
|
if (c->type == C_CONTAINER) {
|
||||||
if (c->parent->focused == c) {
|
if (c->parent->focused == c) {
|
||||||
|
@ -277,6 +333,16 @@ void update_view_border(swayc_t *view) {
|
||||||
} else {
|
} else {
|
||||||
render_borders(view, cr, &config->border_colors.focused_inactive, false);
|
render_borders(view, cr, &config->border_colors.focused_inactive, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate container titles
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < p->children->length; ++i) {
|
||||||
|
swayc_t *child = p->children->items[i];
|
||||||
|
if (child->type == C_CONTAINER) {
|
||||||
|
generate_container_title(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_tabbed_stacked_titlebars(p, cr, &g, focused, focused_inactive);
|
update_tabbed_stacked_titlebars(p, cr, &g, focused, focused_inactive);
|
||||||
} else {
|
} else {
|
||||||
switch (view->border_type) {
|
switch (view->border_type) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
#include <xkbcommon/xkbcommon-names.h>
|
#include <xkbcommon/xkbcommon-names.h>
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
|
#include <wlc/wlc-render.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -2041,6 +2042,17 @@ static struct cmd_results *_do_split(int argc, char **argv, int layout) {
|
||||||
set_focused_container(focused);
|
set_focused_container(focused);
|
||||||
arrange_windows(parent, -1, -1);
|
arrange_windows(parent, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update container title if tabbed/stacked
|
||||||
|
if (swayc_tabbed_stacked_parent(focused)) {
|
||||||
|
update_view_border(focused);
|
||||||
|
swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
|
||||||
|
// schedule render to make changes take effect right away,
|
||||||
|
// otherwise we would have to wait for the view to render,
|
||||||
|
// which is unpredictable.
|
||||||
|
wlc_output_schedule_render(output->handle);
|
||||||
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue