commit d2825a06e2c6fe920d618e748cfc4869ba909e9e
parent 20a9a089a771a3b1347eb8c630c0e2c2de95e541
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Tue, 11 Apr 2006 10:16:01 +0200
fixed several update_views issues
Diffstat:
4 files changed, 75 insertions(+), 69 deletions(-)
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -620,14 +620,3 @@ cid2index(unsigned short id)
return i;
return -1;
}
-
-Bool
-clienthastag(Client *c, const char *t)
-{
- unsigned int i;
- for(i = 0; i < c->view.size; i++)
- if(!strncmp(c->view.data[i]->name, t, strlen(t))
- || !strncmp(c->tags, "*", 2))
- return True;
- return False;
-}
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -1210,7 +1210,7 @@ xwrite(IXPConn *c, Fcall *fcall)
else
cl = client.data[i1];
cext_strlcpy(cl->tags, buf, sizeof(cl->tags));
- update_views(cl);
+ update_views();
draw_client(cl);
break;
case FsFgeom:
diff --git a/cmd/wm/view.c b/cmd/wm/view.c
@@ -8,7 +8,7 @@
#include "wm.h"
-Vector *
+static Vector *
view2vector(ViewVector *vv)
{
return (Vector *) vv;
@@ -152,27 +152,18 @@ name2view(char *name)
View *
get_view(char *name)
{
- unsigned int i;
View *v = name2view(name);
-
- if(!v)
- v = alloc_view(name);
-
- for(i = 0; i < client.size; i++)
- if(strstr(client.data[i]->tags, "*"))
- attach_toview(v, client.data[i]);
-
- return v;
+ return v ? v : alloc_view(name);
}
static Bool
-hasclient(View *v)
+isempty(View *v)
{
unsigned int i;
for(i = 0; i < v->area.size; i++)
if(v->area.data[i]->frame.size)
- return True;
- return False;
+ return False;
+ return True;
}
void
@@ -185,11 +176,11 @@ select_view(char *arg)
}
static Bool
-clientofview(View *v, Client *c)
+isclientof(View *v, Client *c)
{
unsigned int i;
- for(i = 0; i < c->view.size; i++)
- if(v == c->view.data[i])
+ for(i = 0; i < v->area.size; i++)
+ if(clientofarea(v->area.data[i], c))
return True;
return False;
}
@@ -199,8 +190,6 @@ detach_fromview(View *v, Client *c)
{
unsigned int i;
- fprintf(stderr, "detach_fromview: %s\n", c->name);
- cext_vdetach(view2vector(&c->view), v);
for(i = 0; i < v->area.size; i++) {
if(clientofarea(v->area.data[i], c)) {
detach_fromarea(v->area.data[i], c);
@@ -214,7 +203,7 @@ attach_toview(View *v, Client *c)
{
Area *a;
- if(clientofview(v, c))
+ if(isclientof(v, c))
return;
if(c->trans || c->floating)
@@ -225,7 +214,6 @@ attach_toview(View *v, Client *c)
attach_toarea(a, c);
map_client(c);
XMapWindow(dpy, c->framewin);
- cext_vattach(view2vector(&c->view), v);
}
Client *
@@ -303,48 +291,80 @@ arrange_view(View *v, Bool dirty)
}
}
-void
-update_views(Client *c)
+static void
+update_client_views(Client *c)
+{
+ char buf[256];
+ char *toks[16];
+ unsigned int i, n;
+
+ cext_strlcpy(buf, c->tags, sizeof(buf));
+ n = cext_tokenize(toks, 16, buf, '+');
+
+ while(c->view.size)
+ cext_vdetach(view2vector(&c->view), c->view.data[0]);
+
+ for(i = 0; i < n; i++) {
+ if(!strncmp(toks[i], "*", 2))
+ continue;
+ cext_vattach(view2vector(&c->view), get_view(toks[i]));
+ }
+}
+
+static Bool
+isviewof(Client *c, View *v)
+{
+ unsigned int i;
+ for(i = 0; i < c->view.size; i++)
+ if(c->view.data[i] == v)
+ return True;
+ return False;
+}
+
+static View *
+emptyview()
{
unsigned int i;
+ for(i = 0; i < view.size; i++)
+ if(isempty(view.data[i]))
+ return view.data[i];
+ return nil;
+}
- if(c) {
- char buf[256];
- char *toks[16];
- unsigned int j, n;
- Bool match;
+void
+update_views()
+{
+ unsigned int i, j;
+ View *v, *old = view.size ? view.data[sel] : nil;
- cext_strlcpy(buf, c->tags, sizeof(buf));
- n = cext_tokenize(toks, 16, buf, '+');
+ for(i = 0; i < client.size; i++)
+ update_client_views(client.data[i]);
- for(i = 0; i < n; i++) {
- if(!strncmp(toks[i], "*", 2)) {
- for(j = 0; j < view.size; j++) {
+ for(i = 0; i < client.size; i++) {
+ Client *c = client.data[i];
+ for(j = 0; j < view.size; j++) {
+ if(strstr(c->tags, "*"))
+ attach_toview(view.data[j], c);
+ else if(isviewof(c, view.data[j])) {
+ if(!isclientof(view.data[j], c))
attach_toview(view.data[j], c);
- }
}
- else
- attach_toview(get_view(toks[i]), c);
- }
-
- for(i = 0; i < c->view.size; i++) {
- View *v = c->view.data[i];
- match = False;
- for(j = 0; j < n; j++) {
- if(!strncmp(v->name, toks[j], sizeof(v->name))
- || !strncmp(toks[j], "*", 2))
- match = True;
+ else {
+ if(isclientof(view.data[j], c))
+ detach_fromview(view.data[j], c);
}
- if(!match)
- detach_fromview(v, c);
}
}
- for(i = 0; i < view.size; i++)
- if(!hasclient(view.data[i]))
- destroy_view(view.data[i]);
+ while((v = emptyview())) {
+ if(v == old)
+ old = nil;
+ destroy_view(v);
+ }
- if(view.size)
+ if(old)
+ focus_view(old);
+ else if(view.size)
focus_view(view.data[sel]);
else
update_bar_tags();
@@ -354,8 +374,7 @@ void
retag()
{
unsigned int i;
- for(i = 0; i < client.size; i++) {
+ for(i = 0; i < client.size; i++)
match_tags(client.data[i], False);
- update_views(client.data[i]);
- }
+ update_views();
}
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -226,7 +226,6 @@ void send2area_client(Client *c, char *arg);
void resize_all_clients();
void focus(Client *c);
int cid2index(unsigned short id);
-Bool clienthastag(Client *c, const char *t);
void swap_client(Client *c, char *arg);
/* event.c */
@@ -262,7 +261,6 @@ void update_rules();
void match_tags(Client *c, Bool newclient);
/* view.c */
-Vector *view2vector(ViewVector *vv);
void arrange_view(View *v, Bool dirty);
View *alloc_view(char *name);
void focus_view(View *v);
@@ -277,7 +275,7 @@ void restack_view(View *v);
View *name2view(char *name);
void destroy_view(View *v);
View *get_view(char *name);
-void update_views(Client *c);
+void update_views();
void retag();
/* wm.c */