aewl

annotate client.c @ 64:46d44d185464

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