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.

228 lines
4.0 KiB

17 years ago
17 years ago
17 years ago
18 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. /* TODO deserialize ltidx if present */
  83. nlayouts = sizeof layouts / sizeof layouts[0];
  84. for(blw = i = 0; i < nlayouts; i++) {
  85. w = textw(layouts[i].symbol);
  86. if(w > blw)
  87. blw = w;
  88. }
  89. }
  90. void
  91. loaddwmprops(void) {
  92. unsigned int i;
  93. XTextProperty name;
  94. /* check if window has set a property */
  95. name.nitems = 0;
  96. XGetTextProperty(dpy, root, &name, dwmprops);
  97. if(name.nitems && name.encoding == XA_STRING) {
  98. strncpy(prop, (char *)name.value, sizeof prop - 1);
  99. prop[sizeof prop - 1] = '\0';
  100. XFree(name.value);
  101. for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
  102. seltags[i] = prop[i] == '1';
  103. if(i < sizeof prop - 1 && prop[i] != '\0') {
  104. i = prop[i];
  105. if(i < nlayouts)
  106. ltidx = i;
  107. }
  108. }
  109. }
  110. Client *
  111. nexttiled(Client *c) {
  112. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  113. return c;
  114. }
  115. void
  116. restack(void) {
  117. Client *c;
  118. XEvent ev;
  119. XWindowChanges wc;
  120. drawstatus();
  121. if(!sel)
  122. return;
  123. if(sel->isfloating || isfloating())
  124. XRaiseWindow(dpy, sel->win);
  125. if(!isfloating()) {
  126. wc.stack_mode = Below;
  127. wc.sibling = barwin;
  128. if(!sel->isfloating) {
  129. XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
  130. wc.sibling = sel->win;
  131. }
  132. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  133. if(c == sel)
  134. continue;
  135. XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
  136. wc.sibling = c->win;
  137. }
  138. }
  139. XSync(dpy, False);
  140. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  141. }
  142. void
  143. savedwmprops(void) {
  144. unsigned int i;
  145. for(i = 0; i < ntags && i < sizeof prop - 1; i++)
  146. prop[i] = seltags[i] ? '1' : '0';
  147. if(i < sizeof prop - 1)
  148. prop[i++] = (char)ltidx;
  149. prop[i] = '\0';
  150. XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
  151. PropModeReplace, (unsigned char *)prop, i);
  152. }
  153. void
  154. setlayout(const char *arg) {
  155. int i;
  156. if(!arg) {
  157. if(++ltidx == nlayouts)
  158. ltidx = 0;;
  159. }
  160. else {
  161. i = atoi(arg);
  162. if(i < 0 || i >= nlayouts)
  163. return;
  164. ltidx = i;
  165. }
  166. if(sel)
  167. arrange();
  168. else
  169. drawstatus();
  170. savedwmprops();
  171. }
  172. void
  173. togglebar(const char *arg) {
  174. if(bpos == BarOff)
  175. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  176. else
  177. bpos = BarOff;
  178. updatebarpos();
  179. arrange();
  180. }
  181. void
  182. togglemax(const char *arg) {
  183. XEvent ev;
  184. if(!sel || (!isfloating() && !sel->isfloating) || sel->isfixed)
  185. return;
  186. if((sel->ismax = !sel->ismax)) {
  187. sel->rx = sel->x;
  188. sel->ry = sel->y;
  189. sel->rw = sel->w;
  190. sel->rh = sel->h;
  191. resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
  192. }
  193. else
  194. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  195. drawstatus();
  196. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  197. }