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.

230 lines
5.9 KiB

  1. void
  2. dragmfact(const Arg *arg)
  3. {
  4. unsigned int n;
  5. int py, px; // pointer coordinates
  6. int ax, ay, aw, ah; // area position, width and height
  7. int center = 0, horizontal = 0, mirror = 0, fixed = 0; // layout configuration
  8. double fact;
  9. Monitor *m;
  10. XEvent ev;
  11. Time lasttime = 0;
  12. m = selmon;
  13. #if VANITYGAPS_PATCH
  14. int oh, ov, ih, iv;
  15. getgaps(m, &oh, &ov, &ih, &iv, &n);
  16. #else
  17. Client *c;
  18. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  19. #endif // VANITYGAPS_PATCH
  20. ax = m->wx;
  21. ay = m->wy;
  22. ah = m->wh;
  23. aw = m->ww;
  24. if (!n)
  25. return;
  26. #if FLEXTILE_DELUXE_LAYOUT
  27. else if (m->lt[m->sellt]->arrange == &flextile) {
  28. int layout = m->ltaxis[LAYOUT];
  29. if (layout < 0) {
  30. mirror = 1;
  31. layout *= -1;
  32. }
  33. if (layout > FLOATING_MASTER) {
  34. layout -= FLOATING_MASTER;
  35. fixed = 1;
  36. }
  37. if (layout == SPLIT_HORIZONTAL || layout == SPLIT_HORIZONTAL_DUAL_STACK)
  38. horizontal = 1;
  39. else if (layout == SPLIT_CENTERED_VERTICAL && (fixed || n - m->nmaster > 1))
  40. center = 1;
  41. else if (layout == FLOATING_MASTER) {
  42. center = 1;
  43. if (aw < ah)
  44. horizontal = 1;
  45. }
  46. else if (layout == SPLIT_CENTERED_HORIZONTAL) {
  47. if (fixed || n - m->nmaster > 1)
  48. center = 1;
  49. horizontal = 1;
  50. }
  51. }
  52. #endif // FLEXTILE_DELUXE_LAYOUT
  53. #if CENTEREDMASTER_LAYOUT
  54. else if (m->lt[m->sellt]->arrange == &centeredmaster && (fixed || n - m->nmaster > 1))
  55. center = 1;
  56. #endif // CENTEREDMASTER_LAYOUT
  57. #if CENTEREDFLOATINGMASTER_LAYOUT
  58. else if (m->lt[m->sellt]->arrange == &centeredfloatingmaster)
  59. center = 1;
  60. #endif // CENTEREDFLOATINGMASTER_LAYOUT
  61. #if BSTACK_LAYOUT
  62. else if (m->lt[m->sellt]->arrange == &bstack)
  63. horizontal = 1;
  64. #endif // BSTACK_LAYOUT
  65. #if BSTACKHORIZ_LAYOUT
  66. else if (m->lt[m->sellt]->arrange == &bstackhoriz)
  67. horizontal = 1;
  68. #endif // BSTACKHORIZ_LAYOUT
  69. /* do not allow mfact to be modified under certain conditions */
  70. if (!m->lt[m->sellt]->arrange // floating layout
  71. || (!fixed && m->nmaster && n <= m->nmaster) // no master
  72. #if MONOCLE_LAYOUT
  73. || m->lt[m->sellt]->arrange == &monocle
  74. #endif // MONOCLE_LAYOUT
  75. #if GRIDMODE_LAYOUT
  76. || m->lt[m->sellt]->arrange == &grid
  77. #endif // GRIDMODE_LAYOUT
  78. #if HORIZGRID_LAYOUT
  79. || m->lt[m->sellt]->arrange == &horizgrid
  80. #endif // HORIZGRID_LAYOUT
  81. #if GAPPLESSGRID_LAYOUT
  82. || m->lt[m->sellt]->arrange == &gaplessgrid
  83. #endif // GAPPLESSGRID_LAYOUT
  84. #if NROWGRID_LAYOUT
  85. || m->lt[m->sellt]->arrange == &nrowgrid
  86. #endif // NROWGRID_LAYOUT
  87. #if FLEXTILE_DELUXE_LAYOUT
  88. || (m->lt[m->sellt]->arrange == &flextile && m->ltaxis[LAYOUT] == NO_SPLIT)
  89. #endif // FLEXTILE_DELUXE_LAYOUT
  90. )
  91. return;
  92. #if VANITYGAPS_PATCH
  93. ay += oh;
  94. ax += ov;
  95. aw -= 2*ov;
  96. ah -= 2*oh;
  97. #endif // VANITYGAPS_PATCH
  98. if (center) {
  99. if (horizontal) {
  100. px = ax + aw / 2;
  101. #if VANITYGAPS_PATCH
  102. py = ay + ah / 2 + (ah - 2*ih) * (m->mfact / 2.0) + ih / 2;
  103. #else
  104. py = ay + ah / 2 + ah * m->mfact / 2.0;
  105. #endif // VANITYGAPS_PATCH
  106. } else { // vertical split
  107. #if VANITYGAPS_PATCH
  108. px = ax + aw / 2 + (aw - 2*iv) * m->mfact / 2.0 + iv / 2;
  109. #else
  110. px = ax + aw / 2 + aw * m->mfact / 2.0;
  111. #endif // VANITYGAPS_PATCH
  112. py = ay + ah / 2;
  113. }
  114. } else if (horizontal) {
  115. px = ax + aw / 2;
  116. if (mirror)
  117. #if VANITYGAPS_PATCH
  118. py = ay + (ah - ih) * (1.0 - m->mfact) + ih / 2;
  119. #else
  120. py = ay + (ah * (1.0 - m->mfact));
  121. #endif // VANITYGAPS_PATCH
  122. else
  123. #if VANITYGAPS_PATCH
  124. py = ay + ((ah - ih) * m->mfact) + ih / 2;
  125. #else
  126. py = ay + (ah * m->mfact);
  127. #endif // VANITYGAPS_PATCH
  128. } else { // vertical split
  129. if (mirror)
  130. #if VANITYGAPS_PATCH
  131. px = ax + (aw - iv) * (1.0 - m->mfact) + iv / 2;
  132. #else
  133. px = ax + (aw * m->mfact);
  134. #endif // VANITYGAPS_PATCH
  135. else
  136. #if VANITYGAPS_PATCH
  137. px = ax + ((aw - iv) * m->mfact) + iv / 2;
  138. #else
  139. px = ax + (aw * m->mfact);
  140. #endif // VANITYGAPS_PATCH
  141. py = ay + ah / 2;
  142. }
  143. if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
  144. None, cursor[horizontal ? CurResizeVertArrow : CurResizeHorzArrow]->cursor, CurrentTime) != GrabSuccess)
  145. return;
  146. #if WARP_PATCH
  147. ignore_warp = 1;
  148. #endif // WARP_PATCH
  149. XWarpPointer(dpy, None, root, 0, 0, 0, 0, px, py);
  150. do {
  151. XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
  152. switch(ev.type) {
  153. case ConfigureRequest:
  154. case Expose:
  155. case MapRequest:
  156. handler[ev.type](&ev);
  157. break;
  158. case MotionNotify:
  159. if ((ev.xmotion.time - lasttime) <= (1000 / 40))
  160. continue;
  161. if (lasttime != 0) {
  162. px = ev.xmotion.x;
  163. py = ev.xmotion.y;
  164. }
  165. lasttime = ev.xmotion.time;
  166. #if VANITYGAPS_PATCH
  167. if (center)
  168. if (horizontal)
  169. if (py - ay > ah / 2)
  170. fact = (double) 1.0 - (ay + ah - py - ih / 2) * 2 / (double) (ah - 2*ih);
  171. else
  172. fact = (double) 1.0 - (py - ay - ih / 2) * 2 / (double) (ah - 2*ih);
  173. else
  174. if (px - ax > aw / 2)
  175. fact = (double) 1.0 - (ax + aw - px - iv / 2) * 2 / (double) (aw - 2*iv);
  176. else
  177. fact = (double) 1.0 - (px - ax - iv / 2) * 2 / (double) (aw - 2*iv);
  178. else
  179. if (horizontal)
  180. fact = (double) (py - ay - ih / 2) / (double) (ah - ih);
  181. else
  182. fact = (double) (px - ax - iv / 2) / (double) (aw - iv);
  183. #else
  184. if (center)
  185. if (horizontal)
  186. if (py - ay > ah / 2)
  187. fact = (double) 1.0 - (ay + ah - py) * 2 / (double) ah;
  188. else
  189. fact = (double) 1.0 - (py - ay) * 2 / (double) ah;
  190. else
  191. if (px - ax > aw / 2)
  192. fact = (double) 1.0 - (ax + aw - px) * 2 / (double) aw;
  193. else
  194. fact = (double) 1.0 - (px - ax) * 2 / (double) aw;
  195. else
  196. if (horizontal)
  197. fact = (double) (py - ay) / (double) ah;
  198. else
  199. fact = (double) (px - ax) / (double) aw;
  200. #endif // VANITYGAPS_PATCH
  201. if (!center && mirror)
  202. fact = 1.0 - fact;
  203. setmfact(&((Arg) { .f = 1.0 + fact }));
  204. px = ev.xmotion.x;
  205. py = ev.xmotion.y;
  206. break;
  207. }
  208. } while (ev.type != ButtonRelease);
  209. #if WARP_PATCH
  210. ignore_warp = 0;
  211. #endif // WARP_PATCH
  212. XUngrabPointer(dpy, CurrentTime);
  213. while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  214. }