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.

223 lines
4.0 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. unsigned int
  36. discard_events(long even_mask)
  37. {
  38. XEvent ev;
  39. unsigned int n = 0;
  40. while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
  41. return n;
  42. }
  43. static void
  44. buttonpress(XEvent *e)
  45. {
  46. XButtonPressedEvent *ev = &e->xbutton;
  47. Client *c;
  48. if((c = getclient(ev->window))) {
  49. switch(ev->button) {
  50. default:
  51. break;
  52. case Button1:
  53. mmove(c);
  54. break;
  55. case Button2:
  56. XLowerWindow(dpy, c->win);
  57. break;
  58. case Button3:
  59. mresize(c);
  60. break;
  61. }
  62. }
  63. }
  64. static void
  65. configurerequest(XEvent *e)
  66. {
  67. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  68. XWindowChanges wc;
  69. Client *c;
  70. ev->value_mask &= ~CWSibling;
  71. if((c = getclient(ev->window))) {
  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. }
  81. wc.x = ev->x;
  82. wc.y = ev->y;
  83. wc.width = ev->width;
  84. wc.height = ev->height;
  85. wc.border_width = 0;
  86. wc.sibling = None;
  87. wc.stack_mode = Above;
  88. ev->value_mask &= ~CWStackMode;
  89. ev->value_mask |= CWBorderWidth;
  90. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  91. XFlush(dpy);
  92. }
  93. static void
  94. destroynotify(XEvent *e)
  95. {
  96. Client *c;
  97. XDestroyWindowEvent *ev = &e->xdestroywindow;
  98. if((c = getclient(ev->window)))
  99. unmanage(c);
  100. }
  101. static void
  102. enternotify(XEvent *e)
  103. {
  104. XCrossingEvent *ev = &e->xcrossing;
  105. Client *c;
  106. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  107. return;
  108. if((c = getclient(ev->window)))
  109. focus(c);
  110. else if(ev->window == root) {
  111. sel_screen = True;
  112. /*draw_frames();*/
  113. }
  114. }
  115. static void
  116. leavenotify(XEvent *e)
  117. {
  118. XCrossingEvent *ev = &e->xcrossing;
  119. if((ev->window == root) && !ev->same_screen) {
  120. sel_screen = True;
  121. /*draw_frames();*/
  122. }
  123. }
  124. static void
  125. expose(XEvent *e)
  126. {
  127. XExposeEvent *ev = &e->xexpose;
  128. Client *c;
  129. if(ev->count == 0) {
  130. if((c = gettitle(ev->window)))
  131. draw_client(c);
  132. else if(ev->window == barwin)
  133. draw_bar();
  134. }
  135. }
  136. static void
  137. keymapnotify(XEvent *e)
  138. {
  139. update_keys();
  140. }
  141. static void
  142. maprequest(XEvent *e)
  143. {
  144. XMapRequestEvent *ev = &e->xmaprequest;
  145. static XWindowAttributes wa;
  146. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  147. return;
  148. if(wa.override_redirect) {
  149. XSelectInput(dpy, ev->window,
  150. (StructureNotifyMask | PropertyChangeMask));
  151. return;
  152. }
  153. if(!getclient(ev->window))
  154. manage(ev->window, &wa);
  155. }
  156. static void
  157. propertynotify(XEvent *e)
  158. {
  159. XPropertyEvent *ev = &e->xproperty;
  160. Client *c;
  161. if(ev->state == PropertyDelete)
  162. return; /* ignore */
  163. if(ev->atom == wm_atom[WMProtocols]) {
  164. c->proto = win_proto(c->win);
  165. return;
  166. }
  167. if((c = getclient(ev->window))) {
  168. switch (ev->atom) {
  169. default: break;
  170. case XA_WM_TRANSIENT_FOR:
  171. XGetTransientForHint(dpy, c->win, &c->trans);
  172. break;
  173. update_size(c);
  174. case XA_WM_NORMAL_HINTS:
  175. update_size(c);
  176. break;
  177. }
  178. if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
  179. update_name(c);
  180. if(c == stack)
  181. draw_bar();
  182. else
  183. draw_client(c);
  184. }
  185. }
  186. }
  187. static void
  188. unmapnotify(XEvent *e)
  189. {
  190. Client *c;
  191. XUnmapEvent *ev = &e->xunmap;
  192. if((c = getclient(ev->window)))
  193. unmanage(c);
  194. }