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.

187 lines
3.4 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 "wm.h"
  10. /* local functions */
  11. static void configurerequest(XEvent *e);
  12. static void destroynotify(XEvent *e);
  13. static void enternotify(XEvent *e);
  14. static void leavenotify(XEvent *e);
  15. static void expose(XEvent *e);
  16. static void keymapnotify(XEvent *e);
  17. static void maprequest(XEvent *e);
  18. static void propertynotify(XEvent *e);
  19. static void unmapnotify(XEvent *e);
  20. void (*handler[LASTEvent]) (XEvent *) = {
  21. [ConfigureRequest] = configurerequest,
  22. [DestroyNotify] = destroynotify,
  23. [EnterNotify] = enternotify,
  24. [LeaveNotify] = leavenotify,
  25. [Expose] = expose,
  26. [KeyPress] = keypress,
  27. [KeymapNotify] = keymapnotify,
  28. [MapRequest] = maprequest,
  29. [PropertyNotify] = propertynotify,
  30. [UnmapNotify] = unmapnotify
  31. };
  32. unsigned int
  33. flush_masked_events(long even_mask)
  34. {
  35. XEvent ev;
  36. unsigned int n = 0;
  37. while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
  38. return n;
  39. }
  40. static void
  41. configurerequest(XEvent *e)
  42. {
  43. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  44. XWindowChanges wc;
  45. Client *c;
  46. c = getclient(ev->window);
  47. ev->value_mask &= ~CWSibling;
  48. if(c) {
  49. if(ev->value_mask & CWX)
  50. c->r[RFloat].x = ev->x;
  51. if(ev->value_mask & CWY)
  52. c->r[RFloat].y = ev->y;
  53. if(ev->value_mask & CWWidth)
  54. c->r[RFloat].width = ev->width;
  55. if(ev->value_mask & CWHeight)
  56. c->r[RFloat].height = ev->height;
  57. if(ev->value_mask & CWBorderWidth)
  58. c->border = ev->border_width;
  59. }
  60. wc.x = ev->x;
  61. wc.y = ev->y;
  62. wc.width = ev->width;
  63. wc.height = ev->height;
  64. wc.border_width = 0;
  65. wc.sibling = None;
  66. wc.stack_mode = Above;
  67. ev->value_mask &= ~CWStackMode;
  68. ev->value_mask |= CWBorderWidth;
  69. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  70. XFlush(dpy);
  71. }
  72. static void
  73. destroynotify(XEvent *e)
  74. {
  75. Client *c;
  76. XDestroyWindowEvent *ev = &e->xdestroywindow;
  77. if((c = getclient(ev->window)))
  78. unmanage(c);
  79. }
  80. static void
  81. enternotify(XEvent *e)
  82. {
  83. #if 0
  84. XCrossingEvent *ev = &e->xcrossing;
  85. Client *c;
  86. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  87. return;
  88. if((c = client_of_win(ev->window))) {
  89. Frame *f = c->sel;
  90. Area *a = f->area;
  91. if(a->mode == Colmax)
  92. c = a->sel->client;
  93. focus(c, False);
  94. }
  95. else if(ev->window == root) {
  96. sel_screen = True;
  97. draw_frames();
  98. }
  99. #endif
  100. }
  101. static void
  102. leavenotify(XEvent *e)
  103. {
  104. XCrossingEvent *ev = &e->xcrossing;
  105. if((ev->window == root) && !ev->same_screen) {
  106. sel_screen = True;
  107. /*draw_frames();*/
  108. }
  109. }
  110. static void
  111. expose(XEvent *e)
  112. {
  113. XExposeEvent *ev = &e->xexpose;
  114. if(ev->count == 0) {
  115. if(ev->window == barwin)
  116. draw_bar();
  117. }
  118. }
  119. static void
  120. keymapnotify(XEvent *e)
  121. {
  122. #if 0
  123. update_keys();
  124. #endif
  125. }
  126. static void
  127. maprequest(XEvent *e)
  128. {
  129. XMapRequestEvent *ev = &e->xmaprequest;
  130. static XWindowAttributes wa;
  131. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  132. return;
  133. if(wa.override_redirect) {
  134. XSelectInput(dpy, ev->window,
  135. (StructureNotifyMask | PropertyChangeMask));
  136. return;
  137. }
  138. if(!getclient(ev->window))
  139. manage(ev->window, &wa);
  140. }
  141. static void
  142. propertynotify(XEvent *e)
  143. {
  144. #if 0
  145. XPropertyEvent *ev = &e->xproperty;
  146. Client *c;
  147. if(ev->state == PropertyDelete)
  148. return; /* ignore */
  149. if((c = client_of_win(ev->window)))
  150. prop_client(c, ev);
  151. #endif
  152. }
  153. static void
  154. unmapnotify(XEvent *e)
  155. {
  156. Client *c;
  157. XUnmapEvent *ev = &e->xunmap;
  158. if((c = getclient(ev->window)))
  159. unmanage(c);
  160. }