shithub: riscv

Download patch

ref: 1447b95555d6afa39f7ab04f04f1415f8937d899
parent: 31b10e364ff4ca7c04b96637dab6c6cf347a6a2a
author: cinap_lenrek <[email protected]>
date: Sun Sep 18 17:16:45 EDT 2016

rio: improved bandsize()

when dragging a window edge, allow one to slide to a corner
or slide from corner to corner (usefull when inverting).

also make sure the right or bottom of the rectangle returned
by whichrect() is not outside of the screen (which makes
drawing slow).

--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -364,6 +364,8 @@
 Rectangle
 whichrect(Rectangle r, Point p, int which)
 {
+	p.x = min(p.x, screen->clipr.max.x-1);
+	p.y = min(p.y, screen->clipr.max.y-1);
 	switch(which){
 	case 0:	/* top left */
 		r = Rect(p.x, p.y, r.max.x, r.max.y);
@@ -386,7 +388,7 @@
 	case 7:	/* bottom edge */
 		r = Rect(r.min.x, r.min.y, r.max.x, p.y+1);
 		break;
-	case 3:		/* left edge */
+	case 3:	/* left edge */
 		r = Rect(p.x, r.min.y, r.max.x, r.max.y);
 		break;
 	}
@@ -978,27 +980,27 @@
 {
 	Rectangle r, or;
 	Point p, startp;
-	int which, but;
+	int which, owhich, but;
 
-	p = mouse->xy;
+	owhich = -1;
+	or = w->screenr;
 	but = mouse->buttons;
-	which = whichcorner(w->screenr, p);
-	riosetcursor(corners[which]);
-	r = whichrect(w->screenr, p, which);
-	drawborder(r, 1);
-	or = r;
-	startp = p;
-	
-	while(mouse->buttons==but){
+	startp = onscreen(mouse->xy);
+	drawborder(or, 1);
+	while(mouse->buttons == but) {
 		p = onscreen(mouse->xy);
-		r = whichrect(w->screenr, p, which);
+		which = whichcorner(or, p);
+		if(which != owhich && which != 4 && (owhich|~which) & 1){
+			owhich = which;
+			riosetcursor(corners[which]);
+		}
+		r = whichrect(or, p, owhich);
 		if(!eqrect(r, or) && goodrect(r)){
-			drawborder(r, 1);
 			or = r;
+			drawborder(r, 1);
 		}
 		readmouse(mousectl);
 	}
-	p = mouse->xy;
 	drawborder(or, 0);
 	if(mouse->buttons!=0 || !goodrect(or) || eqrect(or, w->screenr)
 	|| abs(p.x-startp.x)+abs(p.y-startp.y) <= 1){