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.

192 lines
3.9 KiB

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 <stdlib.h>
  6. #include <string.h>
  7. #include <X11/Xatom.h>
  8. #include "util.h"
  9. #include "wm.h"
  10. #define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
  11. void
  12. update_name(Client *c)
  13. {
  14. XTextProperty name;
  15. int n;
  16. char **list = NULL;
  17. name.nitems = 0;
  18. c->name[0] = 0;
  19. XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
  20. if(!name.nitems)
  21. XGetWMName(dpy, c->win, &name);
  22. if(!name.nitems)
  23. return;
  24. if(name.encoding == XA_STRING)
  25. strncpy(c->name, (char *)name.value, sizeof(c->name));
  26. else {
  27. if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
  28. && n > 0 && *list)
  29. {
  30. strncpy(c->name, *list, sizeof(c->name));
  31. XFreeStringList(list);
  32. }
  33. }
  34. XFree(name.value);
  35. if(c == stack)
  36. draw_bar();
  37. else
  38. draw_client(c);
  39. }
  40. void
  41. update_size(Client *c)
  42. {
  43. XSizeHints size;
  44. long msize;
  45. if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
  46. size.flags = PSize;
  47. c->flags = size.flags;
  48. c->basew = size.base_width;
  49. c->baseh = size.base_height;
  50. c->incw = size.width_inc;
  51. c->inch = size.height_inc;
  52. c->maxw = size.max_width;
  53. c->maxh = size.max_height;
  54. c->minw = size.min_width;
  55. c->minh = size.min_height;
  56. }
  57. void
  58. focus(Client *c)
  59. {
  60. Client **l;
  61. for(l=&stack; *l && *l != c; l=&(*l)->snext);
  62. eassert(*l == c);
  63. *l = c->snext;
  64. c->snext = stack;
  65. stack = c;
  66. XRaiseWindow(dpy, c->win);
  67. XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
  68. XFlush(dpy);
  69. }
  70. void
  71. manage(Window w, XWindowAttributes *wa)
  72. {
  73. Client *c, **l;
  74. XSetWindowAttributes twa;
  75. c = emallocz(sizeof(Client));
  76. c->win = w;
  77. c->x = wa->x;
  78. c->y = wa->y;
  79. c->w = wa->width;
  80. c->h = wa->height;
  81. update_size(c);
  82. XSetWindowBorderWidth(dpy, c->win, 1);
  83. XSelectInput(dpy, c->win, CLIENT_MASK);
  84. XGetTransientForHint(dpy, c->win, &c->trans);
  85. update_name(c);
  86. twa.override_redirect = 1;
  87. twa.background_pixmap = ParentRelative;
  88. twa.event_mask = ExposureMask;
  89. c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
  90. 0, DefaultDepth(dpy, screen), CopyFromParent,
  91. DefaultVisual(dpy, screen),
  92. CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
  93. for(l=&clients; *l; l=&(*l)->next);
  94. c->next = *l; /* *l == nil */
  95. *l = c;
  96. c->snext = stack;
  97. stack = c;
  98. XMapWindow(dpy, c->win);
  99. XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
  100. GrabModeAsync, GrabModeSync, None, None);
  101. XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
  102. GrabModeAsync, GrabModeSync, None, None);
  103. XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
  104. GrabModeAsync, GrabModeSync, None, None);
  105. focus(c);
  106. }
  107. void
  108. resize(Client *c)
  109. {
  110. XConfigureEvent e;
  111. XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
  112. e.type = ConfigureNotify;
  113. e.event = c->win;
  114. e.window = c->win;
  115. e.x = c->x;
  116. e.y = c->y;
  117. e.width = c->w;
  118. e.height = c->h;
  119. e.border_width = 0;
  120. e.above = None;
  121. e.override_redirect = False;
  122. XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
  123. XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
  124. XSelectInput(dpy, c->win, CLIENT_MASK);
  125. XFlush(dpy);
  126. }
  127. static int
  128. dummy_error_handler(Display *dpy, XErrorEvent *error)
  129. {
  130. return 0;
  131. }
  132. void
  133. unmanage(Client *c)
  134. {
  135. Client **l;
  136. XGrabServer(dpy);
  137. XSetErrorHandler(dummy_error_handler);
  138. XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  139. XUnmapWindow(dpy, c->win);
  140. XDestroyWindow(dpy, c->title);
  141. for(l=&clients; *l && *l != c; l=&(*l)->next);
  142. eassert(*l == c);
  143. *l = c->next;
  144. for(l=&stack; *l && *l != c; l=&(*l)->snext);
  145. eassert(*l == c);
  146. *l = c->snext;
  147. free(c);
  148. XFlush(dpy);
  149. XSetErrorHandler(error_handler);
  150. XUngrabServer(dpy);
  151. discard_events(EnterWindowMask);
  152. if(stack)
  153. focus(stack);
  154. }
  155. Client *
  156. getclient(Window w)
  157. {
  158. Client *c;
  159. for(c = clients; c; c = c->next)
  160. if(c->win == w)
  161. return c;
  162. return NULL;
  163. }
  164. void
  165. draw_client(Client *c)
  166. {
  167. }