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.

224 lines
4.2 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. unsigned int
  36. discard_events(long even_mask)
  37. {
  38. XEvent ev;
  39. unsigned int n = 0;
  40. while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
  41. return n;
  42. }
  43. static void
  44. buttonpress(XEvent *e)
  45. {
  46. XButtonPressedEvent *ev = &e->xbutton;
  47. Client *c;
  48. if((c = getclient(ev->window))) {
  49. switch(ev->button) {
  50. default:
  51. break;
  52. case Button1:
  53. mmove(c);
  54. break;
  55. case Button2:
  56. XLowerWindow(dpy, c->win);
  57. break;
  58. case Button3:
  59. mresize(c);
  60. break;
  61. }
  62. }
  63. }
  64. static void
  65. configurerequest(XEvent *e)
  66. {
  67. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  68. XWindowChanges wc;
  69. Client *c;
  70. ev->value_mask &= ~CWSibling;
  71. if((c = getclient(ev->window))) {
  72. if(ev->value_mask & CWX)
  73. c->r[RFloat].x = ev->x;
  74. if(ev->value_mask & CWY)
  75. c->r[RFloat].y = ev->y;
  76. if(ev->value_mask & CWWidth)
  77. c->r[RFloat].width = ev->width;
  78. if(ev->value_mask & CWHeight)
  79. c->r[RFloat].height = ev->height;
  80. }
  81. wc.x = ev->x;
  82. wc.y = ev->y;
  83. wc.width = ev->width;
  84. wc.height = ev->height;
  85. wc.border_width = 0;
  86. wc.sibling = None;
  87. wc.stack_mode = Above;
  88. ev->value_mask &= ~CWStackMode;
  89. ev->value_mask |= CWBorderWidth;
  90. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  91. XFlush(dpy);
  92. }
  93. static void
  94. destroynotify(XEvent *e)
  95. {
  96. Client *c;
  97. XDestroyWindowEvent *ev = &e->xdestroywindow;
  98. if((c = getclient(ev->window)))
  99. unmanage(c);
  100. }
  101. static void
  102. enternotify(XEvent *e)
  103. {
  104. XCrossingEvent *ev = &e->xcrossing;
  105. Client *c;
  106. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  107. return;
  108. if((c = getclient(ev->window)))
  109. focus(c);
  110. else if(ev->window == root) {
  111. sel_screen = True;
  112. /*draw_frames();*/
  113. }
  114. }
  115. static void
  116. leavenotify(XEvent *e)
  117. {
  118. XCrossingEvent *ev = &e->xcrossing;
  119. if((ev->window == root) && !ev->same_screen) {
  120. sel_screen = True;
  121. /*draw_frames();*/
  122. }
  123. }
  124. static void
  125. expose(XEvent *e)
  126. {
  127. XExposeEvent *ev = &e->xexpose;
  128. if(ev->count == 0) {
  129. if(ev->window == barwin)
  130. draw_bar();
  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. long msize;
  158. Client *c;
  159. if(ev->state == PropertyDelete)
  160. return; /* ignore */
  161. if(ev->atom == wm_atom[WMProtocols]) {
  162. c->proto = win_proto(c->win);
  163. return;
  164. }
  165. if((c = getclient(ev->window))) {
  166. switch (ev->atom) {
  167. default: break;
  168. case XA_WM_TRANSIENT_FOR:
  169. XGetTransientForHint(dpy, c->win, &c->trans);
  170. break;
  171. case XA_WM_NORMAL_HINTS:
  172. if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
  173. || !c->size.flags)
  174. c->size.flags = PSize;
  175. if(c->size.flags & PMinSize && c->size.flags & PMaxSize
  176. && c->size.min_width == c->size.max_width
  177. && c->size.min_height == c->size.max_height)
  178. c->fixedsize = True;
  179. else
  180. c->fixedsize = False;
  181. break;
  182. }
  183. if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
  184. update_name(c);
  185. }
  186. }
  187. }
  188. static void
  189. unmapnotify(XEvent *e)
  190. {
  191. Client *c;
  192. XUnmapEvent *ev = &e->xunmap;
  193. if((c = getclient(ev->window)))
  194. unmanage(c);
  195. }