Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

195 lines
5.1 KiB

  1. #define EXPAND_LEFT (1 << 0)
  2. #define EXPAND_RIGHT (1 << 2)
  3. #define EXPAND_UP (1 << 4)
  4. #define EXPAND_DOWN (1 << 6)
  5. #define IS_SET(q, w) ((q & w) != 0)
  6. #define IS_FORCED(q, w) IS_SET((q << 1), w)
  7. #define EXPANDALL (EXPAND_LEFT | EXPAND_RIGHT | EXPAND_UP | EXPAND_DOWN)
  8. #define UNEXPAND (EXPANDALL << 1) // Force all directions to 0
  9. #define FORCE_EXPANDALL ~0 // Force expand in all directions
  10. void
  11. exresize(const Arg *arg)
  12. {
  13. Client *c;
  14. int x, y, nx, ny, nw, nh;
  15. c = selmon->sel;
  16. if (!c || !arg) return;
  17. if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
  18. togglefloating(NULL);
  19. if (c->expandmask != 0)
  20. expand(UNEXPAND);
  21. x = ((int *)arg->v)[0];
  22. y = ((int *)arg->v)[1];
  23. nw = MIN(selmon->ww - c->bw*2, c->w + x);
  24. nh = MIN(selmon->wh - c->bw*2, c->h + y);
  25. nx = c->x - x/2;
  26. ny = c->y - y/2;
  27. if (!((abs(c->x + c->w/2 - (selmon->wx + selmon->ww/2)) < snap))) {
  28. if ((nw == selmon->ww) ||
  29. (nx < selmon->wx) ||
  30. (abs(selmon->wx - c->x) < snap))
  31. nx = selmon->wx;
  32. else if ((nx+nw > (selmon->wx + selmon->ww)) ||
  33. (abs((selmon->wx + selmon->ww) - (c->x + c->w)) < snap))
  34. nx = (selmon->wx + selmon->ww) - nw - c->bw*2;
  35. } else
  36. nx = selmon->wx + selmon->ww/2 - nw/2;
  37. if (!((abs(c->y + c->h/2 - (selmon->wy + selmon->wh/2)) < snap))) {
  38. if ((nh == selmon->wh) ||
  39. (ny < selmon->wy) ||
  40. (abs(selmon->wy - c->y) < snap))
  41. ny = selmon->wy;
  42. else if ((ny+nh > (selmon->wy + selmon->wh)) ||
  43. (abs((selmon->wy + selmon->wh) - (c->y + c->h)) < snap))
  44. ny = (selmon->wy + selmon->wh) - nh - c->bw*2;
  45. } else
  46. ny = selmon->wy + selmon->wh/2 - nh/2;
  47. resizeclient(c, nx, ny, MAX(nw, 32), MAX(nh, 32));
  48. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
  49. }
  50. void
  51. explace(const Arg *arg)
  52. {
  53. Client *c;
  54. int nx, ny;
  55. c = selmon->sel;
  56. if (!c || (arg->ui >= 9)) return;
  57. if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
  58. togglefloating(NULL);
  59. nx = (arg->ui % 3) - 1;
  60. ny = (arg->ui / 3) - 1;
  61. if (nx < 0) nx = selmon->wx;
  62. else if (nx > 0) nx = selmon->wx + selmon->ww - c->w - c->bw*2;
  63. else nx = selmon->wx + selmon->ww/2 - c->w/2;
  64. if (ny < 0) ny = selmon->wy;
  65. else if (ny > 0) ny = selmon->wy + selmon->wh - c->h - c->bw*2;
  66. else ny = selmon->wy + selmon->wh/2 - c->h/2;
  67. resize(c, nx, ny, c->w, c->h, True);
  68. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
  69. }
  70. int
  71. calculate_expand(unsigned char mask, unsigned char curmask,
  72. unsigned char *newmask, unsigned char key,
  73. int *reset_value, int new_reset_value,
  74. int max_value, int old_value)
  75. {
  76. if (IS_SET(key, mask) ||
  77. (IS_SET(key, curmask) && (!IS_SET(key, mask) && IS_FORCED(key, mask))) ||
  78. (!IS_SET(key, curmask) && (IS_SET(key, mask) && IS_FORCED(key, mask)))) {
  79. if (IS_SET(key, mask) && (!IS_SET(key,curmask) || IS_FORCED(key,mask))) {
  80. if (!IS_SET(key, curmask))
  81. *reset_value = new_reset_value;
  82. *newmask |= key;
  83. return max_value;
  84. } else if ((IS_SET(key,curmask) && IS_SET(key, mask)) ||
  85. (!IS_SET(key, mask) && IS_FORCED(key, mask))) {
  86. *newmask &= ~key;
  87. return *reset_value;
  88. } else {
  89. *newmask &= ~key;
  90. return old_value;
  91. }
  92. } else
  93. return new_reset_value;
  94. }
  95. void
  96. expand(unsigned char mask)
  97. {
  98. XEvent ev;
  99. int nx1, ny1, nx2, ny2;
  100. #if SETBORDERPX_PATCH
  101. int bp = selmon->borderpx;
  102. #else
  103. int bp = borderpx;
  104. #endif // SETBORDERPX_PATCH
  105. unsigned char curmask;
  106. unsigned char newmask;
  107. if (!selmon->sel || selmon->sel->isfixed)
  108. return;
  109. XRaiseWindow(dpy, selmon->sel->win);
  110. newmask = curmask = selmon->sel->expandmask;
  111. if (curmask == 0) {
  112. if(!selmon->lt[selmon->sellt]->arrange || selmon->sel->isfloating)
  113. selmon->sel->wasfloating = 1;
  114. else {
  115. togglefloating(NULL);
  116. selmon->sel->wasfloating = 0;
  117. }
  118. }
  119. nx1 = calculate_expand(mask, curmask, &newmask,
  120. EXPAND_LEFT, &selmon->sel->expandx1,
  121. selmon->sel->x,
  122. selmon->wx,
  123. selmon->sel->oldx);
  124. nx2 = calculate_expand(mask, curmask, &newmask,
  125. EXPAND_RIGHT, &selmon->sel->expandx2,
  126. selmon->sel->x + selmon->sel->w,
  127. selmon->wx + selmon->ww - 2*bp,
  128. selmon->sel->oldw + selmon->sel->x);
  129. ny1 = calculate_expand(mask, curmask, &newmask,
  130. EXPAND_UP, &selmon->sel->expandy1,
  131. selmon->sel->y,
  132. selmon->wy,
  133. selmon->sel->oldy);
  134. ny2 = calculate_expand(mask, curmask, &newmask,
  135. EXPAND_DOWN, &selmon->sel->expandy2,
  136. selmon->sel->y + selmon->sel->h,
  137. selmon->wy + selmon->wh - 2*bp,
  138. selmon->sel->oldh + selmon->sel->y);
  139. resizeclient(selmon->sel, nx1, ny1, MAX(nx2-nx1, 32), MAX(ny2-ny1, 32));
  140. if ((newmask == 0) && (!selmon->sel->wasfloating))
  141. togglefloating(NULL);
  142. selmon->sel->expandmask = newmask;
  143. drawbar(selmon);
  144. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  145. }
  146. void
  147. togglemaximize(const Arg *arg)
  148. {
  149. if (arg->i > 0) expand(FORCE_EXPANDALL);
  150. else if (arg->i < 0) expand(UNEXPAND);
  151. else expand(EXPANDALL);
  152. }
  153. void
  154. toggleverticalexpand(const Arg *arg)
  155. {
  156. if (arg->i < 0) expand(EXPAND_DOWN);
  157. else if (arg->i > 0) expand(EXPAND_UP);
  158. else expand(EXPAND_DOWN | EXPAND_UP);
  159. }
  160. void
  161. togglehorizontalexpand(const Arg *arg)
  162. {
  163. if (arg->i < 0) expand(EXPAND_LEFT);
  164. else if (arg->i > 0) expand(EXPAND_RIGHT);
  165. else expand(EXPAND_LEFT | EXPAND_RIGHT);
  166. }