Configuration of dwm for Mac Computers
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.

189 lines
3.0 KiB

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 Layout *lt = NULL;
  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. lt->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 lt->symbol;
  65. }
  66. Bool
  67. isfloating(void) {
  68. return lt->arrange == floating;
  69. }
  70. Bool
  71. isarrange(void (*func)())
  72. {
  73. return func == lt->arrange;
  74. }
  75. void
  76. initlayouts(void) {
  77. unsigned int i, w;
  78. lt = &layout[0];
  79. nlayouts = sizeof layout / sizeof layout[0];
  80. for(blw = i = 0; i < nlayouts; i++) {
  81. w = textw(layout[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 || lt->arrange == floating)
  100. XRaiseWindow(dpy, sel->win);
  101. if(lt->arrange != floating) {
  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. lt++;
  123. if(lt == layout + nlayouts)
  124. lt = layout;
  125. }
  126. else {
  127. i = atoi(arg);
  128. if(i < 0 || i >= nlayouts)
  129. return;
  130. lt = &layout[i];
  131. }
  132. if(sel)
  133. arrange();
  134. else
  135. drawstatus();
  136. }
  137. void
  138. togglebar(const char *arg) {
  139. if(bpos == BarOff)
  140. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  141. else
  142. bpos = BarOff;
  143. updatebarpos();
  144. arrange();
  145. }
  146. void
  147. togglemax(const char *arg) {
  148. XEvent ev;
  149. if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
  150. return;
  151. if((sel->ismax = !sel->ismax)) {
  152. sel->rx = sel->x;
  153. sel->ry = sel->y;
  154. sel->rw = sel->w;
  155. sel->rh = sel->h;
  156. resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
  157. }
  158. else
  159. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  160. drawstatus();
  161. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  162. }