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.

218 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(barwin == ev->window)
  128. draw_bar();
  129. else if((c = gettitle(ev->window)))
  130. draw_client(c);
  131. }
  132. }
  133. static void
  134. keymapnotify(XEvent *e)
  135. {
  136. update_keys();
  137. }
  138. static void
  139. maprequest(XEvent *e)
  140. {
  141. XMapRequestEvent *ev = &e->xmaprequest;
  142. static XWindowAttributes wa;
  143. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  144. return;
  145. if(wa.override_redirect) {
  146. XSelectInput(dpy, ev->window,
  147. (StructureNotifyMask | PropertyChangeMask));
  148. return;
  149. }
  150. if(!getclient(ev->window))
  151. manage(ev->window, &wa);
  152. }
  153. static void
  154. propertynotify(XEvent *e)
  155. {
  156. XPropertyEvent *ev = &e->xproperty;
  157. Window trans;
  158. Client *c;
  159. if(ev->state == PropertyDelete)
  160. return; /* ignore */
  161. if((c = getclient(ev->window))) {
  162. if(ev->atom == wm_atom[WMProtocols]) {
  163. c->proto = win_proto(c->win);
  164. return;
  165. }
  166. switch (ev->atom) {
  167. default: break;
  168. case XA_WM_TRANSIENT_FOR:
  169. XGetTransientForHint(dpy, c->win, &trans);
  170. if(!c->floating && (c->floating = (trans != 0)))
  171. arrange(NULL);
  172. break;
  173. case XA_WM_NORMAL_HINTS:
  174. update_size(c);
  175. break;
  176. }
  177. if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
  178. update_name(c);
  179. draw_client(c);
  180. }
  181. }
  182. }
  183. static void
  184. unmapnotify(XEvent *e)
  185. {
  186. Client *c;
  187. XUnmapEvent *ev = &e->xunmap;
  188. if((c = getclient(ev->window)))
  189. unmanage(c);
  190. }