aewl

annotate client.c @ 54:a64602deac83

except improvements to the mouse handling this is already nearly feature complete
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 21:49:55 +0200
parents 529901e6a227
children fcbf7213d96f
rev   line source
garbeam@5 1 /*
garbeam@5 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@5 3 * See LICENSE file for license details.
garbeam@5 4 */
garbeam@5 5
garbeam@10 6 #include <stdlib.h>
garbeam@51 7 #include <stdio.h>
garbeam@5 8 #include <string.h>
garbeam@5 9 #include <X11/Xatom.h>
garbeam@32 10 #include <X11/Xutil.h>
garbeam@5 11
garbeam@43 12 #include "dwm.h"
garbeam@5 13
garbeam@53 14 void (*arrange)(Arg *) = tiling;
garbeam@49 15
garbeam@51 16 static Rule rule[] = {
garbeam@53 17 /* class instance tags floating */
garbeam@53 18 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
garbeam@51 19 };
garbeam@50 20
garbeam@49 21 static Client *
garbeam@49 22 next(Client *c)
garbeam@49 23 {
garbeam@50 24 for(; c && !c->tags[tsel]; c = c->next);
garbeam@49 25 return c;
garbeam@49 26 }
garbeam@49 27
garbeam@50 28 void
garbeam@50 29 zoom(Arg *arg)
garbeam@49 30 {
garbeam@51 31 Client **l, *old;
garbeam@50 32
garbeam@51 33 if(!(old = sel))
garbeam@50 34 return;
garbeam@50 35
garbeam@50 36 for(l = &clients; *l && *l != sel; l = &(*l)->next);
garbeam@50 37 *l = sel->next;
garbeam@50 38
garbeam@51 39 old->next = clients; /* pop */
garbeam@51 40 clients = old;
garbeam@51 41 sel = old;
garbeam@50 42 arrange(NULL);
garbeam@50 43 focus(sel);
garbeam@49 44 }
garbeam@31 45
garbeam@27 46 void
garbeam@49 47 max(Arg *arg)
garbeam@28 48 {
garbeam@50 49 if(!sel)
garbeam@28 50 return;
garbeam@50 51 sel->x = sx;
garbeam@50 52 sel->y = sy;
garbeam@50 53 sel->w = sw - 2 * sel->border;
garbeam@50 54 sel->h = sh - 2 * sel->border;
garbeam@50 55 craise(sel);
garbeam@52 56 resize(sel, False);
garbeam@29 57 discard_events(EnterWindowMask);
garbeam@28 58 }
garbeam@28 59
garbeam@46 60 void
garbeam@50 61 view(Arg *arg)
garbeam@50 62 {
garbeam@54 63 Client *c;
garbeam@54 64
garbeam@50 65 tsel = arg->i;
garbeam@50 66 arrange(NULL);
garbeam@54 67
garbeam@54 68 for(c = clients; c; c = next(c->next))
garbeam@54 69 draw_client(c);
garbeam@50 70 }
garbeam@50 71
garbeam@50 72 void
garbeam@53 73 tappend(Arg *arg)
garbeam@49 74 {
garbeam@50 75 if(!sel)
garbeam@49 76 return;
garbeam@49 77
garbeam@53 78 sel->tags[arg->i] = tags[arg->i];
garbeam@53 79 arrange(NULL);
garbeam@53 80 }
garbeam@49 81
garbeam@53 82 void
garbeam@53 83 ttrunc(Arg *arg)
garbeam@53 84 {
garbeam@53 85 int i;
garbeam@53 86 if(!sel)
garbeam@53 87 return;
garbeam@53 88
garbeam@53 89 for(i = 0; i < TLast; i++)
garbeam@53 90 sel->tags[i] = NULL;
garbeam@53 91 tappend(arg);
garbeam@49 92 }
garbeam@49 93
garbeam@50 94 static void
garbeam@50 95 ban_client(Client *c)
garbeam@50 96 {
garbeam@50 97 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
garbeam@50 98 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
garbeam@50 99 }
garbeam@50 100
garbeam@49 101 void
garbeam@49 102 floating(Arg *arg)
garbeam@31 103 {
garbeam@31 104 Client *c;
garbeam@31 105
garbeam@46 106 arrange = floating;
garbeam@50 107 for(c = clients; c; c = c->next) {
garbeam@50 108 if(c->tags[tsel])
garbeam@52 109 resize(c, True);
garbeam@50 110 else
garbeam@50 111 ban_client(c);
garbeam@50 112 }
garbeam@50 113 if(sel && !sel->tags[tsel]) {
garbeam@50 114 if((sel = next(clients))) {
garbeam@50 115 craise(sel);
garbeam@50 116 focus(sel);
garbeam@50 117 }
garbeam@50 118 }
garbeam@31 119 discard_events(EnterWindowMask);
garbeam@31 120 }
garbeam@31 121
garbeam@46 122 void
garbeam@49 123 tiling(Arg *arg)
garbeam@27 124 {
garbeam@27 125 Client *c;
garbeam@51 126 int n, i, w, h;
garbeam@27 127
garbeam@51 128 w = sw - mw;
garbeam@46 129 arrange = tiling;
garbeam@51 130 for(n = 0, c = clients; c; c = c->next)
garbeam@53 131 if(c->tags[tsel] && !c->floating)
garbeam@51 132 n++;
garbeam@50 133
garbeam@52 134 h = (n > 1) ? sh / (n - 1) : sh;
garbeam@27 135
garbeam@51 136 for(i = 0, c = clients; c; c = c->next) {
garbeam@50 137 if(c->tags[tsel]) {
garbeam@53 138 if(c->floating) {
garbeam@53 139 craise(c);
garbeam@53 140 resize(c, True);
garbeam@53 141 continue;
garbeam@53 142 }
garbeam@51 143 if(n == 1) {
garbeam@51 144 c->x = sx;
garbeam@51 145 c->y = sy;
garbeam@52 146 c->w = sw - 2 * c->border;
garbeam@52 147 c->h = sh - 2 * c->border;
garbeam@51 148 }
garbeam@52 149 else if(i == 0) {
garbeam@51 150 c->x = sx;
garbeam@51 151 c->y = sy;
garbeam@52 152 c->w = mw - 2 * c->border;
garbeam@52 153 c->h = sh - 2 * c->border;
garbeam@51 154 }
garbeam@51 155 else {
garbeam@51 156 c->x = sx + mw;
garbeam@52 157 c->y = sy + (i - 1) * h;
garbeam@52 158 c->w = w - 2 * c->border;
garbeam@52 159 c->h = h - 2 * c->border;
garbeam@51 160 }
garbeam@52 161 resize(c, False);
garbeam@51 162 i++;
garbeam@50 163 }
garbeam@50 164 else
garbeam@50 165 ban_client(c);
garbeam@50 166 }
garbeam@50 167 if(sel && !sel->tags[tsel]) {
garbeam@50 168 if((sel = next(clients))) {
garbeam@50 169 craise(sel);
garbeam@50 170 focus(sel);
garbeam@27 171 }
garbeam@27 172 }
garbeam@29 173 discard_events(EnterWindowMask);
garbeam@27 174 }
garbeam@27 175
garbeam@27 176 void
garbeam@49 177 prevc(Arg *arg)
garbeam@27 178 {
garbeam@49 179 Client *c;
garbeam@27 180
garbeam@50 181 if(!sel)
garbeam@27 182 return;
garbeam@49 183
garbeam@50 184 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
garbeam@49 185 craise(c);
garbeam@49 186 focus(c);
garbeam@49 187 }
garbeam@27 188 }
garbeam@27 189
garbeam@27 190 void
garbeam@49 191 nextc(Arg *arg)
garbeam@27 192 {
garbeam@49 193 Client *c;
garbeam@49 194
garbeam@50 195 if(!sel)
garbeam@49 196 return;
garbeam@49 197
garbeam@50 198 if(!(c = next(sel->next)))
garbeam@50 199 c = next(clients);
garbeam@49 200 if(c) {
garbeam@49 201 craise(c);
garbeam@50 202 c->revert = sel;
garbeam@49 203 focus(c);
garbeam@49 204 }
garbeam@49 205 }
garbeam@49 206
garbeam@49 207 void
garbeam@49 208 ckill(Arg *arg)
garbeam@49 209 {
garbeam@50 210 if(!sel)
garbeam@27 211 return;
garbeam@50 212 if(sel->proto & WM_PROTOCOL_DELWIN)
garbeam@50 213 send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
garbeam@27 214 else
garbeam@50 215 XKillClient(dpy, sel->win);
garbeam@27 216 }
garbeam@27 217
garbeam@26 218 static void
garbeam@26 219 resize_title(Client *c)
garbeam@26 220 {
garbeam@31 221 int i;
garbeam@31 222
garbeam@31 223 c->tw = 0;
garbeam@31 224 for(i = 0; i < TLast; i++)
garbeam@31 225 if(c->tags[i])
garbeam@43 226 c->tw += textw(c->tags[i]) + dc.font.height;
garbeam@43 227 c->tw += textw(c->name) + dc.font.height;
garbeam@26 228 if(c->tw > c->w)
garbeam@26 229 c->tw = c->w + 2;
garbeam@26 230 c->tx = c->x + c->w - c->tw + 2;
garbeam@26 231 c->ty = c->y;
garbeam@26 232 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
garbeam@26 233 }
garbeam@18 234
garbeam@13 235 void
garbeam@13 236 update_name(Client *c)
garbeam@5 237 {
garbeam@5 238 XTextProperty name;
garbeam@5 239 int n;
garbeam@7 240 char **list = NULL;
garbeam@5 241
garbeam@5 242 name.nitems = 0;
garbeam@5 243 c->name[0] = 0;
garbeam@5 244 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
garbeam@5 245 if(!name.nitems)
garbeam@5 246 XGetWMName(dpy, c->win, &name);
garbeam@5 247 if(!name.nitems)
garbeam@5 248 return;
garbeam@5 249 if(name.encoding == XA_STRING)
garbeam@5 250 strncpy(c->name, (char *)name.value, sizeof(c->name));
garbeam@5 251 else {
garbeam@5 252 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
garbeam@5 253 && n > 0 && *list)
garbeam@5 254 {
garbeam@5 255 strncpy(c->name, *list, sizeof(c->name));
garbeam@5 256 XFreeStringList(list);
garbeam@5 257 }
garbeam@5 258 }
garbeam@5 259 XFree(name.value);
garbeam@26 260 resize_title(c);
garbeam@5 261 }
garbeam@5 262
garbeam@10 263 void
garbeam@20 264 update_size(Client *c)
garbeam@20 265 {
garbeam@20 266 XSizeHints size;
garbeam@20 267 long msize;
garbeam@20 268 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
garbeam@20 269 size.flags = PSize;
garbeam@20 270 c->flags = size.flags;
garbeam@21 271 if(c->flags & PBaseSize) {
garbeam@21 272 c->basew = size.base_width;
garbeam@21 273 c->baseh = size.base_height;
garbeam@21 274 }
garbeam@21 275 else
garbeam@21 276 c->basew = c->baseh = 0;
garbeam@21 277 if(c->flags & PResizeInc) {
garbeam@21 278 c->incw = size.width_inc;
garbeam@21 279 c->inch = size.height_inc;
garbeam@21 280 }
garbeam@21 281 else
garbeam@21 282 c->incw = c->inch = 0;
garbeam@21 283 if(c->flags & PMaxSize) {
garbeam@21 284 c->maxw = size.max_width;
garbeam@21 285 c->maxh = size.max_height;
garbeam@21 286 }
garbeam@21 287 else
garbeam@21 288 c->maxw = c->maxh = 0;
garbeam@21 289 if(c->flags & PMinSize) {
garbeam@21 290 c->minw = size.min_width;
garbeam@21 291 c->minh = size.min_height;
garbeam@21 292 }
garbeam@21 293 else
garbeam@21 294 c->minw = c->minh = 0;
garbeam@29 295 if(c->flags & PWinGravity)
garbeam@29 296 c->grav = size.win_gravity;
garbeam@29 297 else
garbeam@29 298 c->grav = NorthWestGravity;
garbeam@20 299 }
garbeam@20 300
garbeam@20 301 void
garbeam@32 302 craise(Client *c)
garbeam@26 303 {
garbeam@26 304 XRaiseWindow(dpy, c->win);
garbeam@26 305 XRaiseWindow(dpy, c->title);
garbeam@26 306 }
garbeam@26 307
garbeam@26 308 void
garbeam@26 309 lower(Client *c)
garbeam@26 310 {
garbeam@26 311 XLowerWindow(dpy, c->title);
garbeam@26 312 XLowerWindow(dpy, c->win);
garbeam@26 313 }
garbeam@26 314
garbeam@26 315 void
garbeam@13 316 focus(Client *c)
garbeam@13 317 {
garbeam@52 318 Client *old = sel;
garbeam@52 319
garbeam@50 320 sel = c;
garbeam@52 321 if(old && old != c)
garbeam@52 322 draw_client(old);
garbeam@27 323 draw_client(c);
garbeam@26 324 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
garbeam@13 325 XFlush(dpy);
garbeam@45 326 discard_events(EnterWindowMask);
garbeam@13 327 }
garbeam@13 328
garbeam@51 329 static void
garbeam@51 330 init_tags(Client *c)
garbeam@51 331 {
garbeam@51 332 XClassHint ch;
garbeam@51 333 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
garbeam@51 334 unsigned int i, j;
garbeam@51 335 Bool matched = False;
garbeam@51 336
garbeam@51 337 if(!len) {
garbeam@51 338 c->tags[tsel] = tags[tsel];
garbeam@51 339 return;
garbeam@51 340 }
garbeam@51 341
garbeam@51 342 if(XGetClassHint(dpy, c->win, &ch)) {
garbeam@51 343 if(ch.res_class && ch.res_name) {
garbeam@51 344 for(i = 0; i < len; i++)
garbeam@51 345 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
garbeam@51 346 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
garbeam@51 347 {
garbeam@51 348 for(j = 0; j < TLast; j++)
garbeam@51 349 c->tags[j] = rule[i].tags[j];
garbeam@53 350 c->floating = rule[i].floating;
garbeam@51 351 matched = True;
garbeam@51 352 break;
garbeam@51 353 }
garbeam@51 354 }
garbeam@51 355 if(ch.res_class)
garbeam@51 356 XFree(ch.res_class);
garbeam@51 357 if(ch.res_name)
garbeam@51 358 XFree(ch.res_name);
garbeam@51 359 }
garbeam@51 360
garbeam@51 361 if(!matched)
garbeam@51 362 c->tags[tsel] = tags[tsel];
garbeam@51 363 }
garbeam@51 364
garbeam@13 365 void
garbeam@10 366 manage(Window w, XWindowAttributes *wa)
garbeam@5 367 {
garbeam@50 368 Client *c, **l;
garbeam@5 369 XSetWindowAttributes twa;
garbeam@53 370 Window trans;
garbeam@5 371
garbeam@5 372 c = emallocz(sizeof(Client));
garbeam@5 373 c->win = w;
garbeam@22 374 c->tx = c->x = wa->x;
garbeam@22 375 c->ty = c->y = wa->y;
garbeam@22 376 c->tw = c->w = wa->width;
garbeam@20 377 c->h = wa->height;
garbeam@32 378 c->th = th;
garbeam@29 379 c->border = 1;
garbeam@50 380 c->proto = win_proto(c->win);
garbeam@20 381 update_size(c);
garbeam@26 382 XSelectInput(dpy, c->win,
garbeam@26 383 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
garbeam@53 384 XGetTransientForHint(dpy, c->win, &trans);
garbeam@5 385 twa.override_redirect = 1;
garbeam@5 386 twa.background_pixmap = ParentRelative;
garbeam@23 387 twa.event_mask = ExposureMask;
garbeam@5 388
garbeam@22 389 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
garbeam@20 390 0, DefaultDepth(dpy, screen), CopyFromParent,
garbeam@5 391 DefaultVisual(dpy, screen),
garbeam@5 392 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
garbeam@31 393
garbeam@21 394 update_name(c);
garbeam@51 395 init_tags(c);
garbeam@49 396
garbeam@50 397 for(l = &clients; *l; l = &(*l)->next);
garbeam@50 398 c->next = *l; /* *l == nil */
garbeam@50 399 *l = c;
garbeam@49 400
garbeam@43 401 XSetWindowBorderWidth(dpy, c->win, 1);
garbeam@26 402 XMapRaised(dpy, c->win);
garbeam@26 403 XMapRaised(dpy, c->title);
garbeam@19 404 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
garbeam@19 405 GrabModeAsync, GrabModeSync, None, None);
garbeam@19 406 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
garbeam@19 407 GrabModeAsync, GrabModeSync, None, None);
garbeam@19 408 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
garbeam@18 409 GrabModeAsync, GrabModeSync, None, None);
garbeam@53 410
garbeam@53 411 if(!c->floating)
garbeam@53 412 c->floating = trans
garbeam@53 413 || ((c->maxw == c->minw) && (c->maxh == c->minh));
garbeam@53 414
garbeam@46 415 arrange(NULL);
garbeam@51 416 if(c->tags[tsel])
garbeam@51 417 focus(c);
garbeam@51 418 else
garbeam@51 419 ban_client(c);
garbeam@5 420 }
garbeam@9 421
garbeam@18 422 void
garbeam@29 423 gravitate(Client *c, Bool invert)
garbeam@29 424 {
garbeam@29 425 int dx = 0, dy = 0;
garbeam@29 426
garbeam@29 427 switch(c->grav) {
garbeam@29 428 case StaticGravity:
garbeam@29 429 case NorthWestGravity:
garbeam@29 430 case NorthGravity:
garbeam@29 431 case NorthEastGravity:
garbeam@29 432 dy = c->border;
garbeam@29 433 break;
garbeam@29 434 case EastGravity:
garbeam@29 435 case CenterGravity:
garbeam@29 436 case WestGravity:
garbeam@29 437 dy = -(c->h / 2) + c->border;
garbeam@29 438 break;
garbeam@29 439 case SouthEastGravity:
garbeam@29 440 case SouthGravity:
garbeam@29 441 case SouthWestGravity:
garbeam@29 442 dy = -c->h;
garbeam@29 443 break;
garbeam@29 444 default:
garbeam@29 445 break;
garbeam@29 446 }
garbeam@29 447
garbeam@29 448 switch (c->grav) {
garbeam@29 449 case StaticGravity:
garbeam@29 450 case NorthWestGravity:
garbeam@29 451 case WestGravity:
garbeam@29 452 case SouthWestGravity:
garbeam@29 453 dx = c->border;
garbeam@29 454 break;
garbeam@29 455 case NorthGravity:
garbeam@29 456 case CenterGravity:
garbeam@29 457 case SouthGravity:
garbeam@29 458 dx = -(c->w / 2) + c->border;
garbeam@29 459 break;
garbeam@29 460 case NorthEastGravity:
garbeam@29 461 case EastGravity:
garbeam@29 462 case SouthEastGravity:
garbeam@29 463 dx = -(c->w + c->border);
garbeam@29 464 break;
garbeam@29 465 default:
garbeam@29 466 break;
garbeam@29 467 }
garbeam@29 468
garbeam@29 469 if(invert) {
garbeam@29 470 dx = -dx;
garbeam@29 471 dy = -dy;
garbeam@29 472 }
garbeam@29 473 c->x += dx;
garbeam@29 474 c->y += dy;
garbeam@29 475 }
garbeam@29 476
garbeam@31 477
garbeam@29 478 void
garbeam@52 479 resize(Client *c, Bool inc)
garbeam@18 480 {
garbeam@18 481 XConfigureEvent e;
garbeam@18 482
garbeam@52 483 if(inc) {
garbeam@52 484 if(c->incw)
garbeam@52 485 c->w -= (c->w - c->basew) % c->incw;
garbeam@52 486 if(c->inch)
garbeam@52 487 c->h -= (c->h - c->baseh) % c->inch;
garbeam@52 488 }
garbeam@31 489 if(c->minw && c->w < c->minw)
garbeam@31 490 c->w = c->minw;
garbeam@31 491 if(c->minh && c->h < c->minh)
garbeam@31 492 c->h = c->minh;
garbeam@31 493 if(c->maxw && c->w > c->maxw)
garbeam@31 494 c->w = c->maxw;
garbeam@31 495 if(c->maxh && c->h > c->maxh)
garbeam@31 496 c->h = c->maxh;
garbeam@26 497 resize_title(c);
garbeam@20 498 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
garbeam@18 499 e.type = ConfigureNotify;
garbeam@18 500 e.event = c->win;
garbeam@18 501 e.window = c->win;
garbeam@20 502 e.x = c->x;
garbeam@20 503 e.y = c->y;
garbeam@20 504 e.width = c->w;
garbeam@20 505 e.height = c->h;
garbeam@29 506 e.border_width = c->border;
garbeam@18 507 e.above = None;
garbeam@18 508 e.override_redirect = False;
garbeam@18 509 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
garbeam@18 510 XFlush(dpy);
garbeam@18 511 }
garbeam@18 512
garbeam@10 513 static int
garbeam@33 514 dummy_error_handler(Display *dsply, XErrorEvent *err)
garbeam@10 515 {
garbeam@10 516 return 0;
garbeam@10 517 }
garbeam@10 518
garbeam@10 519 void
garbeam@10 520 unmanage(Client *c)
garbeam@10 521 {
garbeam@50 522 Client **l;
garbeam@50 523
garbeam@10 524 XGrabServer(dpy);
garbeam@10 525 XSetErrorHandler(dummy_error_handler);
garbeam@10 526
garbeam@18 527 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
garbeam@10 528 XDestroyWindow(dpy, c->title);
garbeam@10 529
garbeam@50 530 for(l = &clients; *l && *l != c; l = &(*l)->next);
garbeam@50 531 *l = c->next;
garbeam@50 532 for(l = &clients; *l; l = &(*l)->next)
garbeam@50 533 if((*l)->revert == c)
garbeam@50 534 (*l)->revert = NULL;
garbeam@50 535 if(sel == c)
garbeam@50 536 sel = sel->revert ? sel->revert : clients;
garbeam@49 537
garbeam@10 538 free(c);
garbeam@10 539
garbeam@10 540 XFlush(dpy);
garbeam@10 541 XSetErrorHandler(error_handler);
garbeam@10 542 XUngrabServer(dpy);
garbeam@46 543 arrange(NULL);
garbeam@50 544 if(sel)
garbeam@50 545 focus(sel);
garbeam@10 546 }
garbeam@10 547
garbeam@23 548 Client *
garbeam@23 549 gettitle(Window w)
garbeam@23 550 {
garbeam@23 551 Client *c;
garbeam@50 552 for(c = clients; c; c = c->next)
garbeam@23 553 if(c->title == w)
garbeam@23 554 return c;
garbeam@23 555 return NULL;
garbeam@23 556 }
garbeam@10 557
garbeam@9 558 Client *
garbeam@9 559 getclient(Window w)
garbeam@9 560 {
garbeam@9 561 Client *c;
garbeam@50 562 for(c = clients; c; c = c->next)
garbeam@9 563 if(c->win == w)
garbeam@9 564 return c;
garbeam@9 565 return NULL;
garbeam@9 566 }
garbeam@13 567
garbeam@14 568 void
garbeam@14 569 draw_client(Client *c)
garbeam@14 570 {
garbeam@31 571 int i;
garbeam@52 572 if(c == sel) {
garbeam@52 573 XUnmapWindow(dpy, c->title);
garbeam@52 574 XSetWindowBorder(dpy, c->win, dc.fg);
garbeam@26 575 return;
garbeam@52 576 }
garbeam@52 577
garbeam@52 578 XSetWindowBorder(dpy, c->win, dc.bg);
garbeam@52 579 XMapWindow(dpy, c->title);
garbeam@14 580
garbeam@34 581 dc.x = dc.y = 0;
garbeam@34 582 dc.h = c->th;
garbeam@14 583
garbeam@34 584 dc.w = 0;
garbeam@31 585 for(i = 0; i < TLast; i++) {
garbeam@31 586 if(c->tags[i]) {
garbeam@34 587 dc.x += dc.w;
garbeam@43 588 dc.w = textw(c->tags[i]) + dc.font.height;
garbeam@34 589 draw(True, c->tags[i]);
garbeam@31 590 }
garbeam@31 591 }
garbeam@34 592 dc.x += dc.w;
garbeam@43 593 dc.w = textw(c->name) + dc.font.height;
garbeam@34 594 draw(True, c->name);
garbeam@34 595 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
garbeam@22 596 0, 0, c->tw, c->th, 0, 0);
garbeam@21 597 XFlush(dpy);
garbeam@14 598 }