about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--client.c5
-rw-r--r--dwm.h3
-rw-r--r--tag.c6
-rw-r--r--view.c75
4 files changed, 33 insertions, 56 deletions
diff --git a/client.c b/client.c
index 0a7df77..9645444 100644
--- a/client.c
+++ b/client.c
@@ -241,7 +241,10 @@ manage(Window w, XWindowAttributes *wa)
 			|| (c->maxw && c->minw &&
 				c->maxw == c->minw && c->maxh == c->minh);
 
-	attach(c);
+	if(clients)
+		clients->prev = c;
+	c->next = clients;
+	clients = c;
 
 	settitle(c);
 	if(isvisible(c))
diff --git a/dwm.h b/dwm.h
index 6bb6b3a..b416851 100644
--- a/dwm.h
+++ b/dwm.h
@@ -56,7 +56,7 @@ struct Client {
 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
 	int grav;
 	long flags; 
-	unsigned int border;
+	unsigned int border, weight;
 	Bool isfloat;
 	Bool ismax;
 	Bool *tags;
@@ -127,7 +127,6 @@ extern void *erealloc(void *ptr, unsigned int size);
 extern void spawn(Arg *arg);
 
 /* view.c */
-extern void attach(Client *c);
 extern void detach(Client *c);
 extern void dofloat(Arg *arg);
 extern void dotile(Arg *arg);
diff --git a/tag.c b/tag.c
index 7bc4da0..a2e1c89 100644
--- a/tag.c
+++ b/tag.c
@@ -106,6 +106,8 @@ settags(Client *c)
 	if(!matched)
 		for(i = 0; i < ntags; i++)
 			c->tags[i] = seltag[i];
+	for(i = 0; i < ntags && !c->tags[i]; i++);
+	c->weight = i;
 }
 
 void
@@ -120,8 +122,6 @@ tag(Arg *arg)
 		sel->tags[i] = False;
 	sel->tags[arg->i] = True;
 	settitle(sel);
-	detach(sel);
-	attach(sel);
 	if(!isvisible(sel))
 		arrange(NULL);
 	else
@@ -141,8 +141,6 @@ toggletag(Arg *arg)
 	if(i == ntags)
 		sel->tags[arg->i] = True;
 	settitle(sel);
-	detach(sel);
-	attach(sel);
 	if(!isvisible(sel))
 		arrange(NULL);
 	else
diff --git a/view.c b/view.c
index ac336e3..3270160 100644
--- a/view.c
+++ b/view.c
@@ -6,62 +6,34 @@
 
 /* static */
 
-static Client *
-getslot(Client *c)
+static void
+reorder()
 {
-	unsigned int i, tic;
-	Client *p;
-
-	for(tic = 0; tic < ntags && !c->tags[tic]; tic++);
-	for(p = clients; p; p = p->next) {
-		for(i = 0; i < ntags && !p->tags[i]; i++);
-		if(tic < i)
-			return p;
-	}
-	return p;
-}
+	Client *c, *orig, *p;
 
-static Client *
-tail()
-{
-	Client *c;
-	for(c = clients; c && c->next; c = c->next);
-	return c;
-}
+	orig = clients;
+	clients = NULL;
 
-/* extern */
+	while((c = orig)) {
+		orig = orig->next;
+		detach(c);
 
-void (*arrange)(Arg *) = DEFMODE;
-
-void
-attach(Client *c)
-{
-	Client *p;
-
-	if(!clients) {
-		clients = c;
-		return;
-	}
-	if(!(p = getnext(clients)) && !(p = getslot(c))) {
-		p = tail();
+		for(p = clients; p && p->next && p->weight <= c->weight; p = p->next);
 		c->prev = p;
-		p->next = c;
-		return;
-	}
-
-	if(p == clients) {
-		c->next = clients;
-		clients->prev = c;
-		clients = c;
-	}
-	else {
-		p->prev->next = c;
-		c->prev = p->prev;
-		p->prev = c;
-		c->next = p;
+		if(p) {
+			if((c->next = p->next))
+				c->next->prev = c;
+			p->next = c;
+		}
+		else
+			clients = c;
 	}
 }
 
+/* extern */
+
+void (*arrange)(Arg *) = DEFMODE;
+
 void
 detach(Client *c)
 {
@@ -277,6 +249,7 @@ toggleview(Arg *arg)
 	for(i = 0; i < ntags && !seltag[i]; i++);
 	if(i == ntags)
 		seltag[arg->i] = True; /* cannot toggle last view */
+	reorder();
 	arrange(NULL);
 }
 
@@ -284,10 +257,12 @@ void
 view(Arg *arg)
 {
 	unsigned int i;
+	Client *c;
 
 	for(i = 0; i < ntags; i++)
 		seltag[i] = False;
 	seltag[arg->i] = True;
+	reorder();
 	arrange(NULL);
 }
 
@@ -303,7 +278,9 @@ zoom(Arg *arg)
 		if(!(c = getnext(c->next)))
 			return;
 	detach(c);
-	attach(c);
+	c->next = clients;
+	clients->prev = c;
+	clients = c;
 	focus(c);
 	arrange(NULL);
 }
37c980aad2fcdb54765433e02021ab1e0'>05d17773 ^
51530916 ^




05d17773 ^
51530916 ^




05d17773 ^

51530916 ^




05d17773 ^


51530916 ^




05d17773 ^


51530916 ^
d7494165 ^















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116