wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 95a2527e1195670e43660321adc8f08f944207f0
parent 5df09bbf3f2a09527cdd42efe63a76f761248747
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Sun,  5 Mar 2006 23:38:50 +0100

proceeded with tag integration


Diffstat:
cmd/wm/area.c | 11++++++-----
cmd/wm/client.c | 14++++++++++++--
cmd/wm/fs.c | 3++-
cmd/wm/tag.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
cmd/wm/wm.h | 3++-
rc/wmiirc | 11+++++++++++
6 files changed, 85 insertions(+), 29 deletions(-)

diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -158,6 +158,7 @@ detach_fromarea(Client *c) destroy_area(a); arrange_tag(t, True); } + update_ctags(); } char * @@ -210,7 +211,7 @@ relax_area(Area *a) Frame *f = a->frame[i]; unsigned int tmp = f->rect.height; f->rect.height += (a->rect.height - h); - resize_client(f->client, &f->rect, 0, True); + resize_client(f->client, &f->rect, nil, True); h += (f->rect.height - tmp); } } @@ -223,7 +224,7 @@ relax_area(Area *a) f->rect.y = yoff; if(a->mode != Colmax) yoff = f->rect.y + f->rect.height + hdiff; - resize_client(f->client, &f->rect, 0, False); + resize_client(f->client, &f->rect, nil, False); } } @@ -248,7 +249,7 @@ arrange_area(Area *a) else f->rect.height = a->rect.height - f->rect.y + a->rect.y; - resize_client(f->client, &f->rect, 0, True); + resize_client(f->client, &f->rect, nil, True); } break; case Colstack: @@ -263,14 +264,14 @@ arrange_area(Area *a) else f->rect.height = bar_height(); yoff += f->rect.height; - resize_client(f->client, &f->rect, 0, True); + resize_client(f->client, &f->rect, nil, True); } break; case Colmax: for(i = 0; i < a->nframe; i++) { Frame *f = a->frame[i]; f->rect = a->rect; - resize_client(f->client, &f->rect, 0, True); + resize_client(f->client, &f->rect, nil, True); } break; default: diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -341,8 +341,9 @@ attach_client(Client *c) } void -detach_client(Client *c, Bool unmap) +detach_fromtag(Tag *t, Client *c, Bool unmap) { + /* TODO: later check c->frame's if it is a member of t */ Frame *f = c->frame; if(f) { if(!c->destroyed) { @@ -359,6 +360,15 @@ detach_client(Client *c, Bool unmap) destroy_client(c); } +void +detach_client(Client *c, Bool unmap) +{ + int i; + for(i = 0; i < ntag; i++) + if(is_clientof(tag[i], c)) + detach_fromtag(tag[i], client[i], unmap); +} + Client * sel_client_of_tag(Tag *t) { @@ -433,7 +443,7 @@ resize_client(Client *c, XRectangle *r, XPoint *pt, Bool ignore_xcall) int px = sel * rect.width; - if(area2index(f->area) > 0) + if((area2index(f->area) > 0) && pt) resize_area(c, r, pt); else f->rect = *r; diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c @@ -41,7 +41,7 @@ static char Enocommand[] = "command not supported"; * /keys/ FsDkeys * /keys/foo FsFkey * /tags/ FsDtags - * /tags/foo FsFtag + * /tags/foo FsFtags * /bar/ FsDbar * /bar/expand FsFexpand id of expandable label * /bar/new/ FsDlabel @@ -1094,6 +1094,7 @@ xwrite(IXPConn *c, Fcall *fcall) if(fcall->count > sizeof(f->client->tags)) return "tags value too long"; memcpy(f->client->tags, fcall->data, fcall->count); + f->client->tags[fcall->count] = 0; update_ctags(); break; case FsFgeom: diff --git a/cmd/wm/tag.c b/cmd/wm/tag.c @@ -42,6 +42,8 @@ destroy_tag(Tag *t) cext_array_detach((void **)tag, t, &tagsz); ntag--; + if(sel >= ntag) + sel = 0; for(i = 0; i < ntag; i++) XChangeProperty(dpy, root, net_atom[NetNumWS], XA_CARDINAL, @@ -130,20 +132,8 @@ tid2index(unsigned short id) return -1; } -void -select_tag(char *arg) -{ - Client *c; - Tag *t = ctag2tag(arg); - if(!t) - return; - focus_tag(t); - if((c = sel_client_of_tag(t))) - focus_client(c); -} - Tag * -ctag2tag(char *name) +get_tag(char *name) { unsigned int i; Tag *t; @@ -163,6 +153,18 @@ ctag2tag(char *name) return t; } +void +select_tag(char *arg) +{ + Client *c; + Tag *t = get_tag(arg); + if(!t) + return; + focus_tag(t); + if((c = sel_client_of_tag(t))) + focus_client(c); +} + Bool has_ctag(char *tag) { @@ -173,27 +175,47 @@ has_ctag(char *tag) return False; } +Bool +is_clientof(Tag *t, Client *c) +{ + unsigned int i, j; + for(i = 0; i < t->narea; i++) { + Area *a = t->area[i]; + for(j = 0; j < a->nframe; j++) + if(a->frame[j]->client == c) + return True; + } + return False; +} + void update_ctags() { - unsigned int i; + unsigned int i, j, k; char buf[256]; char *tags[128]; for(i = 0; i < nctag; i++) { + Bool exists = False; + for(j = 0; j < nclient; j++) + if(strstr(client[j]->tags, ctag[i])) + exists = True; + if(!exists) { + for(j = 0; j < ntag; j++) + if(strstr(tag[j]->name, ctag[i])) { + destroy_tag(tag[j]); + j--; + } + } free(ctag[i]); ctag[i] = nil; } nctag = 0; for(i = 0; i < nclient; i++) { - unsigned int j, k; cext_strlcpy(buf, client[i]->tags, sizeof(buf)); - fprintf(stderr, "update_ctags: %s\n", buf); j = cext_tokenize(tags, 128, buf, ' '); - fprintf(stderr, "update_ctags: %d\n", j); for(k = 0; k < j; k++) { - fprintf(stderr, "update_ctags: tag=%s\n", tags[k]); if(!has_ctag(tags[k])) { ctag = (char **)cext_array_attach((void **)ctag, strdup(tags[k]), sizeof(char *), &ctagsz); @@ -201,6 +223,16 @@ update_ctags() } } } - for(i = 0; i < nctag; i++) - fprintf(stderr, "tag=%s\n", ctag[i]); + + for(i = 0; i < nclient; i++) + for(j = 0; j < ntag; j++) { + if(strstr(client[i]->tags, tag[j]->name)) { + if(!is_clientof(tag[j], client[i])) + attach_totag(tag[j], client[i]); + } + else { + if(is_clientof(tag[j], client[i])) + detach_fromtag(tag[j], client[i], False); + } + } } diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -251,6 +251,7 @@ void select_client(Client *c, char *arg); void sendtoarea_client(Client *c, char *arg); void resize_all_clients(); void focus(Client *c); +void detach_fromtag(Tag *t, Client *c, Bool unmap); /* event.c */ void init_x_event_handler(); @@ -293,7 +294,7 @@ void select_tag(char *arg); int tag2index(Tag *t); Bool has_ctag(char *tag); void update_ctags(); -Tag *ctag2tag(char *name); +Bool is_clientof(Tag *t, Client *c); /* wm.c */ void scan_wins(); diff --git a/rc/wmiirc b/rc/wmiirc @@ -70,6 +70,15 @@ $MODKEY-n $MODKEY-m $MODKEY-s $MODKEY-equal +$MODKEY-1 +$MODKEY-2 +$MODKEY-3 +$MODKEY-4 +$MODKEY-5 +$MODKEY-6 +$MODKEY-7 +$MODKEY-8 +$MODKEY-9 $MODKEY-Shift-1 $MODKEY-Shift-2 $MODKEY-Shift-3 @@ -126,6 +135,8 @@ do xwrite /ws/sel/ctl select next;; $MODKEY-k) xwrite /ws/sel/ctl select prev;; + $MODKEY-[0-9]) + xwrite /ws/sel/sel/tags `echo $1 | sed 's/.*-//'`;; $MODKEY-Shift-[0-9]) xwrite /ctl select `echo $1 | sed 's/.*-//'`;; esac;;