git: 9front

Download patch

ref: 6b1d5dd87ab8db1f339226db3ce53abe1bdbaff0
parent: 9e906340ca08563f16414e9c8b75b578ff0f3881
author: cinap_lenrek <cinap_lenrek@vmi>
date: Tue Nov 29 08:41:02 EST 2011

rio: dont serve /dev/screen from display->image, as its not updated on resize. instead, use screen and omit the file if provided by the enviroment. allow unaligned reads.

--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -430,9 +430,13 @@
 				dir = dirtab;
 				goto Accept;
 			}
-		
+
+			/* don't serve these if it's provided in the environment */
 			if(snarffd>=0 && strcmp(x->wname[i], "snarf")==0)
-				break;	/* don't serve /dev/snarf if it's provided in the environment */
+				break;	
+			if(strcmp(x->wname[i], "screen")==0 && access("/dev/screen", AEXIST)==0)
+				break;
+
 			id = WIN(f->qid);
 			d = dirtab;
 			d++;	/* skip '.' */
--- a/sys/src/cmd/rio/xfid.c
+++ b/sys/src/cmd/rio/xfid.c
@@ -567,19 +567,29 @@
 int
 readwindow(Image *i, char *t, Rectangle r, int offset, int n)
 {
-	int ww, y;
+	int ww, oo, y, m;
+	uchar *tt;
 
-	offset -= 5*12;
 	ww = bytesperline(r, i->depth);
 	r.min.y += offset/ww;
 	if(r.min.y >= r.max.y)
 		return 0;
-	y = r.min.y + n/ww;
+	y = r.min.y + (n + ww-1)/ww;
 	if(y < r.max.y)
 		r.max.y = y;
-	if(r.max.y <= r.min.y)
-		return 0;
-	return unloadimage(i, r, (uchar*)t, n);
+	m = ww * Dy(r);
+	oo = offset % ww;
+	if(oo == 0 && n >= m)
+		return unloadimage(i, r, (uchar*)t, n);
+	if((tt = malloc(m)) == nil)
+		return -1;
+	m = unloadimage(i, r, tt, m) - oo;
+	if(m > 0){
+		if(n < m) m = n;
+		memmove(t, tt + oo, m);
+	}
+	free(tt);
+	return m;
 }
 
 void
@@ -798,30 +808,26 @@
 
 	case Qwindow:
 		i = w->i;
-		if(i == nil || Dx(w->screenr)<=0){
+		r = w->screenr;
+		if(i == nil || Dx(r)<=0){
 			filsysrespond(x->fs, x, &fc, Enowindow);
 			return;
 		}
-		r = w->screenr;
 		goto caseImage;
 
 	case Qscreen:
-		i = display->image;
-		if(i == nil){
-			filsysrespond(x->fs, x, &fc, "no top-level screen");
-			break;
-		}
-		r = i->r;
-		/* fall through */
+		i = screen;
+		r = screen->r;
 
 	caseImage:
 		if(off < 5*12){
 			n = sprint(buf, "%11s %11d %11d %11d %11d ",
 				chantostr(cbuf, i->chan),
-				i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y);
+				r.min.x, r.min.y, r.max.x, r.max.y);
 			t = estrdup(buf);
 			goto Text;
 		}
+		off -= 5*12;
 		t = malloc(cnt);
 		fc.data = t;
 		n = readwindow(i, t, r, off, cnt);	/* careful; fc.count is unsigned */
--