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.

118 lines
2.5 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. static void
  11. update_client_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. }
  35. void
  36. manage(Window w, XWindowAttributes *wa)
  37. {
  38. Client *c, **l;
  39. XSetWindowAttributes twa;
  40. long msize;
  41. c = emallocz(sizeof(Client));
  42. c->win = w;
  43. c->r[RFloat].x = wa->x;
  44. c->r[RFloat].y = wa->y;
  45. c->r[RFloat].width = wa->width;
  46. c->r[RFloat].height = wa->height;
  47. c->border = wa->border_width;
  48. XSetWindowBorderWidth(dpy, c->win, 0);
  49. XGetTransientForHint(dpy, c->win, &c->trans);
  50. if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
  51. c->size.flags = PSize;
  52. c->fixedsize =
  53. (c->size.flags & PMinSize && c->size.flags & PMaxSize
  54. && c->size.min_width == c->size.max_width
  55. && c->size.min_height == c->size.max_height);
  56. update_client_name(c);
  57. twa.override_redirect = 1;
  58. twa.background_pixmap = ParentRelative;
  59. twa.event_mask = ExposureMask;
  60. c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
  61. c->r[RFloat].width, barrect.height, 0,
  62. DefaultDepth(dpy, screen), CopyFromParent,
  63. DefaultVisual(dpy, screen),
  64. CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
  65. for(l=&clients; *l; l=&(*l)->next);
  66. c->next = *l; /* *l == nil */
  67. *l = c;
  68. XMapRaised(dpy, c->win);
  69. XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
  70. XFlush(dpy);
  71. }
  72. static int
  73. dummy_error_handler(Display *dpy, XErrorEvent *error)
  74. {
  75. return 0;
  76. }
  77. void
  78. unmanage(Client *c)
  79. {
  80. Client **l;
  81. XGrabServer(dpy);
  82. XSetErrorHandler(dummy_error_handler);
  83. XUnmapWindow(dpy, c->win);
  84. XDestroyWindow(dpy, c->title);
  85. for(l=&clients; *l && *l != c; l=&(*l)->next);
  86. eassert(*l == c);
  87. *l = c->next;
  88. free(c);
  89. XFlush(dpy);
  90. XSetErrorHandler(error_handler);
  91. XUngrabServer(dpy);
  92. /*flush_masked_events(EnterWindowMask); ? */
  93. }
  94. Client *
  95. getclient(Window w)
  96. {
  97. Client *c;
  98. for(c = clients; c; c = c->next)
  99. if(c->win == w)
  100. return c;
  101. return NULL;
  102. }