bar_wintitleactions.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. void
  2. hide(Client *c) {
  3. Client *n;
  4. if (!c || HIDDEN(c))
  5. return;
  6. Window w = c->win;
  7. static XWindowAttributes ra, ca;
  8. // more or less taken directly from blackbox's hide() function
  9. XGrabServer(dpy);
  10. XGetWindowAttributes(dpy, root, &ra);
  11. XGetWindowAttributes(dpy, w, &ca);
  12. // prevent UnmapNotify events
  13. XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
  14. XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
  15. XUnmapWindow(dpy, w);
  16. setclientstate(c, IconicState);
  17. XSelectInput(dpy, root, ra.your_event_mask);
  18. XSelectInput(dpy, w, ca.your_event_mask);
  19. XUngrabServer(dpy);
  20. if (c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
  21. for (n = c->snext; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
  22. if (!n)
  23. for (n = c->mon->stack; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
  24. } else {
  25. n = nexttiled(c);
  26. if (!n)
  27. n = prevtiled(c);
  28. }
  29. focus(n);
  30. arrange(c->mon);
  31. }
  32. void
  33. show(Client *c)
  34. {
  35. if (!c || !HIDDEN(c))
  36. return;
  37. XMapWindow(dpy, c->win);
  38. setclientstate(c, NormalState);
  39. arrange(c->mon);
  40. }
  41. void
  42. togglewin(const Arg *arg)
  43. {
  44. Client *c = (Client*)arg->v;
  45. if (!c)
  46. return;
  47. if (!HIDDEN(c) && c == selmon->sel)
  48. hide(c);
  49. else {
  50. if (HIDDEN(c))
  51. show(c);
  52. focus(c);
  53. restack(c->mon);
  54. }
  55. }
  56. Client *
  57. prevtiled(Client *c)
  58. {
  59. Client *p, *i;
  60. for (p = NULL, i = c->mon->clients; c && i != c; i = i->next)
  61. if (ISVISIBLE(i) && !HIDDEN(i))
  62. p = i;
  63. return p;
  64. }
  65. void
  66. showhideclient(const Arg *arg)
  67. {
  68. Client *c = (Client*)arg->v;
  69. if (!c)
  70. c = selmon->sel;
  71. if (!c)
  72. return;
  73. if (HIDDEN(c)) {
  74. show(c);
  75. focus(c);
  76. restack(c->mon);
  77. } else {
  78. hide(c);
  79. }
  80. }