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.

299 lines
7.0 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <X11/Xatom.h>
  8. #include <X11/Xutil.h>
  9. /* static functions */
  10. static void
  11. detachstack(Client *c) {
  12. Client **tc;
  13. for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
  14. *tc = c->snext;
  15. }
  16. static void
  17. grabbuttons(Client *c, Bool focused) {
  18. XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  19. if(focused) {
  20. XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
  21. GrabModeAsync, GrabModeSync, None, None);
  22. XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
  23. GrabModeAsync, GrabModeSync, None, None);
  24. XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
  25. GrabModeAsync, GrabModeSync, None, None);
  26. XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
  27. GrabModeAsync, GrabModeSync, None, None);
  28. XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
  29. GrabModeAsync, GrabModeSync, None, None);
  30. XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
  31. GrabModeAsync, GrabModeSync, None, None);
  32. XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
  33. GrabModeAsync, GrabModeSync, None, None);
  34. XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
  35. GrabModeAsync, GrabModeSync, None, None);
  36. XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
  37. GrabModeAsync, GrabModeSync, None, None);
  38. XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
  39. GrabModeAsync, GrabModeSync, None, None);
  40. XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
  41. GrabModeAsync, GrabModeSync, None, None);
  42. XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
  43. GrabModeAsync, GrabModeSync, None, None);
  44. }
  45. else
  46. XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
  47. GrabModeAsync, GrabModeSync, None, None);
  48. }
  49. static int
  50. xerrordummy(Display *dsply, XErrorEvent *ee) {
  51. return 0;
  52. }
  53. /* extern functions */
  54. void
  55. configure(Client *c) {
  56. XEvent synev;
  57. synev.type = ConfigureNotify;
  58. synev.xconfigure.display = dpy;
  59. synev.xconfigure.event = c->win;
  60. synev.xconfigure.window = c->win;
  61. synev.xconfigure.x = c->x;
  62. synev.xconfigure.y = c->y;
  63. synev.xconfigure.width = c->w;
  64. synev.xconfigure.height = c->h;
  65. synev.xconfigure.border_width = c->border;
  66. synev.xconfigure.above = None;
  67. XSendEvent(dpy, c->win, True, NoEventMask, &synev);
  68. }
  69. void
  70. focus(Client *c) {
  71. if(c && !isvisible(c))
  72. return;
  73. if(sel && sel != c) {
  74. grabbuttons(sel, False);
  75. XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
  76. }
  77. if(c) {
  78. detachstack(c);
  79. c->snext = stack;
  80. stack = c;
  81. grabbuttons(c, True);
  82. }
  83. sel = c;
  84. drawstatus();
  85. if(!activescreen)
  86. return;
  87. if(sel) {
  88. XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
  89. XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
  90. }
  91. else
  92. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  93. }
  94. Client *
  95. getclient(Window w) {
  96. Client *c;
  97. for(c = clients; c; c = c->next)
  98. if(c->win == w)
  99. return c;
  100. return NULL;
  101. }
  102. void
  103. killclient(Arg *arg) {
  104. if(!sel)
  105. return;
  106. if(sel->proto & PROTODELWIN)
  107. sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
  108. else
  109. XKillClient(dpy, sel->win);
  110. }
  111. void
  112. manage(Window w, XWindowAttributes *wa) {
  113. Client *c;
  114. Window trans;
  115. c = emallocz(sizeof(Client));
  116. c->tags = emallocz(ntags * sizeof(Bool));
  117. c->win = w;
  118. c->x = wa->x;
  119. c->y = wa->y;
  120. c->w = wa->width;
  121. c->h = wa->height;
  122. if(c->w == sw && c->h == sh) {
  123. c->border = 0;
  124. c->x = sx;
  125. c->y = sy;
  126. }
  127. else {
  128. c->border = BORDERPX;
  129. if(c->x < wax)
  130. c->x = wax;
  131. if(c->y < way)
  132. c->y = way;
  133. if(c->x + c->w + 2 * c->border > wax + waw)
  134. c->x = wax + waw - c->w - 2 * c->border;
  135. if(c->y + c->h + 2 * c->border > way + wah)
  136. c->y = way + wah - c->h - 2 * c->border;
  137. }
  138. updatesizehints(c);
  139. c->proto = getproto(c->win);
  140. XSelectInput(dpy, c->win,
  141. StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
  142. XGetTransientForHint(dpy, c->win, &trans);
  143. grabbuttons(c, False);
  144. updatetitle(c);
  145. settags(c, getclient(trans));
  146. if(!c->isfloat)
  147. c->isfloat = trans || c->isfixed;
  148. if(clients)
  149. clients->prev = c;
  150. c->next = clients;
  151. c->snext = stack;
  152. stack = clients = c;
  153. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  154. XMapWindow(dpy, c->win);
  155. if(isvisible(c))
  156. focus(c);
  157. arrange();
  158. }
  159. void
  160. resize(Client *c, Bool sizehints) {
  161. XWindowChanges wc;
  162. if(sizehints) {
  163. if(c->incw)
  164. c->w -= (c->w - c->basew) % c->incw;
  165. if(c->inch)
  166. c->h -= (c->h - c->baseh) % c->inch;
  167. if(c->minw && c->w < c->minw)
  168. c->w = c->minw;
  169. if(c->minh && c->h < c->minh)
  170. c->h = c->minh;
  171. if(c->maxw && c->w > c->maxw)
  172. c->w = c->maxw;
  173. if(c->maxh && c->h > c->maxh)
  174. c->h = c->maxh;
  175. }
  176. if(c->w == sw && c->h == sh)
  177. c->border = 0;
  178. else
  179. c->border = BORDERPX;
  180. /* offscreen appearance fixes */
  181. if(c->x + c->w + 2 * c->border < sx)
  182. c->x = sx;
  183. if(c->y + c->h + 2 * c->border < sy)
  184. c->y = sy;
  185. if(c->x > sw)
  186. c->x = sw - c->w - 2 * c->border;
  187. if(c->y > sh)
  188. c->y = sh - c->h - 2 * c->border;
  189. wc.x = c->x;
  190. wc.y = c->y;
  191. wc.width = c->w;
  192. wc.height = c->h;
  193. wc.border_width = c->border;
  194. XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
  195. configure(c);
  196. XSync(dpy, False);
  197. }
  198. void
  199. updatesizehints(Client *c) {
  200. long msize;
  201. XSizeHints size;
  202. if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
  203. size.flags = PSize;
  204. c->flags = size.flags;
  205. if(c->flags & PBaseSize) {
  206. c->basew = size.base_width;
  207. c->baseh = size.base_height;
  208. }
  209. else
  210. c->basew = c->baseh = 0;
  211. if(c->flags & PResizeInc) {
  212. c->incw = size.width_inc;
  213. c->inch = size.height_inc;
  214. }
  215. else
  216. c->incw = c->inch = 0;
  217. if(c->flags & PMaxSize) {
  218. c->maxw = size.max_width;
  219. c->maxh = size.max_height;
  220. }
  221. else
  222. c->maxw = c->maxh = 0;
  223. if(c->flags & PMinSize) {
  224. c->minw = size.min_width;
  225. c->minh = size.min_height;
  226. }
  227. else
  228. c->minw = c->minh = 0;
  229. c->isfixed = (c->maxw && c->minw && c->maxh && c->minh &&
  230. c->maxw == c->minw && c->maxh == c->minh);
  231. }
  232. void
  233. updatetitle(Client *c) {
  234. char **list = NULL;
  235. int n;
  236. XTextProperty name;
  237. name.nitems = 0;
  238. c->name[0] = 0;
  239. XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
  240. if(!name.nitems)
  241. XGetWMName(dpy, c->win, &name);
  242. if(!name.nitems)
  243. return;
  244. if(name.encoding == XA_STRING)
  245. strncpy(c->name, (char *)name.value, sizeof c->name);
  246. else {
  247. if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
  248. && n > 0 && *list)
  249. {
  250. strncpy(c->name, *list, sizeof c->name);
  251. XFreeStringList(list);
  252. }
  253. }
  254. XFree(name.value);
  255. }
  256. void
  257. unmanage(Client *c) {
  258. Client *nc;
  259. /* The server grab construct avoids race conditions. */
  260. XGrabServer(dpy);
  261. XSetErrorHandler(xerrordummy);
  262. detach(c);
  263. detachstack(c);
  264. if(sel == c) {
  265. for(nc = stack; nc && !isvisible(nc); nc = nc->snext);
  266. focus(nc);
  267. }
  268. XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  269. free(c->tags);
  270. free(c);
  271. XSync(dpy, False);
  272. XSetErrorHandler(xerror);
  273. XUngrabServer(dpy);
  274. arrange();
  275. }