diff options
author | 2016-04-24 01:47:57 +0200 | |
---|---|---|
committer | 2016-04-25 00:00:49 +0200 | |
commit | 6c7ed7e7cb1f25429db05103b98e6fcee11d0362 (patch) | |
tree | 1e17e7ff8c2957ee96a22751533e71da4a6e9790 /sway/border.c | |
parent | Disable inner gaps when in tabbed/stacked mode (diff) | |
download | sway-6c7ed7e7cb1f25429db05103b98e6fcee11d0362.tar.gz sway-6c7ed7e7cb1f25429db05103b98e6fcee11d0362.tar.zst sway-6c7ed7e7cb1f25429db05103b98e6fcee11d0362.zip |
Add title to nested tabbed/stacked containers
Diffstat (limited to 'sway/border.c')
-rw-r--r-- | sway/border.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/sway/border.c b/sway/border.c index cc329b6a..cec443f4 100644 --- a/sway/border.c +++ b/sway/border.c | |||
@@ -203,6 +203,62 @@ void map_update_view_border(swayc_t *view, void *data) { | |||
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | /** | ||
207 | * Generate nested container title for tabbed/stacked layouts | ||
208 | */ | ||
209 | static char *generate_container_title(swayc_t *container) { | ||
210 | char layout = 'H'; | ||
211 | char *name, *prev_name = NULL; | ||
212 | switch (container->layout) { | ||
213 | case L_TABBED: | ||
214 | layout = 'T'; | ||
215 | break; | ||
216 | case L_STACKED: | ||
217 | layout = 'S'; | ||
218 | break; | ||
219 | case L_VERT: | ||
220 | layout = 'V'; | ||
221 | break; | ||
222 | default: | ||
223 | layout = 'H'; | ||
224 | } | ||
225 | int len = 9; | ||
226 | name = malloc(len * sizeof(char)); | ||
227 | snprintf(name, len, "sway: %c[", layout); | ||
228 | |||
229 | int i; | ||
230 | for (i = 0; i < container->children->length; ++i) { | ||
231 | prev_name = name; | ||
232 | swayc_t* child = container->children->items[i]; | ||
233 | const char *title = child->name; | ||
234 | if (child->type == C_CONTAINER) { | ||
235 | title = generate_container_title(child); | ||
236 | } | ||
237 | |||
238 | len = strlen(name) + strlen(title) + 1; | ||
239 | if (i < container->children->length-1) { | ||
240 | len++; | ||
241 | } | ||
242 | |||
243 | name = malloc(len * sizeof(char)); | ||
244 | if (i < container->children->length-1) { | ||
245 | snprintf(name, len, "%s%s ", prev_name, title); | ||
246 | } else { | ||
247 | snprintf(name, len, "%s%s", prev_name, title); | ||
248 | } | ||
249 | free(prev_name); | ||
250 | } | ||
251 | |||
252 | prev_name = name; | ||
253 | len = strlen(name) + 2; | ||
254 | name = malloc(len * sizeof(char)); | ||
255 | snprintf(name, len, "%s]", prev_name); | ||
256 | free(prev_name); | ||
257 | free(container->name); | ||
258 | container->name = name; | ||
259 | return container->name + 6; // don't include "sway: " | ||
260 | } | ||
261 | |||
206 | void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometry *g, swayc_t *focused, swayc_t *focused_inactive) { | 262 | void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometry *g, swayc_t *focused, swayc_t *focused_inactive) { |
207 | if (c->type == C_CONTAINER) { | 263 | if (c->type == C_CONTAINER) { |
208 | if (c->parent->focused == c) { | 264 | if (c->parent->focused == c) { |
@@ -277,6 +333,16 @@ void update_view_border(swayc_t *view) { | |||
277 | } else { | 333 | } else { |
278 | render_borders(view, cr, &config->border_colors.focused_inactive, false); | 334 | render_borders(view, cr, &config->border_colors.focused_inactive, false); |
279 | } | 335 | } |
336 | |||
337 | // generate container titles | ||
338 | int i; | ||
339 | for (i = 0; i < p->children->length; ++i) { | ||
340 | swayc_t *child = p->children->items[i]; | ||
341 | if (child->type == C_CONTAINER) { | ||
342 | generate_container_title(child); | ||
343 | } | ||
344 | } | ||
345 | |||
280 | update_tabbed_stacked_titlebars(p, cr, &g, focused, focused_inactive); | 346 | update_tabbed_stacked_titlebars(p, cr, &g, focused, focused_inactive); |
281 | } else { | 347 | } else { |
282 | switch (view->border_type) { | 348 | switch (view->border_type) { |