diff options
author | Thomas Adam <thomas@xteddy.org> | 2023-02-07 12:01:13 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2023-02-07 12:01:13 +0000 |
commit | ddaeebc2133b991aacac78dea672add480895465 (patch) | |
tree | cfd08ae1dfd6f1e173771324e09cd19ced028b00 /format.c | |
parent | 4a0126f7fb9071f2833632536b2c113f5840d2ff (diff) | |
parent | 0bd78b42c0a379e46645a7083e0b4785b19e39aa (diff) |
Merge branch 'obsd-master'
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -103,6 +103,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2) #define FORMAT_SESSION_NAME 0x8000 #define FORMAT_CHARACTER 0x10000 #define FORMAT_COLOUR 0x20000 +#define FORMAT_CLIENTS 0x40000 /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 100 @@ -3747,7 +3748,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s, cp++; /* Check single character modifiers with no arguments. */ - if (strchr("labcdnwETSWP<>", cp[0]) != NULL && + if (strchr("labcdnwETSWPL<>", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; @@ -4075,6 +4076,40 @@ format_loop_panes(struct format_expand_state *es, const char *fmt) return (value); } +/* Loop over clients. */ +static char * +format_loop_clients(struct format_expand_state *es, const char *fmt) +{ + struct format_tree *ft = es->ft; + struct client *c = ft->client; + struct cmdq_item *item = ft->item; + struct format_tree *nft; + struct format_expand_state next; + char *expanded, *value; + size_t valuelen; + + value = xcalloc(1, 1); + valuelen = 1; + + TAILQ_FOREACH(c, &clients, entry) { + format_log(es, "client loop: %s", c->name); + nft = format_create(c, item, 0, ft->flags); + format_defaults(nft, c, ft->s, ft->wl, ft->wp); + format_copy_state(&next, es, 0); + next.ft = nft; + expanded = format_expand1(&next, fmt); + format_free(nft); + + valuelen += strlen(expanded); + value = xrealloc(value, valuelen); + + strlcat(value, expanded, valuelen); + free(expanded); + } + + return (value); +} + static char * format_replace_expression(struct format_modifier *mexp, struct format_expand_state *es, const char *copy) @@ -4349,6 +4384,9 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, case 'P': modifiers |= FORMAT_PANES; break; + case 'L': + modifiers |= FORMAT_CLIENTS; + break; } } else if (fm->size == 2) { if (strcmp(fm->modifier, "||") == 0 || @@ -4405,6 +4443,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, value = format_loop_panes(es, copy); if (value == NULL) goto fail; + } else if (modifiers & FORMAT_CLIENTS) { + value = format_loop_clients(es, copy); + if (value == NULL) + goto fail; } else if (modifiers & FORMAT_WINDOW_NAME) { value = format_window_name(es, copy); if (value == NULL) |