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.

380 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
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. if(ev->button == Button3)
  102. viewextend(&a);
  103. else
  104. view(&a);
  105. return;
  106. }
  107. }
  108. if(ev->button == Button1)
  109. viewprev(&a);
  110. else if(ev->button == Button3)
  111. viewnext(&a);
  112. break;
  113. case Button4:
  114. viewprev(&a);
  115. break;
  116. case Button5:
  117. viewnext(&a);
  118. break;
  119. }
  120. }
  121. else if((c = getclient(ev->window))) {
  122. higher(c);
  123. focus(c);
  124. switch(ev->button) {
  125. default:
  126. break;
  127. case Button1:
  128. if(!c->ismax && (arrange == dofloat || c->isfloat))
  129. movemouse(c);
  130. break;
  131. case Button2:
  132. zoom(NULL);
  133. break;
  134. case Button3:
  135. if(!c->ismax && (arrange == dofloat || c->isfloat))
  136. resizemouse(c);
  137. break;
  138. }
  139. }
  140. }
  141. static void
  142. configurerequest(XEvent *e)
  143. {
  144. Client *c;
  145. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  146. XEvent synev;
  147. XWindowChanges wc;
  148. unsigned long newmask;
  149. if((c = getclient(ev->window))) {
  150. gravitate(c, True);
  151. if(ev->value_mask & CWX)
  152. c->x = ev->x;
  153. if(ev->value_mask & CWY)
  154. c->y = ev->y;
  155. if(ev->value_mask & CWWidth)
  156. c->w = ev->width;
  157. if(ev->value_mask & CWHeight)
  158. c->h = ev->height;
  159. if(ev->value_mask & CWBorderWidth)
  160. c->border = ev->border_width;
  161. gravitate(c, False);
  162. wc.x = c->x;
  163. wc.y = c->y;
  164. wc.width = c->w;
  165. wc.height = c->h;
  166. newmask = ev->value_mask & (~(CWSibling | CWStackMode | CWBorderWidth));
  167. if(newmask)
  168. XConfigureWindow(dpy, c->win, newmask, &wc);
  169. else {
  170. synev.type = ConfigureNotify;
  171. synev.xconfigure.display = dpy;
  172. synev.xconfigure.event = c->win;
  173. synev.xconfigure.window = c->win;
  174. synev.xconfigure.x = c->x;
  175. synev.xconfigure.y = c->y;
  176. synev.xconfigure.width = c->w;
  177. synev.xconfigure.height = c->h;
  178. synev.xconfigure.border_width = c->border;
  179. synev.xconfigure.above = None;
  180. /* Send synthetic ConfigureNotify */
  181. XSendEvent(dpy, c->win, True, NoEventMask, &synev);
  182. }
  183. XSync(dpy, False);
  184. if(c->isfloat)
  185. resize(c, False, TopLeft);
  186. else
  187. arrange(NULL);
  188. }
  189. else {
  190. wc.x = ev->x;
  191. wc.y = ev->y;
  192. wc.width = ev->width;
  193. wc.height = ev->height;
  194. wc.border_width = ev->border_width;
  195. wc.sibling = ev->above;
  196. wc.stack_mode = ev->detail;
  197. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  198. XSync(dpy, False);
  199. }
  200. }
  201. static void
  202. destroynotify(XEvent *e)
  203. {
  204. Client *c;
  205. XDestroyWindowEvent *ev = &e->xdestroywindow;
  206. if((c = getclient(ev->window)))
  207. unmanage(c);
  208. }
  209. static void
  210. enternotify(XEvent *e)
  211. {
  212. Client *c;
  213. XCrossingEvent *ev = &e->xcrossing;
  214. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  215. return;
  216. if((c = getclient(ev->window)) || (c = getctitle(ev->window)))
  217. focus(c);
  218. else if(ev->window == root) {
  219. issel = True;
  220. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  221. drawall();
  222. }
  223. }
  224. static void
  225. expose(XEvent *e)
  226. {
  227. Client *c;
  228. XExposeEvent *ev = &e->xexpose;
  229. if(ev->count == 0) {
  230. if(barwin == ev->window)
  231. drawstatus();
  232. else if((c = getctitle(ev->window)))
  233. drawtitle(c);
  234. }
  235. }
  236. static void
  237. keypress(XEvent *e)
  238. {
  239. static unsigned int len = sizeof(key) / sizeof(key[0]);
  240. unsigned int i;
  241. KeySym keysym;
  242. XKeyEvent *ev = &e->xkey;
  243. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  244. for(i = 0; i < len; i++)
  245. if(keysym == key[i].keysym &&
  246. CLEANMASK(key[i].mod) == CLEANMASK(ev->state)) {
  247. if(key[i].func)
  248. key[i].func(&key[i].arg);
  249. return;
  250. }
  251. }
  252. static void
  253. leavenotify(XEvent *e)
  254. {
  255. XCrossingEvent *ev = &e->xcrossing;
  256. if((ev->window == root) && !ev->same_screen) {
  257. issel = False;
  258. drawall();
  259. }
  260. }
  261. static void
  262. maprequest(XEvent *e)
  263. {
  264. static XWindowAttributes wa;
  265. XMapRequestEvent *ev = &e->xmaprequest;
  266. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  267. return;
  268. if(wa.override_redirect) {
  269. XSelectInput(dpy, ev->window,
  270. (StructureNotifyMask | PropertyChangeMask));
  271. return;
  272. }
  273. if(!getclient(ev->window))
  274. manage(ev->window, &wa);
  275. }
  276. static void
  277. propertynotify(XEvent *e)
  278. {
  279. Client *c;
  280. Window trans;
  281. XPropertyEvent *ev = &e->xproperty;
  282. if(ev->state == PropertyDelete)
  283. return; /* ignore */
  284. if((c = getclient(ev->window))) {
  285. if(ev->atom == wmatom[WMProtocols]) {
  286. c->proto = getproto(c->win);
  287. return;
  288. }
  289. switch (ev->atom) {
  290. default: break;
  291. case XA_WM_TRANSIENT_FOR:
  292. XGetTransientForHint(dpy, c->win, &trans);
  293. if(!c->isfloat && (c->isfloat = (trans != 0)))
  294. arrange(NULL);
  295. break;
  296. case XA_WM_NORMAL_HINTS:
  297. setsize(c);
  298. break;
  299. }
  300. if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
  301. settitle(c);
  302. drawtitle(c);
  303. }
  304. }
  305. }
  306. static void
  307. unmapnotify(XEvent *e)
  308. {
  309. Client *c;
  310. XUnmapEvent *ev = &e->xunmap;
  311. if((c = getclient(ev->window)))
  312. unmanage(c);
  313. }
  314. /* extern */
  315. void (*handler[LASTEvent]) (XEvent *) = {
  316. [ButtonPress] = buttonpress,
  317. [ConfigureRequest] = configurerequest,
  318. [DestroyNotify] = destroynotify,
  319. [EnterNotify] = enternotify,
  320. [LeaveNotify] = leavenotify,
  321. [Expose] = expose,
  322. [KeyPress] = keypress,
  323. [MapRequest] = maprequest,
  324. [PropertyNotify] = propertynotify,
  325. [UnmapNotify] = unmapnotify
  326. };
  327. void
  328. grabkeys()
  329. {
  330. static unsigned int len = sizeof(key) / sizeof(key[0]);
  331. unsigned int i;
  332. KeyCode code;
  333. for(i = 0; i < len; i++) {
  334. code = XKeysymToKeycode(dpy, key[i].keysym);
  335. XGrabKey(dpy, code, key[i].mod, root, True,
  336. GrabModeAsync, GrabModeAsync);
  337. XGrabKey(dpy, code, key[i].mod | LockMask, root, True,
  338. GrabModeAsync, GrabModeAsync);
  339. XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root, True,
  340. GrabModeAsync, GrabModeAsync);
  341. XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root, True,
  342. GrabModeAsync, GrabModeAsync);
  343. }
  344. }