dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit a8192a7b13358ce85cb65128314abeee18464212
parent ca2df77446856a5c3da1d923ac52783f3faece5c
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun,  9 Oct 2016 21:11:01 +0200

Extend tag command syntax to allow flexible tag manipulations

 tag win +foo -bar

will add the tag `foo` and remove the tag `bar` from `win`.
If a tag is neither prefixed with a plus or minus sign, the
existing set of tags are replaced with the one tag given.

The resulting tags must be non empty i.e. each window must be
assigned to at least one tag otherwise the command will be
ignored.

Diffstat:
config.def.h | 2+-
dvtm.c | 23+++++++++++++++++------
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -192,7 +192,7 @@ static Cmd commands[] = { { "create", { create, { NULL } } }, /* focus <win_id>: focus the window whose `DVTM_WINDOW_ID` is `win_id` */ { "focus", { focusid, { NULL } } }, - /* tag <win_id> <tag> [tag ...]: replace the tags of the window with the given identifier */ + /* tag <win_id> <tag> [tag ...]: add +tag, remove -tag or set tag of the window with the given identifier */ { "tag", { tagid, { NULL } } }, }; diff --git a/dvtm.c b/dvtm.c @@ -770,8 +770,10 @@ keybinding(KeyCombo keys, unsigned int keycount) { static unsigned int bitoftag(const char *tag) { unsigned int i; + if (!tag) + return ~0; for (i = 0; (i < LENGTH(tags)) && strcmp(tags[i], tag); i++); - return (i < LENGTH(tags)) ? (1 << i) : ~0; + return (i < LENGTH(tags)) ? (1 << i) : 0; } static void @@ -806,11 +808,20 @@ tagid(const char *args[]) { const int win_id = atoi(args[0]); for (Client *c = clients; c; c = c->next) { if (c->id == win_id) { - unsigned int i; - c->tags = 0; - for (i = 1; i < MAX_ARGS && args[i]; i++) - c->tags |= bitoftag(args[i]) & TAGMASK; - tagschanged(); + unsigned int ntags = c->tags; + for (unsigned int i = 1; i < MAX_ARGS && args[i]; i++) { + if (args[i][0] == '+') + ntags |= bitoftag(args[i]+1); + else if (args[i][0] == '-') + ntags &= ~bitoftag(args[i]+1); + else + ntags = bitoftag(args[i]); + } + ntags &= TAGMASK; + if (ntags) { + c->tags = ntags; + tagschanged(); + } return; } }