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.

202 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 configurerequest(XEvent *e);
  13. static void destroynotify(XEvent *e);
  14. static void enternotify(XEvent *e);
  15. static void leavenotify(XEvent *e);
  16. static void expose(XEvent *e);
  17. static void keymapnotify(XEvent *e);
  18. static void maprequest(XEvent *e);
  19. static void propertynotify(XEvent *e);
  20. static void unmapnotify(XEvent *e);
  21. void (*handler[LASTEvent]) (XEvent *) = {
  22. [ConfigureRequest] = configurerequest,
  23. [DestroyNotify] = destroynotify,
  24. [EnterNotify] = enternotify,
  25. [LeaveNotify] = leavenotify,
  26. [Expose] = expose,
  27. [KeyPress] = keypress,
  28. [KeymapNotify] = keymapnotify,
  29. [MapRequest] = maprequest,
  30. [PropertyNotify] = propertynotify,
  31. [UnmapNotify] = unmapnotify
  32. };
  33. unsigned int
  34. flush_events(long even_mask)
  35. {
  36. XEvent ev;
  37. unsigned int n = 0;
  38. while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
  39. return n;
  40. }
  41. static void
  42. configurerequest(XEvent *e)
  43. {
  44. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  45. XWindowChanges wc;
  46. Client *c;
  47. c = getclient(ev->window);
  48. ev->value_mask &= ~CWSibling;
  49. if(c) {
  50. if(ev->value_mask & CWX)
  51. c->r[RFloat].x = ev->x;
  52. if(ev->value_mask & CWY)
  53. c->r[RFloat].y = ev->y;
  54. if(ev->value_mask & CWWidth)
  55. c->r[RFloat].width = ev->width;
  56. if(ev->value_mask & CWHeight)
  57. c->r[RFloat].height = ev->height;
  58. if(ev->value_mask & CWBorderWidth)
  59. c->border = ev->border_width;
  60. }
  61. wc.x = ev->x;
  62. wc.y = ev->y;
  63. wc.width = ev->width;
  64. wc.height = ev->height;
  65. wc.border_width = 0;
  66. wc.sibling = None;
  67. wc.stack_mode = Above;
  68. ev->value_mask &= ~CWStackMode;
  69. ev->value_mask |= CWBorderWidth;
  70. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  71. XFlush(dpy);
  72. }
  73. static void
  74. destroynotify(XEvent *e)
  75. {
  76. Client *c;
  77. XDestroyWindowEvent *ev = &e->xdestroywindow;
  78. if((c = getclient(ev->window)))
  79. unmanage(c);
  80. }
  81. static void
  82. enternotify(XEvent *e)
  83. {
  84. XCrossingEvent *ev = &e->xcrossing;
  85. Client *c;
  86. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  87. return;
  88. if((c = getclient(ev->window)))
  89. focus(c);
  90. else if(ev->window == root) {
  91. sel_screen = True;
  92. /*draw_frames();*/
  93. }
  94. }
  95. static void
  96. leavenotify(XEvent *e)
  97. {
  98. XCrossingEvent *ev = &e->xcrossing;
  99. if((ev->window == root) && !ev->same_screen) {
  100. sel_screen = True;
  101. /*draw_frames();*/
  102. }
  103. }
  104. static void
  105. expose(XEvent *e)
  106. {
  107. XExposeEvent *ev = &e->xexpose;
  108. if(ev->count == 0) {
  109. if(ev->window == barwin)
  110. draw_bar();
  111. }
  112. }
  113. static void
  114. keymapnotify(XEvent *e)
  115. {
  116. update_keys();
  117. }
  118. static void
  119. maprequest(XEvent *e)
  120. {
  121. XMapRequestEvent *ev = &e->xmaprequest;
  122. static XWindowAttributes wa;
  123. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  124. return;
  125. if(wa.override_redirect) {
  126. XSelectInput(dpy, ev->window,
  127. (StructureNotifyMask | PropertyChangeMask));
  128. return;
  129. }
  130. if(!getclient(ev->window))
  131. manage(ev->window, &wa);
  132. }
  133. static void
  134. propertynotify(XEvent *e)
  135. {
  136. XPropertyEvent *ev = &e->xproperty;
  137. long msize;
  138. Client *c;
  139. if(ev->state == PropertyDelete)
  140. return; /* ignore */
  141. if(ev->atom == wm_atom[WMProtocols]) {
  142. c->proto = win_proto(c->win);
  143. return;
  144. }
  145. if((c = getclient(ev->window))) {
  146. switch (ev->atom) {
  147. default: break;
  148. case XA_WM_TRANSIENT_FOR:
  149. XGetTransientForHint(dpy, c->win, &c->trans);
  150. break;
  151. case XA_WM_NORMAL_HINTS:
  152. if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
  153. || !c->size.flags)
  154. c->size.flags = PSize;
  155. if(c->size.flags & PMinSize && c->size.flags & PMaxSize
  156. && c->size.min_width == c->size.max_width
  157. && c->size.min_height == c->size.max_height)
  158. c->fixedsize = True;
  159. else
  160. c->fixedsize = False;
  161. break;
  162. }
  163. if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
  164. update_name(c);
  165. }
  166. }
  167. }
  168. static void
  169. unmapnotify(XEvent *e)
  170. {
  171. Client *c;
  172. XUnmapEvent *ev = &e->xunmap;
  173. if((c = getclient(ev->window)))
  174. unmanage(c);
  175. }