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.

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