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.

217 lines
3.9 KiB

  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include <fcntl.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <X11/keysym.h>
  9. #include <X11/Xatom.h>
  10. #include "wm.h"
  11. /* local functions */
  12. static void buttonpress(XEvent *e);
  13. static void configurerequest(XEvent *e);
  14. static void destroynotify(XEvent *e);
  15. static void enternotify(XEvent *e);
  16. static void leavenotify(XEvent *e);
  17. static void expose(XEvent *e);
  18. static void keymapnotify(XEvent *e);
  19. static void maprequest(XEvent *e);
  20. static void propertynotify(XEvent *e);
  21. static void unmapnotify(XEvent *e);
  22. void (*handler[LASTEvent]) (XEvent *) = {
  23. [ButtonPress] = buttonpress,
  24. [ConfigureRequest] = configurerequest,
  25. [DestroyNotify] = destroynotify,
  26. [EnterNotify] = enternotify,
  27. [LeaveNotify] = leavenotify,
  28. [Expose] = expose,
  29. [KeyPress] = keypress,
  30. [KeymapNotify] = keymapnotify,
  31. [MapRequest] = maprequest,
  32. [PropertyNotify] = propertynotify,
  33. [UnmapNotify] = unmapnotify
  34. };
  35. void
  36. discard_events(long even_mask)
  37. {
  38. XEvent ev;
  39. while(XCheckMaskEvent(dpy, even_mask, &ev));
  40. }
  41. static void
  42. buttonpress(XEvent *e)
  43. {
  44. XButtonPressedEvent *ev = &e->xbutton;
  45. Client *c;
  46. if((c = getclient(ev->window))) {
  47. craise(c);
  48. switch(ev->button) {
  49. default:
  50. break;
  51. case Button1:
  52. mmove(c);
  53. break;
  54. case Button2:
  55. lower(c);
  56. break;
  57. case Button3:
  58. mresize(c);
  59. break;
  60. }
  61. }
  62. }
  63. static void
  64. configurerequest(XEvent *e)
  65. {
  66. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  67. XWindowChanges wc;
  68. Client *c;
  69. ev->value_mask &= ~CWSibling;
  70. if((c = getclient(ev->window))) {
  71. gravitate(c, True);
  72. if(ev->value_mask & CWX)
  73. c->x = ev->x;
  74. if(ev->value_mask & CWY)
  75. c->y = ev->y;
  76. if(ev->value_mask & CWWidth)
  77. c->w = ev->width;
  78. if(ev->value_mask & CWHeight)
  79. c->h = ev->height;
  80. if(ev->value_mask & CWBorderWidth)
  81. c->border = ev->border_width;
  82. gravitate(c, False);
  83. }
  84. wc.x = ev->x;
  85. wc.y = ev->y;
  86. wc.width = ev->width;
  87. wc.height = ev->height;
  88. wc.border_width = 1;
  89. wc.sibling = None;
  90. wc.stack_mode = Above;
  91. ev->value_mask &= ~CWStackMode;
  92. ev->value_mask |= CWBorderWidth;
  93. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  94. XFlush(dpy);
  95. }
  96. static void
  97. destroynotify(XEvent *e)
  98. {
  99. Client *c;
  100. XDestroyWindowEvent *ev = &e->xdestroywindow;
  101. if((c = getclient(ev->window)))
  102. unmanage(c);
  103. }
  104. static void
  105. enternotify(XEvent *e)
  106. {
  107. XCrossingEvent *ev = &e->xcrossing;
  108. Client *c;
  109. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  110. return;
  111. if((c = getclient(ev->window)))
  112. focus(c);
  113. else if(ev->window == root)
  114. issel = True;
  115. }
  116. static void
  117. leavenotify(XEvent *e)
  118. {
  119. XCrossingEvent *ev = &e->xcrossing;
  120. if((ev->window == root) && !ev->same_screen)
  121. issel = True;
  122. }
  123. static void
  124. expose(XEvent *e)
  125. {
  126. XExposeEvent *ev = &e->xexpose;
  127. Client *c;
  128. if(ev->count == 0) {
  129. if((c = gettitle(ev->window)))
  130. draw_client(c);
  131. }
  132. }
  133. static void
  134. keymapnotify(XEvent *e)
  135. {
  136. update_keys();
  137. }
  138. static void
  139. maprequest(XEvent *e)
  140. {
  141. XMapRequestEvent *ev = &e->xmaprequest;
  142. static XWindowAttributes wa;
  143. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  144. return;
  145. if(wa.override_redirect) {
  146. XSelectInput(dpy, ev->window,
  147. (StructureNotifyMask | PropertyChangeMask));
  148. return;
  149. }
  150. if(!getclient(ev->window))
  151. manage(ev->window, &wa);
  152. }
  153. static void
  154. propertynotify(XEvent *e)
  155. {
  156. XPropertyEvent *ev = &e->xproperty;
  157. Client *c;
  158. if(ev->state == PropertyDelete)
  159. return; /* ignore */
  160. if((c = getclient(ev->window))) {
  161. if(ev->atom == wm_atom[WMProtocols]) {
  162. c->proto = win_proto(c->win);
  163. return;
  164. }
  165. switch (ev->atom) {
  166. default: break;
  167. case XA_WM_TRANSIENT_FOR:
  168. XGetTransientForHint(dpy, c->win, &c->trans);
  169. break;
  170. update_size(c);
  171. case XA_WM_NORMAL_HINTS:
  172. update_size(c);
  173. break;
  174. }
  175. if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
  176. update_name(c);
  177. draw_client(c);
  178. }
  179. }
  180. }
  181. static void
  182. unmapnotify(XEvent *e)
  183. {
  184. Client *c;
  185. XUnmapEvent *ev = &e->xunmap;
  186. if((c = getclient(ev->window)))
  187. unmanage(c);
  188. }