# samterm.patch -rw-r--r-- 1.8 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--- a/sys/src/cmd/samterm/flayer.c
+++ b/sys/src/cmd/samterm/flayer.c
@@ -144,6 +144,33 @@
 		newvisibilities(0);
 }
 
+Rectangle
+flautosize(Point p)
+{
+	int i;
+	Rectangle b, r;
+
+	b = screen->r;
+	for(i = 0; i <nllist; i++){
+		if(llist[i]->visible != All)
+			continue;
+		if(ptinrect(p, llist[i]->entire))
+			continue;
+
+		r = llist[i]->entire;
+		/* prefer expanding vertically over horizontally */
+		if(p.x > r.max.x)
+			rectclip(&b, Rpt(Pt(r.max.x, screen->r.min.y), screen->r.max));
+		else if(p.x < r.min.x)
+			rectclip(&b, Rpt(screen->r.min, Pt(r.min.x, screen->r.max.y)));
+		else if(p.y > r.max.y)
+			rectclip(&b, Rpt(Pt(screen->r.min.x, r.max.y), screen->r.max));
+		else if(p.y < r.min.y)
+			rectclip(&b, Rpt(screen->r.min, Pt(screen->r.max.x, r.min.y)));
+	}
+	return b;
+}
+
 void
 newvisibilities(int redraw)
 	/* if redraw false, we know it's a flupfront, and needn't
--- a/sys/src/cmd/samterm/flayer.h
+++ b/sys/src/cmd/samterm/flayer.h
@@ -41,6 +41,7 @@
 void	flstart(Rectangle);
 void	flupfront(Flayer*);
 Flayer	*flwhich(Point);
+Rectangle flautosize(Point);
 
 #define	FLMARGIN	4
 #define	FLSCROLLWID	12
--- a/sys/src/cmd/samterm/main.c
+++ b/sys/src/cmd/samterm/main.c
@@ -271,25 +271,10 @@
 int
 getr(Rectangle *rp)
 {
-	Point p;
-	Rectangle r;
-
 	*rp = getrect(3, mousectl);
-	if(rp->max.x && rp->max.x-rp->min.x<=5 && rp->max.y-rp->min.y<=5){
-		p = rp->min;
-		r = cmd.l[cmd.front].entire;
-		*rp = screen->r;
-		if(cmd.nwin==1){
-			if (p.y <= r.min.y)
-				rp->max.y = r.min.y;
-			else if (p.y >= r.max.y)
-				rp->min.y = r.max.y;
-			if (p.x <= r.min.x)
-				rp->max.x = r.min.x;
-			else if (p.x >= r.max.x)
-				rp->min.x = r.max.x;
-		}
-	}
+	if(rp->max.x && rp->max.x-rp->min.x<=5 && rp->max.y-rp->min.y<=5)
+		*rp = flautosize(rp->min);
+
 	return rectclip(rp, screen->r) &&
 	   rp->max.x-rp->min.x>100 && rp->max.y-rp->min.y>40;
 }