shithub: riscv

Download patch

ref: d1315ade4171b25039a60b01d8fd8f39d822cc10
parent: 30a9d5907018a578873bff2f7f1eaccfcc4d5a1f
author: cinap_lenrek <[email protected]>
date: Sun Sep 20 08:25:01 EDT 2015

libdraw, screenrc: bind devdraw and devmouse in screenrc instead of handling it in libdraw

libdraw was attempting to bind '#i' and '#m' to /dev when it could not find
/dev/mouse or /dev/draw. a library shouldnt be that clever and do namespace
manipulations on behalf of the caller. so instead, we setup the graphics
environment in screenrc on boot time.

--- a/rc/bin/screenrc
+++ b/rc/bin/screenrc
@@ -35,7 +35,13 @@
 	}
 }
 
-if(test -f /dev/mousectl && test -f '#i/winname'){
+if(! test -d /dev/draw)
+	bind -a '#i' /dev
+
+if(! test -f /dev/mouse)
+	bind -a '#m' /dev
+
+if(test -f /dev/mousectl && test -f /dev/winname){
 	ask mouseport ' is (ps2, ps2intellimouse, 0, 1, 2)' ps2
 	switch($mouseport){
 	case ps2 ps2intellimouse 0 1 2
--- a/sys/src/libdraw/init.c
+++ b/sys/src/libdraw/init.c
@@ -44,7 +44,6 @@
 	df = getdefont(display);
 	display->defaultsubfont = df;
 	if(df == nil){
-		fprint(2, "imageinit: can't open default subfont: %r\n");
     Error:
 		closedisplay(display);
 		display = nil;
@@ -70,16 +69,12 @@
 			df->n-1, deffontname);
 //BUG: Need something better for this	installsubfont("*default*", df);
 		font = buildfont(display, buf, deffontname);
-		if(font == nil){
-			fprint(2, "imageinit: can't open default font: %r\n");
+		if(font == nil)
 			goto Error;
-		}
 	}else{
 		font = openfont(display, fontname);	/* BUG: grey fonts */
-		if(font == nil){
-			fprint(2, "imageinit: can't open font %s: %r\n", fontname);
+		if(font == nil)
 			goto Error;
-		}
 	}
 	display->defaultfont = font;
 
@@ -110,14 +105,10 @@
 }
 
 int
-initdraw(void(*error)(Display*, char*), char *fontname , char *label)
+initdraw(void(*error)(Display*, char*), char *fontname, char *label)
 {
-	char *dev = "/dev";
+	static char dev[] = "/dev";
 
-	if(access("/dev/draw/new", AEXIST)<0 && bind("#i", "/dev", MAFTER)<0){
-		fprint(2, "imageinit: can't bind /dev/draw: %r\n");
-		return -1;
-	}
 	return geninitdraw(dev, error, fontname, label, dev, Refnone);
 }
 
@@ -138,7 +129,6 @@
 	fd = open(winname, OREAD);
 	if(fd<0 || (n=read(fd, buf, sizeof buf-1))<=0){
 		if((image=d->image) == nil){
-			fprint(2, "gengetwindow: %r\n");
 			*winp = nil;
 			d->screenimage = nil;
 			return -1;
@@ -158,7 +148,6 @@
 				strcpy(obuf, buf);
 				goto retry;
 			}
-			fprint(2, "namedimage %s failed: %r\n", buf);
 		}
 		if(*winp != nil){
 			_freeimage1(*winp);
@@ -171,7 +160,6 @@
 			d->screenimage = nil;
 			return -1;
 		}
-		assert(image->chan != 0);
 	}
 
 	d->screenimage = image;
@@ -194,7 +182,6 @@
 		freeimage(image);
 		return -1;
 	}
-	assert((*winp)->chan != 0);
 	d->screenimage = *winp;
 	return 1;
 }
@@ -236,13 +223,10 @@
 	sprint(buf, "%s/draw/new", dev);
 	ctlfd = open(buf, ORDWR|OCEXEC);
 	if(ctlfd < 0){
-		if(bind("#i", dev, MAFTER) < 0){
     Error1:
-			free(t);
-			werrstr("initdisplay: %s: %r", buf);
-			return nil;
-		}
-		ctlfd = open(buf, ORDWR|OCEXEC);
+		free(t);
+		werrstr("initdisplay: %s: %r", buf);
+		return nil;
 	}
 	if(ctlfd < 0)
 		goto Error1;
@@ -399,10 +383,8 @@
 {
 	if(debuglockdisplay){
 		/* avoid busy looping; it's rare we collide anyway */
-		while(!canqlock(&disp->qlock)){
-			fprint(1, "proc %d waiting for display lock...\n", getpid());
+		while(!canqlock(&disp->qlock))
 			sleep(1000);
-		}
 	}else
 		qlock(&disp->qlock);
 }
--- a/sys/src/libdraw/mouse.c
+++ b/sys/src/libdraw/mouse.c
@@ -99,10 +99,6 @@
 		file = "/dev/mouse";
 	mc->file = strdup(file);
 	mc->mfd = open(file, ORDWR|OCEXEC);
-	if(mc->mfd<0 && strcmp(file, "/dev/mouse")==0){
-		bind("#m", "/dev", MAFTER);
-		mc->mfd = open(file, ORDWR|OCEXEC);
-	}
 	if(mc->mfd < 0){
 		free(mc);
 		return nil;