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.

117 lines
2.0 KiB

18 years ago
18 years ago
  1. /* See LICENSE file for copyright and license details. */
  2. #include "dwm.h"
  3. #include <stdlib.h>
  4. unsigned int blw = 0;
  5. Layout *lt = NULL;
  6. /* static */
  7. static unsigned int nlayouts = 0;
  8. LAYOUTS
  9. /* extern */
  10. void
  11. focusclient(const char *arg) {
  12. Client *c;
  13. if(!sel || !arg)
  14. return;
  15. if(atoi(arg) < 0) {
  16. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  17. if(!c) {
  18. for(c = clients; c && c->next; c = c->next);
  19. for(; c && !isvisible(c); c = c->prev);
  20. }
  21. }
  22. else {
  23. for(c = sel->next; c && !isvisible(c); c = c->next);
  24. if(!c)
  25. for(c = clients; c && !isvisible(c); c = c->next);
  26. }
  27. if(c) {
  28. focus(c);
  29. restack();
  30. }
  31. }
  32. void
  33. initlayouts(void) {
  34. unsigned int i, w;
  35. lt = &layout[0];
  36. nlayouts = sizeof layout / sizeof layout[0];
  37. for(blw = i = 0; i < nlayouts; i++) {
  38. w = textw(layout[i].symbol);
  39. if(w > blw)
  40. blw = w;
  41. }
  42. }
  43. Client *
  44. nexttiled(Client *c) {
  45. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  46. return c;
  47. }
  48. void
  49. restack(void) {
  50. Client *c;
  51. XEvent ev;
  52. XWindowChanges wc;
  53. drawstatus();
  54. if(!sel)
  55. return;
  56. if(sel->isfloating || lt->arrange == floating)
  57. XRaiseWindow(dpy, sel->win);
  58. if(lt->arrange != floating) {
  59. wc.stack_mode = Below;
  60. wc.sibling = barwin;
  61. if(!sel->isfloating) {
  62. XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
  63. wc.sibling = sel->win;
  64. }
  65. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  66. if(c == sel)
  67. continue;
  68. XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
  69. wc.sibling = c->win;
  70. }
  71. }
  72. XSync(dpy, False);
  73. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  74. }
  75. void
  76. setlayout(const char *arg) {
  77. int i;
  78. if(!arg) {
  79. lt++;
  80. if(lt == layout + nlayouts)
  81. lt = layout;
  82. }
  83. else {
  84. i = atoi(arg);
  85. if(i < 0 || i >= nlayouts)
  86. return;
  87. lt = &layout[i];
  88. }
  89. if(sel)
  90. lt->arrange();
  91. else
  92. drawstatus();
  93. }
  94. void
  95. togglebar(const char *arg) {
  96. if(bpos == BarOff)
  97. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  98. else
  99. bpos = BarOff;
  100. updatebarpos();
  101. lt->arrange();
  102. }