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.

146 lines
2.8 KiB

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