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.

216 lines
4.0 KiB

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