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.

181 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. typedef struct {
  5. const char *symbol;
  6. void (*arrange)(void);
  7. } Layout;
  8. unsigned int blw = 0;
  9. static Layout *lt = NULL;
  10. /* static */
  11. static void
  12. floating(void) {
  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. focusclient(const char *arg) {
  35. Client *c;
  36. if(!sel || !arg)
  37. return;
  38. if(atoi(arg) < 0) {
  39. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  40. if(!c) {
  41. for(c = clients; c && c->next; c = c->next);
  42. for(; c && !isvisible(c); c = c->prev);
  43. }
  44. }
  45. else {
  46. for(c = sel->next; c && !isvisible(c); c = c->next);
  47. if(!c)
  48. for(c = clients; c && !isvisible(c); c = c->next);
  49. }
  50. if(c) {
  51. focus(c);
  52. restack();
  53. }
  54. }
  55. const char *
  56. getsymbol(void)
  57. {
  58. return lt->symbol;
  59. }
  60. Bool
  61. isfloating(void) {
  62. return lt->arrange == floating;
  63. }
  64. Bool
  65. isarrange(void (*func)())
  66. {
  67. return func == lt->arrange;
  68. }
  69. void
  70. initlayouts(void) {
  71. unsigned int i, w;
  72. lt = &layout[0];
  73. nlayouts = sizeof layout / sizeof layout[0];
  74. for(blw = i = 0; i < nlayouts; i++) {
  75. w = textw(layout[i].symbol);
  76. if(w > blw)
  77. blw = w;
  78. }
  79. }
  80. Client *
  81. nexttiled(Client *c) {
  82. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  83. return c;
  84. }
  85. void
  86. restack(void) {
  87. Client *c;
  88. XEvent ev;
  89. XWindowChanges wc;
  90. drawstatus();
  91. if(!sel)
  92. return;
  93. if(sel->isfloating || lt->arrange == floating)
  94. XRaiseWindow(dpy, sel->win);
  95. if(lt->arrange != floating) {
  96. wc.stack_mode = Below;
  97. wc.sibling = barwin;
  98. if(!sel->isfloating) {
  99. XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
  100. wc.sibling = sel->win;
  101. }
  102. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  103. if(c == sel)
  104. continue;
  105. XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
  106. wc.sibling = c->win;
  107. }
  108. }
  109. XSync(dpy, False);
  110. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  111. }
  112. void
  113. setlayout(const char *arg) {
  114. int i;
  115. if(!arg) {
  116. lt++;
  117. if(lt == layout + nlayouts)
  118. lt = layout;
  119. }
  120. else {
  121. i = atoi(arg);
  122. if(i < 0 || i >= nlayouts)
  123. return;
  124. lt = &layout[i];
  125. }
  126. if(sel)
  127. arrange();
  128. else
  129. drawstatus();
  130. }
  131. void
  132. togglebar(const char *arg) {
  133. if(bpos == BarOff)
  134. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  135. else
  136. bpos = BarOff;
  137. updatebarpos();
  138. arrange();
  139. }
  140. void
  141. togglemax(const char *arg) {
  142. XEvent ev;
  143. if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
  144. return;
  145. if((sel->ismax = !sel->ismax)) {
  146. sel->rx = sel->x;
  147. sel->ry = sel->y;
  148. sel->rw = sel->w;
  149. sel->rh = sel->h;
  150. resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
  151. }
  152. else
  153. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  154. drawstatus();
  155. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  156. }