using double-linked list in order to get correct prev focus handling 72707c2f
arg@10ksloc.org · 2006-07-20 16:54 4 file(s) · +45 −21
client.c +31 −15
77 77
		c = getnext(clients, tsel);
78 78
	if(c) {
79 79
		higher(c);
80 -
		c->revert = sel;
81 80
		focus(c);
82 81
	}
83 82
}
93 92
	if(sel->ismax)
94 93
		togglemax(NULL);
95 94
96 -
	if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
95 +
	if(!(c = getprev(sel->prev))) {
96 +
		for(c = clients; c && c->next; c = c->next);
97 +
		c = getprev(c);
98 +
	}
99 +
	if(c) {
97 100
		higher(c);
98 101
		focus(c);
99 102
	}
127 130
	int dx = 0, dy = 0;
128 131
129 132
	switch(c->grav) {
133 +
	default:
134 +
		break;
130 135
	case StaticGravity:
131 136
	case NorthWestGravity:
132 137
	case NorthGravity:
143 148
	case SouthWestGravity:
144 149
		dy = -(c->h);
145 150
		break;
146 -
	default:
147 -
		break;
148 151
	}
149 152
150 153
	switch (c->grav) {
154 +
	default:
155 +
		break;
151 156
	case StaticGravity:
152 157
	case NorthWestGravity:
153 158
	case WestGravity:
163 168
	case EastGravity:
164 169
	case SouthEastGravity:
165 170
		dx = -(c->w + c->border);
166 -
		break;
167 -
	default:
168 171
		break;
169 172
	}
170 173
204 207
void
205 208
manage(Window w, XWindowAttributes *wa)
206 209
{
207 -
	int diff;
208 210
	Client *c;
209 211
	Window trans;
210 212
	XSetWindowAttributes twa;
224 226
	c->proto = getproto(c->win);
225 227
	setsize(c);
226 228
	XSelectInput(dpy, c->win,
227 -
			StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
229 +
		StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
228 230
	XGetTransientForHint(dpy, c->win, &trans);
229 231
	twa.override_redirect = 1;
230 232
	twa.background_pixmap = ParentRelative;
237 239
238 240
	settags(c);
239 241
242 +
	if(clients)
243 +
		clients->prev = c;
240 244
	c->next = clients;
241 245
	clients = c;
242 246
264 268
	else {
265 269
		XMapRaised(dpy, c->win);
266 270
		XMapRaised(dpy, c->title);
271 +
267 272
	}
268 273
}
269 274
273 278
	Client **l;
274 279
275 280
	for(l = &clients; *l && *l != c; l = &(*l)->next);
281 +
	if(c->prev)
282 +
		c->prev->next = c->next;
283 +
	if(c->next)
284 +
		c->next->prev = c->prev;
276 285
	*l = c->next;
277 286
278 -
	c->next = clients; /* pop */
287 +
	if(clients)
288 +
		clients->prev = c;
289 +
	c->next = clients;
279 290
	clients = c;
280 291
	arrange(NULL);
281 292
}
439 450
	XDestroyWindow(dpy, c->title);
440 451
441 452
	for(l = &clients; *l && *l != c; l = &(*l)->next);
453 +
	if(c->prev)
454 +
		c->prev->next = c->next;
455 +
	if(c->next)
456 +
		c->next->prev = c->prev;
442 457
	*l = c->next;
443 -
	for(l = &clients; *l; l = &(*l)->next)
444 -
		if((*l)->revert == c)
445 -
			(*l)->revert = NULL;
446 -
	if(sel == c)
447 -
		sel = sel->revert ? sel->revert : clients;
448 -
458 +
	if(sel == c) {
459 +
		sel = getnext(c->next, tsel);
460 +
		if(!sel)
461 +
			sel = getprev(c->prev);
462 +
		if(!sel)
463 +
			sel = clients;
464 +
	}
449 465
	free(c);
450 466
451 467
	XSync(dpy, False);
config.mk +5 −5
13 13
LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
14 14
15 15
# Linux/BSD
16 -
CFLAGS = -O3 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
17 -
	-DVERSION=\"${VERSION}\"
18 -
LDFLAGS = ${LIBS}
19 -
#CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
16 +
#CFLAGS = -O3 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
20 17
#	-DVERSION=\"${VERSION}\"
21 -
#LDFLAGS = -g ${LIBS}
18 +
#LDFLAGS = ${LIBS}
19 +
CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
20 +
	-DVERSION=\"${VERSION}\"
21 +
LDFLAGS = -g ${LIBS}
22 22
23 23
24 24
# Solaris
dwm.h +2 −1
76 76
	Bool isfloat;
77 77
	Bool ismax;
78 78
	Client *next;
79 -
	Client *revert;
79 +
	Client *prev;
80 80
	Window win;
81 81
	Window title;
82 82
};
135 135
extern void dofloat(Arg *arg);
136 136
extern void dotile(Arg *arg);
137 137
extern Client *getnext(Client *c, unsigned int t);
138 +
extern Client *getprev(Client *c);
138 139
extern void heretag(Arg *arg);
139 140
extern void replacetag(Arg *arg);
140 141
extern void settags(Client *c);
tag.c +7 −0
140 140
	return c;
141 141
}
142 142
143 +
Client *
144 +
getprev(Client *c)
145 +
{
146 +
	for(; c && !c->tags[tsel]; c = c->prev);
147 +
	return c;
148 +
}
149 +
143 150
void
144 151
heretag(Arg *arg)
145 152
{