Configuration of dwm for Mac Computers
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.

222 lines
4.0 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 <X11/Xatom.h>
  10. #include "wm.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. raise(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 = ev->border_width;
  82. gravitate(c, False);
  83. }
  84. wc.x = ev->x;
  85. wc.y = ev->y;
  86. wc.width = ev->width;
  87. wc.height = ev->height;
  88. wc.border_width = 1;
  89. wc.sibling = None;
  90. wc.stack_mode = Above;
  91. ev->value_mask &= ~CWStackMode;
  92. ev->value_mask |= CWBorderWidth;
  93. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  94. XFlush(dpy);
  95. }
  96. static void
  97. destroynotify(XEvent *e)
  98. {
  99. Client *c;
  100. XDestroyWindowEvent *ev = &e->xdestroywindow;
  101. if((c = getclient(ev->window)))
  102. unmanage(c);
  103. }
  104. static void
  105. enternotify(XEvent *e)
  106. {
  107. XCrossingEvent *ev = &e->xcrossing;
  108. Client *c;
  109. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  110. return;
  111. if((c = getclient(ev->window)))
  112. focus(c);
  113. else if(ev->window == root)
  114. sel_screen = True;
  115. }
  116. static void
  117. leavenotify(XEvent *e)
  118. {
  119. XCrossingEvent *ev = &e->xcrossing;
  120. if((ev->window == root) && !ev->same_screen)
  121. sel_screen = True;
  122. }
  123. static void
  124. expose(XEvent *e)
  125. {
  126. XExposeEvent *ev = &e->xexpose;
  127. Client *c;
  128. if(ev->count == 0) {
  129. if((c = gettitle(ev->window)))
  130. draw_client(c);
  131. else if(ev->window == barwin)
  132. draw_bar();
  133. }
  134. }
  135. static void
  136. keymapnotify(XEvent *e)
  137. {
  138. update_keys();
  139. }
  140. static void
  141. maprequest(XEvent *e)
  142. {
  143. XMapRequestEvent *ev = &e->xmaprequest;
  144. static XWindowAttributes wa;
  145. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  146. return;
  147. if(wa.override_redirect) {
  148. XSelectInput(dpy, ev->window,
  149. (StructureNotifyMask | PropertyChangeMask));
  150. return;
  151. }
  152. if(!getclient(ev->window))
  153. manage(ev->window, &wa);
  154. }
  155. static void
  156. propertynotify(XEvent *e)
  157. {
  158. XPropertyEvent *ev = &e->xproperty;
  159. Client *c;
  160. if(ev->state == PropertyDelete)
  161. return; /* ignore */
  162. if(ev->atom == wm_atom[WMProtocols]) {
  163. c->proto = win_proto(c->win);
  164. return;
  165. }
  166. if((c = getclient(ev->window))) {
  167. switch (ev->atom) {
  168. default: break;
  169. case XA_WM_TRANSIENT_FOR:
  170. XGetTransientForHint(dpy, c->win, &c->trans);
  171. break;
  172. update_size(c);
  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. if(c == stack)
  180. draw_bar();
  181. else
  182. draw_client(c);
  183. }
  184. }
  185. }
  186. static void
  187. unmapnotify(XEvent *e)
  188. {
  189. Client *c;
  190. XUnmapEvent *ev = &e->xunmap;
  191. if((c = getclient(ev->window)))
  192. unmanage(c);
  193. }