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.

365 lines
7.7 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
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 <X11/keysym.h>
  7. #include <X11/Xatom.h>
  8. /* static */
  9. typedef struct {
  10. unsigned long mod;
  11. KeySym keysym;
  12. void (*func)(Arg *arg);
  13. Arg arg;
  14. } Key;
  15. KEYS
  16. #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
  17. #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
  18. static void
  19. movemouse(Client *c) {
  20. int x1, y1, ocx, ocy, di;
  21. unsigned int dui;
  22. Window dummy;
  23. XEvent ev;
  24. ocx = c->x;
  25. ocy = c->y;
  26. if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  27. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  28. return;
  29. c->ismax = False;
  30. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  31. for(;;) {
  32. XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
  33. switch (ev.type) {
  34. case ButtonRelease:
  35. resize(c, True);
  36. XUngrabPointer(dpy, CurrentTime);
  37. return;
  38. case ConfigureRequest:
  39. case Expose:
  40. case MapRequest:
  41. handler[ev.type](&ev);
  42. break;
  43. case MotionNotify:
  44. XSync(dpy, False);
  45. c->x = ocx + (ev.xmotion.x - x1);
  46. c->y = ocy + (ev.xmotion.y - y1);
  47. if(abs(wax + c->x) < SNAP)
  48. c->x = wax;
  49. else if(abs((wax + waw) - (c->x + c->w + 2 * c->border)) < SNAP)
  50. c->x = wax + waw - c->w - 2 * c->border;
  51. if(abs(way - c->y) < SNAP)
  52. c->y = way;
  53. else if(abs((way + wah) - (c->y + c->h + 2 * c->border)) < SNAP)
  54. c->y = way + wah - c->h - 2 * c->border;
  55. resize(c, False);
  56. break;
  57. }
  58. }
  59. }
  60. static void
  61. resizemouse(Client *c) {
  62. int ocx, ocy;
  63. int nw, nh;
  64. XEvent ev;
  65. ocx = c->x;
  66. ocy = c->y;
  67. if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  68. None, cursor[CurResize], CurrentTime) != GrabSuccess)
  69. return;
  70. c->ismax = False;
  71. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
  72. for(;;) {
  73. XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask , &ev);
  74. switch(ev.type) {
  75. case ButtonRelease:
  76. resize(c, True);
  77. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
  78. c->w + c->border - 1, c->h + c->border - 1);
  79. XUngrabPointer(dpy, CurrentTime);
  80. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  81. return;
  82. case ConfigureRequest:
  83. case Expose:
  84. case MapRequest:
  85. handler[ev.type](&ev);
  86. break;
  87. case MotionNotify:
  88. XSync(dpy, False);
  89. nw = ev.xmotion.x - ocx - 2 * c->border + 1;
  90. c->w = nw > 0 ? nw : 1;
  91. nh = ev.xmotion.y - ocy - 2 * c->border + 1;
  92. c->h = nh > 0 ? nh : 1;
  93. resize(c, True);
  94. break;
  95. }
  96. }
  97. }
  98. static void
  99. buttonpress(XEvent *e) {
  100. int x;
  101. Arg a;
  102. Client *c;
  103. XButtonPressedEvent *ev = &e->xbutton;
  104. if(barwin == ev->window) {
  105. x = 0;
  106. for(a.i = 0; a.i < ntags; a.i++) {
  107. x += textw(tags[a.i]);
  108. if(ev->x < x) {
  109. if(ev->button == Button1) {
  110. if(ev->state & MODKEY)
  111. tag(&a);
  112. else
  113. view(&a);
  114. }
  115. else if(ev->button == Button3) {
  116. if(ev->state & MODKEY)
  117. toggletag(&a);
  118. else
  119. toggleview(&a);
  120. }
  121. return;
  122. }
  123. }
  124. if(ev->x < x + bmw)
  125. switch(ev->button) {
  126. case Button1:
  127. togglemode(NULL);
  128. break;
  129. case Button4:
  130. a.i = 1;
  131. incnmaster(&a);
  132. break;
  133. case Button5:
  134. a.i = -1;
  135. incnmaster(&a);
  136. break;
  137. }
  138. }
  139. else if((c = getclient(ev->window))) {
  140. focus(c);
  141. if(CLEANMASK(ev->state) != MODKEY)
  142. return;
  143. if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) {
  144. restack();
  145. movemouse(c);
  146. }
  147. else if(ev->button == Button2)
  148. zoom(NULL);
  149. else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) &&
  150. !c->isfixed) {
  151. restack();
  152. resizemouse(c);
  153. }
  154. }
  155. }
  156. static void
  157. configurerequest(XEvent *e) {
  158. Client *c;
  159. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  160. XWindowChanges wc;
  161. wc.x = ev->x;
  162. wc.y = ev->y;
  163. wc.width = ev->width;
  164. wc.height = ev->height;
  165. wc.border_width = ev->border_width;
  166. wc.sibling = ev->above;
  167. wc.stack_mode = ev->detail;
  168. if((c = getclient(ev->window))) {
  169. c->ismax = False;
  170. if(ev->value_mask & CWBorderWidth)
  171. c->border = ev->border_width;
  172. if((!c->isfloat && (arrange != dofloat))
  173. || ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))))
  174. {
  175. configure(c);
  176. XSync(dpy, False);
  177. return;
  178. }
  179. }
  180. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  181. if(c && !isvisible(c))
  182. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  183. XSync(dpy, False);
  184. }
  185. static void
  186. destroynotify(XEvent *e) {
  187. Client *c;
  188. XDestroyWindowEvent *ev = &e->xdestroywindow;
  189. if((c = getclient(ev->window)))
  190. unmanage(c);
  191. }
  192. static void
  193. enternotify(XEvent *e) {
  194. Client *c;
  195. XCrossingEvent *ev = &e->xcrossing;
  196. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  197. return;
  198. if((c = getclient(ev->window)) && isvisible(c))
  199. focus(c);
  200. else if(ev->window == root) {
  201. selscreen = True;
  202. for(c = stack; c && !isvisible(c); c = c->snext);
  203. focus(c);
  204. }
  205. }
  206. static void
  207. expose(XEvent *e) {
  208. XExposeEvent *ev = &e->xexpose;
  209. if(ev->count == 0) {
  210. if(barwin == ev->window)
  211. drawstatus();
  212. }
  213. }
  214. static void
  215. keypress(XEvent *e) {
  216. static unsigned int len = sizeof key / sizeof key[0];
  217. unsigned int i;
  218. KeySym keysym;
  219. XKeyEvent *ev = &e->xkey;
  220. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  221. for(i = 0; i < len; i++) {
  222. if(keysym == key[i].keysym
  223. && CLEANMASK(key[i].mod) == CLEANMASK(ev->state))
  224. {
  225. if(key[i].func)
  226. key[i].func(&key[i].arg);
  227. }
  228. }
  229. }
  230. static void
  231. leavenotify(XEvent *e) {
  232. XCrossingEvent *ev = &e->xcrossing;
  233. if((ev->window == root) && !ev->same_screen) {
  234. selscreen = False;
  235. focus(NULL);
  236. }
  237. }
  238. static void
  239. mappingnotify(XEvent *e) {
  240. XMappingEvent *ev = &e->xmapping;
  241. XRefreshKeyboardMapping(ev);
  242. if(ev->request == MappingKeyboard)
  243. grabkeys();
  244. }
  245. static void
  246. maprequest(XEvent *e) {
  247. static XWindowAttributes wa;
  248. XMapRequestEvent *ev = &e->xmaprequest;
  249. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  250. return;
  251. if(wa.override_redirect)
  252. return;
  253. if(!getclient(ev->window))
  254. manage(ev->window, &wa);
  255. }
  256. static void
  257. propertynotify(XEvent *e) {
  258. Client *c;
  259. Window trans;
  260. XPropertyEvent *ev = &e->xproperty;
  261. if(ev->state == PropertyDelete)
  262. return; /* ignore */
  263. if((c = getclient(ev->window))) {
  264. switch (ev->atom) {
  265. default: break;
  266. case XA_WM_TRANSIENT_FOR:
  267. XGetTransientForHint(dpy, c->win, &trans);
  268. if(!c->isfloat && (c->isfloat = (trans != 0)))
  269. arrange();
  270. break;
  271. case XA_WM_NORMAL_HINTS:
  272. updatesizehints(c);
  273. break;
  274. }
  275. if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
  276. updatetitle(c);
  277. if(c == sel)
  278. drawstatus();
  279. }
  280. }
  281. }
  282. static void
  283. unmapnotify(XEvent *e) {
  284. Client *c;
  285. XUnmapEvent *ev = &e->xunmap;
  286. if((c = getclient(ev->window)))
  287. unmanage(c);
  288. }
  289. /* extern */
  290. void (*handler[LASTEvent]) (XEvent *) = {
  291. [ButtonPress] = buttonpress,
  292. [ConfigureRequest] = configurerequest,
  293. [DestroyNotify] = destroynotify,
  294. [EnterNotify] = enternotify,
  295. [LeaveNotify] = leavenotify,
  296. [Expose] = expose,
  297. [KeyPress] = keypress,
  298. [MappingNotify] = mappingnotify,
  299. [MapRequest] = maprequest,
  300. [PropertyNotify] = propertynotify,
  301. [UnmapNotify] = unmapnotify
  302. };
  303. void
  304. grabkeys(void) {
  305. static unsigned int len = sizeof key / sizeof key[0];
  306. unsigned int i;
  307. KeyCode code;
  308. XUngrabKey(dpy, AnyKey, AnyModifier, root);
  309. for(i = 0; i < len; i++) {
  310. code = XKeysymToKeycode(dpy, key[i].keysym);
  311. XGrabKey(dpy, code, key[i].mod, root, True,
  312. GrabModeAsync, GrabModeAsync);
  313. XGrabKey(dpy, code, key[i].mod | LockMask, root, True,
  314. GrabModeAsync, GrabModeAsync);
  315. XGrabKey(dpy, code, key[i].mod | numlockmask, root, True,
  316. GrabModeAsync, GrabModeAsync);
  317. XGrabKey(dpy, code, key[i].mod | numlockmask | LockMask, root, True,
  318. GrabModeAsync, GrabModeAsync);
  319. }
  320. }
  321. void
  322. procevent(void) {
  323. XEvent ev;
  324. while(XPending(dpy)) {
  325. XNextEvent(dpy, &ev);
  326. if(handler[ev.type])
  327. (handler[ev.type])(&ev); /* call handler */
  328. }
  329. }