Configuration file for DWM on MacBook Air
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
2.9 KiB

18 years ago
18 years ago
  1. /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. /* extern */
  6. void (*arrange)(void) = DEFMODE;
  7. void
  8. attach(Client *c) {
  9. if(clients)
  10. clients->prev = c;
  11. c->next = clients;
  12. clients = c;
  13. }
  14. void
  15. attachstack(Client *c) {
  16. c->snext = stack;
  17. stack = c;
  18. }
  19. void
  20. dofloat(void) {
  21. Client *c;
  22. for(c = clients; c; c = c->next) {
  23. if(isvisible(c)) {
  24. if(c->isbanned)
  25. XMoveWindow(dpy, c->win, c->x, c->y);
  26. c->isbanned = False;
  27. resize(c, c->x, c->y, c->w, c->h, True);
  28. }
  29. else {
  30. c->isbanned = True;
  31. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  32. }
  33. }
  34. if(!sel || !isvisible(sel)) {
  35. for(c = stack; c && !isvisible(c); c = c->snext);
  36. focus(c);
  37. }
  38. restack();
  39. }
  40. void
  41. detach(Client *c) {
  42. if(c->prev)
  43. c->prev->next = c->next;
  44. if(c->next)
  45. c->next->prev = c->prev;
  46. if(c == clients)
  47. clients = c->next;
  48. c->next = c->prev = NULL;
  49. }
  50. void
  51. detachstack(Client *c) {
  52. Client **tc;
  53. for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
  54. *tc = c->snext;
  55. }
  56. void
  57. focusnext(Arg *arg) {
  58. Client *c;
  59. if(!sel)
  60. return;
  61. for(c = sel->next; c && !isvisible(c); c = c->next);
  62. if(!c)
  63. for(c = clients; c && !isvisible(c); c = c->next);
  64. if(c) {
  65. focus(c);
  66. restack();
  67. }
  68. }
  69. void
  70. focusprev(Arg *arg) {
  71. Client *c;
  72. if(!sel)
  73. return;
  74. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  75. if(!c) {
  76. for(c = clients; c && c->next; c = c->next);
  77. for(; c && !isvisible(c); c = c->prev);
  78. }
  79. if(c) {
  80. focus(c);
  81. restack();
  82. }
  83. }
  84. Client *
  85. getclient(Window w) {
  86. Client *c;
  87. for(c = clients; c; c = c->next)
  88. if(c->win == w)
  89. return c;
  90. return NULL;
  91. }
  92. Bool
  93. isvisible(Client *c) {
  94. unsigned int i;
  95. for(i = 0; i < ntags; i++)
  96. if(c->tags[i] && seltag[i])
  97. return True;
  98. return False;
  99. }
  100. Client *
  101. nextmanaged(Client *c) {
  102. for(; c && (c->isfloat || !isvisible(c)); c = c->next);
  103. return c;
  104. }
  105. void
  106. restack(void) {
  107. Client *c;
  108. XEvent ev;
  109. drawstatus();
  110. if(!sel)
  111. return;
  112. if(sel->isfloat || arrange == dofloat)
  113. XRaiseWindow(dpy, sel->win);
  114. if(arrange != dofloat) {
  115. if(!sel->isfloat)
  116. XLowerWindow(dpy, sel->win);
  117. for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
  118. if(c == sel)
  119. continue;
  120. XLowerWindow(dpy, c->win);
  121. }
  122. }
  123. XSync(dpy, False);
  124. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  125. }
  126. void
  127. togglefloat(Arg *arg) {
  128. if(!sel || arrange == dofloat)
  129. return;
  130. sel->isfloat = !sel->isfloat;
  131. arrange();
  132. }
  133. void
  134. togglemode(Arg *arg) {
  135. arrange = (arrange == dofloat) ? dotile : dofloat;
  136. if(sel)
  137. arrange();
  138. else
  139. drawstatus();
  140. }
  141. void
  142. toggleview(Arg *arg) {
  143. unsigned int i;
  144. seltag[arg->i] = !seltag[arg->i];
  145. for(i = 0; i < ntags && !seltag[i]; i++);
  146. if(i == ntags)
  147. seltag[arg->i] = True; /* cannot toggle last view */
  148. arrange();
  149. }
  150. void
  151. view(Arg *arg) {
  152. unsigned int i;
  153. for(i = 0; i < ntags; i++)
  154. seltag[i] = (arg->i == -1) ? True : False;
  155. if(arg->i >= 0 && arg->i < ntags)
  156. seltag[arg->i] = True;
  157. arrange();
  158. }