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.

151 lines
3.0 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. void
  11. update_name(Client *c)
  12. {
  13. XTextProperty name;
  14. int n;
  15. char **list = NULL;
  16. name.nitems = 0;
  17. c->name[0] = 0;
  18. XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
  19. if(!name.nitems)
  20. XGetWMName(dpy, c->win, &name);
  21. if(!name.nitems)
  22. return;
  23. if(name.encoding == XA_STRING)
  24. strncpy(c->name, (char *)name.value, sizeof(c->name));
  25. else {
  26. if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
  27. && n > 0 && *list)
  28. {
  29. strncpy(c->name, *list, sizeof(c->name));
  30. XFreeStringList(list);
  31. }
  32. }
  33. XFree(name.value);
  34. if(c == stack)
  35. draw_bar();
  36. else
  37. draw_client(c);
  38. }
  39. void
  40. focus(Client *c)
  41. {
  42. Client **l;
  43. for(l=&stack; *l && *l != c; l=&(*l)->snext);
  44. eassert(*l == c);
  45. *l = c->snext;
  46. c->snext = stack;
  47. stack = c;
  48. XRaiseWindow(dpy, c->win);
  49. XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
  50. XFlush(dpy);
  51. }
  52. void
  53. manage(Window w, XWindowAttributes *wa)
  54. {
  55. Client *c, **l;
  56. XSetWindowAttributes twa;
  57. long msize;
  58. c = emallocz(sizeof(Client));
  59. c->win = w;
  60. c->r[RFloat].x = wa->x;
  61. c->r[RFloat].y = wa->y;
  62. c->r[RFloat].width = wa->width;
  63. c->r[RFloat].height = wa->height;
  64. c->border = wa->border_width;
  65. XSetWindowBorderWidth(dpy, c->win, 0);
  66. XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
  67. XGetTransientForHint(dpy, c->win, &c->trans);
  68. if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
  69. c->size.flags = PSize;
  70. c->fixedsize =
  71. (c->size.flags & PMinSize && c->size.flags & PMaxSize
  72. && c->size.min_width == c->size.max_width
  73. && c->size.min_height == c->size.max_height);
  74. update_name(c);
  75. twa.override_redirect = 1;
  76. twa.background_pixmap = ParentRelative;
  77. twa.event_mask = ExposureMask;
  78. c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
  79. c->r[RFloat].width, barrect.height, 0,
  80. DefaultDepth(dpy, screen), CopyFromParent,
  81. DefaultVisual(dpy, screen),
  82. CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
  83. for(l=&clients; *l; l=&(*l)->next);
  84. c->next = *l; /* *l == nil */
  85. *l = c;
  86. c->snext = stack;
  87. stack = c;
  88. XMapWindow(dpy, c->win);
  89. focus(c);
  90. }
  91. static int
  92. dummy_error_handler(Display *dpy, XErrorEvent *error)
  93. {
  94. return 0;
  95. }
  96. void
  97. unmanage(Client *c)
  98. {
  99. Client **l;
  100. XGrabServer(dpy);
  101. XSetErrorHandler(dummy_error_handler);
  102. XUnmapWindow(dpy, c->win);
  103. XDestroyWindow(dpy, c->title);
  104. for(l=&clients; *l && *l != c; l=&(*l)->next);
  105. eassert(*l == c);
  106. *l = c->next;
  107. for(l=&stack; *l && *l != c; l=&(*l)->snext);
  108. eassert(*l == c);
  109. *l = c->snext;
  110. free(c);
  111. XFlush(dpy);
  112. XSetErrorHandler(error_handler);
  113. XUngrabServer(dpy);
  114. flush_events(EnterWindowMask);
  115. if(stack)
  116. focus(stack);
  117. }
  118. Client *
  119. getclient(Window w)
  120. {
  121. Client *c;
  122. for(c = clients; c; c = c->next)
  123. if(c->win == w)
  124. return c;
  125. return NULL;
  126. }
  127. void
  128. draw_client(Client *c)
  129. {
  130. }