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.

229 lines
4.1 KiB

18 years ago
17 years ago
  1. /* See LICENSE file for copyright and license details. */
  2. #include "dwm.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. unsigned int blw = 0;
  6. Layout *lt = NULL;
  7. /* static */
  8. static unsigned int nlayouts = 0;
  9. LAYOUTS
  10. /* extern */
  11. void
  12. floating(const char *arg) {
  13. Client *c;
  14. if(lt->arrange != floating)
  15. return;
  16. for(c = clients; c; c = c->next)
  17. if(isvisible(c)) {
  18. unban(c);
  19. resize(c, c->x, c->y, c->w, c->h, True);
  20. }
  21. else
  22. ban(c);
  23. focus(NULL);
  24. restack();
  25. }
  26. void
  27. focusclient(const char *arg) {
  28. Client *c;
  29. if(!sel || !arg)
  30. return;
  31. if(atoi(arg) < 0) {
  32. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  33. if(!c) {
  34. for(c = clients; c && c->next; c = c->next);
  35. for(; c && !isvisible(c); c = c->prev);
  36. }
  37. }
  38. else {
  39. for(c = sel->next; c && !isvisible(c); c = c->next);
  40. if(!c)
  41. for(c = clients; c && !isvisible(c); c = c->next);
  42. }
  43. if(c) {
  44. focus(c);
  45. restack();
  46. }
  47. }
  48. void
  49. initlayouts(void) {
  50. unsigned int i, w;
  51. lt = &layout[0];
  52. nlayouts = sizeof layout / sizeof layout[0];
  53. for(blw = i = 0; i < nlayouts; i++) {
  54. w = textw(layout[i].symbol);
  55. if(w > blw)
  56. blw = w;
  57. }
  58. }
  59. Client *
  60. nexttiled(Client *c) {
  61. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  62. return c;
  63. }
  64. void
  65. restack(void) {
  66. Client *c;
  67. XEvent ev;
  68. XWindowChanges wc;
  69. drawstatus();
  70. if(!sel)
  71. return;
  72. if(sel->isfloating || lt->arrange == floating)
  73. XRaiseWindow(dpy, sel->win);
  74. if(lt->arrange != floating) {
  75. wc.stack_mode = Below;
  76. wc.sibling = barwin;
  77. if(!sel->isfloating) {
  78. XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
  79. wc.sibling = sel->win;
  80. }
  81. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  82. if(c == sel)
  83. continue;
  84. XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
  85. wc.sibling = c->win;
  86. }
  87. }
  88. XSync(dpy, False);
  89. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  90. }
  91. void
  92. setlayout(const char *arg) {
  93. int i;
  94. if(!arg) {
  95. lt++;
  96. if(lt == layout + nlayouts)
  97. lt = layout;
  98. }
  99. else {
  100. i = atoi(arg);
  101. if(i < 0 || i >= nlayouts)
  102. return;
  103. lt = &layout[i];
  104. }
  105. if(sel)
  106. lt->arrange(NULL);
  107. else
  108. drawstatus();
  109. }
  110. void
  111. tile(const char *arg) {
  112. static double master = MASTER;
  113. double delta;
  114. unsigned int i, n, nx, ny, nw, nh, mw, th;
  115. Client *c;
  116. if(lt->arrange != tile)
  117. return;
  118. /* arg handling, manipulate master */
  119. if(arg && (1 == sscanf(arg, "%lf", &delta))) {
  120. if(delta + master > 0.1 && delta + master < 0.9)
  121. master += delta;
  122. }
  123. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  124. n++;
  125. /* window geoms */
  126. mw = (n == 1) ? waw : master * waw;
  127. th = (n > 1) ? wah / (n - 1) : 0;
  128. if(n > 1 && th < bh)
  129. th = wah;
  130. nx = wax;
  131. ny = way;
  132. for(i = 0, c = clients; c; c = c->next)
  133. if(isvisible(c)) {
  134. unban(c);
  135. if(c->isfloating)
  136. continue;
  137. c->ismax = False;
  138. if(i == 0) { /* master */
  139. nw = mw - 2 * c->border;
  140. nh = wah - 2 * c->border;
  141. }
  142. else { /* tile window */
  143. if(i == 1) {
  144. ny = way;
  145. nx += mw;
  146. }
  147. nw = waw - mw - 2 * c->border;
  148. if(i + 1 == n) /* remainder */
  149. nh = (way + wah) - ny - 2 * c->border;
  150. else
  151. nh = th - 2 * c->border;
  152. }
  153. resize(c, nx, ny, nw, nh, False);
  154. if(n > 1 && th != wah)
  155. ny += nh + 2 * c->border;
  156. i++;
  157. }
  158. else
  159. ban(c);
  160. focus(NULL);
  161. restack();
  162. }
  163. void
  164. togglebar(const char *arg) {
  165. if(bpos == BarOff)
  166. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  167. else
  168. bpos = BarOff;
  169. updatebarpos();
  170. lt->arrange(NULL);
  171. }
  172. void
  173. togglemax(const char *arg) {
  174. XEvent ev;
  175. if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
  176. return;
  177. if((sel->ismax = !sel->ismax)) {
  178. sel->rx = sel->x;
  179. sel->ry = sel->y;
  180. sel->rw = sel->w;
  181. sel->rh = sel->h;
  182. resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
  183. }
  184. else
  185. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  186. drawstatus();
  187. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  188. }
  189. void
  190. zoom(const char *arg) {
  191. Client *c;
  192. if(!sel || lt->arrange == floating || sel->isfloating)
  193. return;
  194. if((c = sel) == nexttiled(clients))
  195. if(!(c = nexttiled(c->next)))
  196. return;
  197. detach(c);
  198. attach(c);
  199. focus(c);
  200. lt->arrange(NULL);
  201. }