dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

dragcfact.c (1888B)


      1 void
      2 dragcfact(const Arg *arg)
      3 {
      4 	int prev_x, prev_y, dist_x, dist_y;
      5 	float fact;
      6 	Client *c;
      7 	XEvent ev;
      8 	Time lasttime = 0;
      9 
     10 	if (!(c = selmon->sel))
     11 		return;
     12 	if (c->isfloating) {
     13 		resizemouse(arg);
     14 		return;
     15 	}
     16 	#if !FAKEFULLSCREEN_PATCH
     17 	#if FAKEFULLSCREEN_CLIENT_PATCH
     18 	if (c->isfullscreen && !c->fakefullscreen) /* no support resizing fullscreen windows by mouse */
     19 		return;
     20 	#else
     21 	if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
     22 		return;
     23 	#endif // FAKEFULLSCREEN_CLIENT_PATCH
     24 	#endif // !FAKEFULLSCREEN_PATCH
     25 	restack(selmon);
     26 
     27 	if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
     28 		None, cursor[CurIronCross]->cursor, CurrentTime) != GrabSuccess)
     29 		return;
     30 
     31 	#if WARP_PATCH
     32 	ignore_warp = 1;
     33 	#endif // WARP_PATCH
     34 
     35 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
     36 
     37 	prev_x = prev_y = -999999;
     38 
     39 	do {
     40 		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
     41 		switch(ev.type) {
     42 		case ConfigureRequest:
     43 		case Expose:
     44 		case MapRequest:
     45 			handler[ev.type](&ev);
     46 			break;
     47 		case MotionNotify:
     48 			if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate_dragcfact))
     49 				continue;
     50 			lasttime = ev.xmotion.time;
     51 			if (prev_x == -999999) {
     52 				prev_x = ev.xmotion.x_root;
     53 				prev_y = ev.xmotion.y_root;
     54 			}
     55 
     56 			dist_x = ev.xmotion.x - prev_x;
     57 			dist_y = ev.xmotion.y - prev_y;
     58 
     59 			if (abs(dist_x) > abs(dist_y)) {
     60 				fact = (float) 4.0 * dist_x / c->mon->ww;
     61 			} else {
     62 				fact = (float) -4.0 * dist_y / c->mon->wh;
     63 			}
     64 
     65 			if (fact)
     66 				setcfact(&((Arg) { .f = fact }));
     67 
     68 			prev_x = ev.xmotion.x;
     69 			prev_y = ev.xmotion.y;
     70 			break;
     71 		}
     72 	} while (ev.type != ButtonRelease);
     73 
     74 	#if WARP_PATCH
     75 	ignore_warp = 0;
     76 	#endif // WARP_PATCH
     77 
     78 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
     79 
     80 	XUngrabPointer(dpy, CurrentTime);
     81 	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
     82 }
     83