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.

195 lines
3.7 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. #if 0
  76. Client *c;
  77. XDestroyWindowEvent *ev = &e->xdestroywindow;
  78. if((c = client_of_win(ev->window)))
  79. destroy_client(c);
  80. #endif
  81. }
  82. static void
  83. enternotify(XEvent *e)
  84. {
  85. #if 0
  86. XCrossingEvent *ev = &e->xcrossing;
  87. Client *c;
  88. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  89. return;
  90. if((c = client_of_win(ev->window))) {
  91. Frame *f = c->sel;
  92. Area *a = f->area;
  93. if(a->mode == Colmax)
  94. c = a->sel->client;
  95. focus(c, False);
  96. }
  97. else if(ev->window == root) {
  98. sel_screen = True;
  99. draw_frames();
  100. }
  101. #endif
  102. }
  103. static void
  104. leavenotify(XEvent *e)
  105. {
  106. XCrossingEvent *ev = &e->xcrossing;
  107. if((ev->window == root) && !ev->same_screen) {
  108. sel_screen = True;
  109. /*draw_frames();*/
  110. }
  111. }
  112. static void
  113. expose(XEvent *e)
  114. {
  115. XExposeEvent *ev = &e->xexpose;
  116. if(ev->count == 0) {
  117. if(ev->window == barwin)
  118. draw_bar();
  119. }
  120. }
  121. static void
  122. keymapnotify(XEvent *e)
  123. {
  124. #if 0
  125. update_keys();
  126. #endif
  127. }
  128. static void
  129. maprequest(XEvent *e)
  130. {
  131. XMapRequestEvent *ev = &e->xmaprequest;
  132. static XWindowAttributes wa;
  133. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  134. return;
  135. if(wa.override_redirect) {
  136. XSelectInput(dpy, ev->window,
  137. (StructureNotifyMask | PropertyChangeMask));
  138. return;
  139. }
  140. /*if(!client_of_win(ev->window))*/
  141. /*manage(create_client(ev->window, &wa));*/
  142. XMapRaised(dpy, ev->window);
  143. XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height);
  144. XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime);
  145. XFlush(dpy);
  146. }
  147. static void
  148. propertynotify(XEvent *e)
  149. {
  150. #if 0
  151. XPropertyEvent *ev = &e->xproperty;
  152. Client *c;
  153. if(ev->state == PropertyDelete)
  154. return; /* ignore */
  155. if((c = client_of_win(ev->window)))
  156. prop_client(c, ev);
  157. #endif
  158. }
  159. static void
  160. unmapnotify(XEvent *e)
  161. {
  162. #if 0
  163. Client *c;
  164. XUnmapEvent *ev = &e->xunmap;
  165. if((c = client_of_win(ev->window)))
  166. destroy_client(c);
  167. #endif
  168. }