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.

188 lines
3.1 KiB

17 years ago
17 years ago
17 years ago
17 years ago
  1. /* See LICENSE file for copyright and license details. */
  2. #include "dwm.h"
  3. #include <stdlib.h>
  4. /* static */
  5. typedef struct {
  6. const char *symbol;
  7. void (*arrange)(void);
  8. } Layout;
  9. unsigned int blw = 0;
  10. static unsigned int ltidx = 0; /* default */
  11. static void
  12. floating(void) { /* default floating layout */
  13. Client *c;
  14. for(c = clients; c; c = c->next)
  15. if(isvisible(c))
  16. resize(c, c->x, c->y, c->w, c->h, True);
  17. }
  18. static unsigned int nlayouts = 0;
  19. LAYOUTS
  20. /* extern */
  21. void
  22. arrange(void) {
  23. Client *c;
  24. for(c = clients; c; c = c->next)
  25. if(isvisible(c))
  26. unban(c);
  27. else
  28. ban(c);
  29. layouts[ltidx].arrange();
  30. focus(NULL);
  31. restack();
  32. }
  33. void
  34. focusnext(const char *arg) {
  35. Client *c;
  36. if(!sel)
  37. return;
  38. for(c = sel->next; c && !isvisible(c); c = c->next);
  39. if(!c)
  40. for(c = clients; c && !isvisible(c); c = c->next);
  41. if(c) {
  42. focus(c);
  43. restack();
  44. }
  45. }
  46. void
  47. focusprev(const char *arg) {
  48. Client *c;
  49. if(!sel)
  50. return;
  51. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  52. if(!c) {
  53. for(c = clients; c && c->next; c = c->next);
  54. for(; c && !isvisible(c); c = c->prev);
  55. }
  56. if(c) {
  57. focus(c);
  58. restack();
  59. }
  60. }
  61. const char *
  62. getsymbol(void)
  63. {
  64. return layouts[ltidx].symbol;
  65. }
  66. Bool
  67. isfloating(void) {
  68. return layouts[ltidx].arrange == floating;
  69. }
  70. Bool
  71. isarrange(void (*func)())
  72. {
  73. return func == layouts[ltidx].arrange;
  74. }
  75. void
  76. initlayouts(void) {
  77. unsigned int i, w;
  78. /* TODO deserialize ltidx if present */
  79. nlayouts = sizeof layouts / sizeof layouts[0];
  80. for(blw = i = 0; i < nlayouts; i++) {
  81. w = textw(layouts[i].symbol);
  82. if(w > blw)
  83. blw = w;
  84. }
  85. }
  86. Client *
  87. nexttiled(Client *c) {
  88. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  89. return c;
  90. }
  91. void
  92. restack(void) {
  93. Client *c;
  94. XEvent ev;
  95. XWindowChanges wc;
  96. drawstatus();
  97. if(!sel)
  98. return;
  99. if(sel->isfloating || isfloating())
  100. XRaiseWindow(dpy, sel->win);
  101. if(!isfloating()) {
  102. wc.stack_mode = Below;
  103. wc.sibling = barwin;
  104. if(!sel->isfloating) {
  105. XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
  106. wc.sibling = sel->win;
  107. }
  108. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  109. if(c == sel)
  110. continue;
  111. XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
  112. wc.sibling = c->win;
  113. }
  114. }
  115. XSync(dpy, False);
  116. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  117. }
  118. void
  119. setlayout(const char *arg) {
  120. int i;
  121. if(!arg) {
  122. if(++ltidx == nlayouts)
  123. ltidx = 0;;
  124. }
  125. else {
  126. i = atoi(arg);
  127. if(i < 0 || i >= nlayouts)
  128. return;
  129. ltidx = i;
  130. }
  131. if(sel)
  132. arrange();
  133. else
  134. drawstatus();
  135. }
  136. void
  137. togglebar(const char *arg) {
  138. if(bpos == BarOff)
  139. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  140. else
  141. bpos = BarOff;
  142. updatebarpos();
  143. arrange();
  144. }
  145. void
  146. togglemax(const char *arg) {
  147. XEvent ev;
  148. if(!sel || (!isfloating() && !sel->isfloating) || sel->isfixed)
  149. return;
  150. if((sel->ismax = !sel->ismax)) {
  151. sel->rx = sel->x;
  152. sel->ry = sel->y;
  153. sel->rw = sel->w;
  154. sel->rh = sel->h;
  155. resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
  156. }
  157. else
  158. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  159. drawstatus();
  160. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  161. }