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.

220 lines
4.0 KiB

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