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.

262 lines
5.1 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 "wm.h"
  10. /* local functions */
  11. static void configurerequest(XEvent *e);
  12. static void destroynotify(XEvent *e);
  13. static void enternotify(XEvent *e);
  14. static void leavenotify(XEvent *e);
  15. static void expose(XEvent *e);
  16. static void keypress(XEvent *e);
  17. static void keymapnotify(XEvent *e);
  18. static void maprequest(XEvent *e);
  19. static void propertynotify(XEvent *e);
  20. static void unmapnotify(XEvent *e);
  21. void (*handler[LASTEvent]) (XEvent *) = {
  22. [ConfigureRequest] = configurerequest,
  23. [DestroyNotify] = destroynotify,
  24. [EnterNotify] = enternotify,
  25. [LeaveNotify] = leavenotify,
  26. [Expose] = expose,
  27. [KeyPress] = keypress,
  28. [KeymapNotify] = keymapnotify,
  29. [MapRequest] = maprequest,
  30. [PropertyNotify] = propertynotify,
  31. [UnmapNotify] = unmapnotify
  32. };
  33. unsigned int
  34. flush_masked_events(long even_mask)
  35. {
  36. XEvent ev;
  37. unsigned int n = 0;
  38. while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
  39. return n;
  40. }
  41. static void
  42. configurerequest(XEvent *e)
  43. {
  44. #if 0
  45. XConfigureRequestEvent *ev = &e->xconfigurerequest;
  46. XWindowChanges wc;
  47. XRectangle *frect;
  48. Client *c;
  49. c = client_of_win(ev->window);
  50. ev->value_mask &= ~CWSibling;
  51. if(c) {
  52. gravitate_client(c, True);
  53. if(ev->value_mask & CWX)
  54. c->rect.x = ev->x;
  55. if(ev->value_mask & CWY)
  56. c->rect.y = ev->y;
  57. if(ev->value_mask & CWWidth)
  58. c->rect.width = ev->width;
  59. if(ev->value_mask & CWHeight)
  60. c->rect.height = ev->height;
  61. if(ev->value_mask & CWBorderWidth)
  62. c->border = ev->border_width;
  63. gravitate_client(c, False);
  64. if(c->frame) {
  65. if(c->sel->area->floating)
  66. frect=&c->sel->rect;
  67. else
  68. frect=&c->sel->revert;
  69. if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
  70. frect->y = wc.y = -height_of_bar();
  71. frect->x = wc.x = -def.border;
  72. }
  73. else {
  74. frect->y = wc.y = c->rect.y - height_of_bar();
  75. frect->x = wc.x = c->rect.x - def.border;
  76. }
  77. frect->width = wc.width = c->rect.width + 2 * def.border;
  78. frect->height = wc.height = c->rect.height + def.border
  79. + height_of_bar();
  80. wc.border_width = 1;
  81. wc.sibling = None;
  82. wc.stack_mode = ev->detail;
  83. if(c->sel->area->view != screen->sel)
  84. wc.x += 2 * screen->rect.width;
  85. if(c->sel->area->floating) {
  86. XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
  87. configure_client(c);
  88. }
  89. }
  90. }
  91. wc.x = ev->x;
  92. wc.y = ev->y;
  93. wc.width = ev->width;
  94. wc.height = ev->height;
  95. if(c && c->frame) {
  96. wc.x = def.border;
  97. wc.y = height_of_bar();
  98. wc.width = c->sel->rect.width - 2 * def.border;
  99. wc.height = c->sel->rect.height - def.border - height_of_bar();
  100. }
  101. wc.border_width = 0;
  102. wc.sibling = None;
  103. wc.stack_mode = Above;
  104. ev->value_mask &= ~CWStackMode;
  105. ev->value_mask |= CWBorderWidth;
  106. XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
  107. XFlush(dpy);
  108. #endif
  109. }
  110. static void
  111. destroynotify(XEvent *e)
  112. {
  113. #if 0
  114. Client *c;
  115. XDestroyWindowEvent *ev = &e->xdestroywindow;
  116. if((c = client_of_win(ev->window)))
  117. destroy_client(c);
  118. #endif
  119. }
  120. static void
  121. enternotify(XEvent *e)
  122. {
  123. #if 0
  124. XCrossingEvent *ev = &e->xcrossing;
  125. Client *c;
  126. if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
  127. return;
  128. if((c = client_of_win(ev->window))) {
  129. Frame *f = c->sel;
  130. Area *a = f->area;
  131. if(a->mode == Colmax)
  132. c = a->sel->client;
  133. focus(c, False);
  134. }
  135. else if(ev->window == root) {
  136. sel_screen = True;
  137. draw_frames();
  138. }
  139. #endif
  140. }
  141. static void
  142. leavenotify(XEvent *e)
  143. {
  144. XCrossingEvent *ev = &e->xcrossing;
  145. if((ev->window == root) && !ev->same_screen) {
  146. sel_screen = True;
  147. /*draw_frames();*/
  148. }
  149. }
  150. static void
  151. expose(XEvent *e)
  152. {
  153. XExposeEvent *ev = &e->xexpose;
  154. if(ev->count == 0) {
  155. if(ev->window == barwin)
  156. draw_bar();
  157. }
  158. }
  159. static void
  160. keypress(XEvent *e)
  161. {
  162. #if 0
  163. XKeyEvent *ev = &e->xkey;
  164. KeySym k = 0;
  165. char buf[32];
  166. int n;
  167. static Frame *f;
  168. ev->state &= valid_mask;
  169. if((f = frame_of_win(ev->window))) {
  170. buf[0] = 0;
  171. n = XLookupString(ev, buf, sizeof(buf), &k, 0);
  172. if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
  173. || IsPFKey(k) || IsPrivateKeypadKey(k))
  174. return;
  175. buf[n] = 0;
  176. blitz_kpress_input(&f->tagbar, ev->state, k, buf);
  177. }
  178. else
  179. key(root, ev->state, (KeyCode) ev->keycode);
  180. #endif
  181. }
  182. static void
  183. keymapnotify(XEvent *e)
  184. {
  185. #if 0
  186. update_keys();
  187. #endif
  188. }
  189. static void
  190. maprequest(XEvent *e)
  191. {
  192. XMapRequestEvent *ev = &e->xmaprequest;
  193. static XWindowAttributes wa;
  194. if(!XGetWindowAttributes(dpy, ev->window, &wa))
  195. return;
  196. if(wa.override_redirect) {
  197. XSelectInput(dpy, ev->window,
  198. (StructureNotifyMask | PropertyChangeMask));
  199. return;
  200. }
  201. /*if(!client_of_win(ev->window))*/
  202. manage(create_client(ev->window, &wa));
  203. }
  204. static void
  205. propertynotify(XEvent *e)
  206. {
  207. #if 0
  208. XPropertyEvent *ev = &e->xproperty;
  209. Client *c;
  210. if(ev->state == PropertyDelete)
  211. return; /* ignore */
  212. if((c = client_of_win(ev->window)))
  213. prop_client(c, ev);
  214. #endif
  215. }
  216. static void
  217. unmapnotify(XEvent *e)
  218. {
  219. #if 0
  220. Client *c;
  221. XUnmapEvent *ev = &e->xunmap;
  222. if((c = client_of_win(ev->window)))
  223. destroy_client(c);
  224. #endif
  225. }