aewl

annotate client.c @ 70:e5fff8249705

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