commit 29825ad4c6f4a52b0242dab17b6de704a472f543
parent 2c8f3c1e0c1bb93ad8ec2c1409170cdf7eeaa753
Author: Kris Maglione <jg@suckless.org>
Date: Fri, 30 May 2008 11:48:43 -0400
Show a client's extra tags in its titlebar.
Diffstat:
6 files changed, 76 insertions(+), 12 deletions(-)
diff --git a/cmd/wmii/_util.c b/cmd/wmii/_util.c
@@ -4,6 +4,7 @@
#include "dat.h"
#include <errno.h>
#include <fcntl.h>
+#include <stdarg.h>
#include <sys/wait.h>
#include <unistd.h>
#include <bio.h>
@@ -306,3 +307,16 @@ join(char **list, char *sep) {
return fmtstrflush(&f);
}
+int
+strlcatprint(char *buf, int len, const char *fmt, ...) {
+ va_list ap;
+ int buflen;
+ int ret;
+
+ va_start(ap, fmt);
+ buflen = strlen(buf);
+ ret = vsnprint(buf+buflen, len-buflen, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+
diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c
@@ -981,6 +981,8 @@ client_setviews(Client *c, char **tags) {
}
if(c->sel == nil)
c->sel = c->frame;
+ if(c->sel)
+ frame_draw(c->sel);
}
static int
@@ -1003,6 +1005,39 @@ static char *badtags[] = {
"sel",
};
+char*
+client_extratags(Client *c) {
+ Frame *f;
+ char *toks[32];
+ char *s, *s2;
+ int i;
+
+ i = 0;
+ toks[i++] = "";
+ for(f=c->frame; f && i < nelem(toks)-1; f=f->cnext)
+ if(f != c->sel)
+ toks[i++] = f->view->name;
+ toks[i] = nil;
+
+ s = nil;
+ if(i > 1)
+ s = join(toks, "+");
+ if(!c->tagre.regex && !c->tagvre.regex)
+ return s;
+
+ if(c->tagre.regex) {
+ s2 = s;
+ s = smprint("%s+/%s/", s, c->tagre.regex);
+ free(s2);
+ }
+ if(c->tagvre.regex) {
+ s2 = s;
+ s = smprint("%s-/%s/", s, c->tagvre.regex);
+ free(s2);
+ }
+ return s;
+}
+
void
apply_tags(Client *c, const char *tags) {
uint i, j, k, n;
@@ -1101,6 +1136,10 @@ apply_tags(Client *c, const char *tags) {
s = join(toks, "+");
utflcpy(c->tags, s, sizeof c->tags);
+ if(c->tagre.regex)
+ strlcatprint(c->tags, sizeof c->tags, "+/%s/", c->tagre.regex);
+ if(c->tagvre.regex)
+ strlcatprint(c->tags, sizeof c->tags, "-/%s/", c->tagvre.regex);
changeprop_string(&c->w, "_WMII_TAGS", s);
free(s);
diff --git a/cmd/wmii/dat.h b/cmd/wmii/dat.h
@@ -273,6 +273,7 @@ struct View {
Area* oldsel;
Area* revert;
int selcol;
+ bool dead;
Rectangle r;
};
diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h
@@ -46,6 +46,7 @@ void apply_tags(Client*, const char*);
void client_configure(Client*);
Client* client_create(XWindow, XWindowAttributes*);
void client_destroy(Client*);
+char* client_extratags(Client*);
bool client_floats_p(Client*);
void client_focus(Client*);
Frame* client_groupframe(Client*, View*);
@@ -250,6 +251,7 @@ void grep(char**, Reprog*, int);
char* join(char**, char*);
void refree(Regex*);
void reinit(Regex*, char*);
+int strlcatprint(char*, int, const char*, ...);
int spawn3(int[3], const char*, char*[]);
int spawn3l(int[3], const char*, ...);
void uniq(char**);
diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c
@@ -406,10 +406,11 @@ frame_resize(Frame *f, Rectangle r) {
void
frame_draw(Frame *f) {
- Rectangle r, fr;
+ Rectangle r, r2, fr;
Client *c;
CTuple *col;
Image *img;
+ char *s;
uint w;
if(f->view != screen->sel)
@@ -426,15 +427,6 @@ frame_draw(Frame *f) {
col = &def.focuscolor;
else
col = &def.normcolor;
- /*
- Frame *tf;
- if(!f->area->floating && f->area->mode == Colmax)
- for(tf=f->area->frame; tf; tf=tf->anext)
- if(tf->client == screen->focus) {
- col = &def.focuscolor;
- break;
- }
- */
/* Background/border */
r = fr;
@@ -481,8 +473,19 @@ frame_draw(Frame *f) {
r.max.x = fr.max.x;
r.min.y = 0;
r.max.y = labelh(def.font);
- if(c->floating)
- r.max.x -= Dx(f->grabbox);
+ if((s = client_extratags(c))) {
+ r2 = r;
+ w = textwidth(def.font, s);
+ w = min(w, Dx(r) - 30); /* Magic number. */
+ if(w > 0) { /* Magic number. */
+ r.max.x -= w + 4;
+ drawstring(img, def.font, r2, East,
+ s, col->fg);
+ }
+ free(s);
+ }else
+ if(c->floating)
+ r.max.x -= Dx(f->grabbox);
w = drawstring(img, def.font, r, West,
c->name, col->fg);
diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c
@@ -108,9 +108,14 @@ view_destroy(View *v) {
View *tv;
Area *a, *an;
+ if(v->dead)
+ return;
+ v->dead = true;
+
for(vp=&view; *vp; vp=&(*vp)->next)
if(*vp == v) break;
*vp = v->next;
+ assert(v != v->next);
/* FIXME: Can do better */
for(a=v->area; a; a=an) {