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