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.

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