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.

153 lines
2.5 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. detach(Client *c) {
  9. if(c->prev)
  10. c->prev->next = c->next;
  11. if(c->next)
  12. c->next->prev = c->prev;
  13. if(c == clients)
  14. clients = c->next;
  15. c->next = c->prev = NULL;
  16. }
  17. void
  18. dofloat(void) {
  19. Client *c;
  20. for(c = clients; c; c = c->next) {
  21. if(isvisible(c)) {
  22. if(c->isbanned)
  23. XMoveWindow(dpy, c->win, c->x, c->y);
  24. c->isbanned = False;
  25. resize(c, c->x, c->y, c->w, c->h, True);
  26. }
  27. else {
  28. c->isbanned = True;
  29. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  30. }
  31. }
  32. if(!sel || !isvisible(sel)) {
  33. for(c = stack; c && !isvisible(c); c = c->snext);
  34. focus(c);
  35. }
  36. restack();
  37. }
  38. void
  39. focusnext(Arg *arg) {
  40. Client *c;
  41. if(!sel)
  42. return;
  43. for(c = sel->next; c && !isvisible(c); c = c->next);
  44. if(!c)
  45. for(c = clients; c && !isvisible(c); c = c->next);
  46. if(c) {
  47. focus(c);
  48. restack();
  49. }
  50. }
  51. void
  52. focusprev(Arg *arg) {
  53. Client *c;
  54. if(!sel)
  55. return;
  56. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  57. if(!c) {
  58. for(c = clients; c && c->next; c = c->next);
  59. for(; c && !isvisible(c); c = c->prev);
  60. }
  61. if(c) {
  62. focus(c);
  63. restack();
  64. }
  65. }
  66. Bool
  67. isvisible(Client *c) {
  68. unsigned int i;
  69. for(i = 0; i < ntags; i++)
  70. if(c->tags[i] && seltag[i])
  71. return True;
  72. return False;
  73. }
  74. Client *
  75. nextmanaged(Client *c) {
  76. for(; c && (c->isfloat || !isvisible(c)); c = c->next);
  77. return c;
  78. }
  79. void
  80. restack(void) {
  81. Client *c;
  82. XEvent ev;
  83. drawstatus();
  84. if(!sel)
  85. return;
  86. if(sel->isfloat || arrange == dofloat)
  87. XRaiseWindow(dpy, sel->win);
  88. if(arrange != dofloat) {
  89. if(!sel->isfloat)
  90. XLowerWindow(dpy, sel->win);
  91. for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
  92. if(c == sel)
  93. continue;
  94. XLowerWindow(dpy, c->win);
  95. }
  96. }
  97. XSync(dpy, False);
  98. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  99. }
  100. void
  101. togglefloat(Arg *arg) {
  102. if(!sel || arrange == dofloat)
  103. return;
  104. sel->isfloat = !sel->isfloat;
  105. arrange();
  106. }
  107. void
  108. togglemode(Arg *arg) {
  109. arrange = (arrange == dofloat) ? dotile : dofloat;
  110. if(sel)
  111. arrange();
  112. else
  113. drawstatus();
  114. }
  115. void
  116. toggleview(Arg *arg) {
  117. unsigned int i;
  118. seltag[arg->i] = !seltag[arg->i];
  119. for(i = 0; i < ntags && !seltag[i]; i++);
  120. if(i == ntags)
  121. seltag[arg->i] = True; /* cannot toggle last view */
  122. arrange();
  123. }
  124. void
  125. view(Arg *arg) {
  126. unsigned int i;
  127. for(i = 0; i < ntags; i++)
  128. seltag[i] = (arg->i == -1) ? True : False;
  129. if(arg->i >= 0 && arg->i < ntags)
  130. seltag[arg->i] = True;
  131. arrange();
  132. }