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.

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