betterresize.c (3811B)
1 void 2 resizemouse(const Arg *arg) 3 { 4 Client *c; 5 Monitor *m; 6 XEvent ev; 7 #if LOCK_MOVE_RESIZE_REFRESH_RATE 8 Time lasttime = 0; 9 #endif 10 if (!(c = selmon->sel) || c->isfullscreen) 11 return; 12 13 restack(selmon); 14 15 int orig_x = c->x; 16 int orig_y = c->y; 17 int orig_w = c->w; 18 int orig_h = c->h; 19 20 int rx, ry; 21 Window junkwin; 22 int junk_signed; 23 unsigned int junk; 24 if (!XQueryPointer(dpy, c->win, &junkwin, &junkwin, &junk_signed, &junk_signed, &rx, &ry, &junk)) 25 return; 26 int left = rx < orig_w / 3; 27 int right = rx > orig_w * 2 / 3; 28 int top = ry < orig_h / 3; 29 int bottom = ry > orig_h * 2 / 3; 30 #if BR_CHANGE_CURSOR 31 Cursor cur; 32 if (top && left) cur = cursor[CurNW]->cursor; 33 else if (top && right) cur = cursor[CurNE]->cursor; 34 else if (bottom && left) cur = cursor[CurSW]->cursor; 35 else if (bottom && right) cur = cursor[CurSE]->cursor; 36 else if (top) cur = cursor[CurN]->cursor; 37 else if (bottom) cur = cursor[CurS]->cursor; 38 else if (left) cur = cursor[CurW]->cursor; 39 else if (right) cur = cursor[CurE]->cursor; 40 else cur = cursor[CurResize]->cursor; // fallback 41 #else 42 Cursor cur = cursor[CurResize]->cursor; 43 #endif 44 if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, 45 None, cur, CurrentTime) != GrabSuccess) 46 return; 47 do { 48 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); 49 50 if (ev.type == MotionNotify) { 51 #if LOCK_MOVE_RESIZE_REFRESH_RATE 52 if (ev.xmotion.time - lasttime <= (1000 / refreshrate)) 53 continue; 54 lasttime = ev.xmotion.time; 55 #endif 56 int dx = ev.xmotion.x_root - (orig_x + rx); 57 int dy = ev.xmotion.y_root - (orig_y + ry); 58 59 int nx = orig_x; 60 int ny = orig_y; 61 int nw = orig_w; 62 int nh = orig_h; 63 64 if (left) nw = orig_w - dx; 65 else if (right) nw = orig_w + dx; 66 67 if (top) nh = orig_h - dy; 68 else if (bottom) nh = orig_h + dy; 69 70 int min_w = MAX(1, c->minw); 71 int min_h = MAX(1, c->minh); 72 73 if (nw < min_w) nw = min_w; 74 if (nh < min_h) nh = min_h; 75 76 if (left) nx = orig_x + (orig_w - nw); 77 if (top) ny = orig_y + (orig_h - nh); 78 79 int dx_final = nw - orig_w; 80 int dy_final = nh - orig_h; 81 #if !RESIZINIG_WINDOWS_IN_ALL_LAYOUTS_FLOATS_THEM 82 if (!c->isfloating && selmon->lt[selmon->sellt]->arrange && 83 (abs(dx_final) > snap || abs(dy_final) > snap)) { 84 #else 85 if (!c->isfloating && (abs(dx_final) > snap || abs(dy_final) > snap)) { 86 #endif 87 if (nx >= selmon->wx && nx + nw <= selmon->wx + selmon->ww && 88 ny >= selmon->wy && ny + nh <= selmon->wy + selmon->wh) { 89 90 togglefloating(NULL); 91 92 orig_x = c->x; 93 orig_y = c->y; 94 orig_w = c->w; 95 orig_h = c->h; 96 } 97 } 98 #if USE_RESIZECLIENT_FUNC 99 resizeclient(c, nx, ny, nw, nh); 100 #else 101 resize(c, nx, ny, nw, nh, 1); 102 #endif 103 drawbar(selmon); //fix for issue 1 104 } 105 } while (ev.type != ButtonRelease); 106 107 XUngrabPointer(dpy, CurrentTime); 108 while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 109 110 if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { 111 sendmon(c, m); 112 selmon = m; 113 focus(NULL); 114 } 115 #if ENHANCED_TOGGLE_FLOATING && RESTORE_SIZE_AND_POS_ETF 116 c->wasmanuallyedited = 1; 117 if (c->isfloating) { 118 c->sfx = c->x; 119 c->sfy = c->y; 120 c->sfw = c->w; 121 c->sfh = c->h; 122 } 123 #endif 124 }