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.
This commit is contained in:
cinap_lenrek 2015-09-20 12:25:01 +02:00
parent 30a9d59070
commit d1315ade41
3 changed files with 15 additions and 31 deletions

View file

@ -35,7 +35,13 @@ if(test -f /dev/vgactl){
} }
} }
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 ask mouseport ' is (ps2, ps2intellimouse, 0, 1, 2)' ps2
switch($mouseport){ switch($mouseport){
case ps2 ps2intellimouse 0 1 2 case ps2 ps2intellimouse 0 1 2

View file

@ -44,7 +44,6 @@ geninitdraw(char *devdir, void(*error)(Display*, char*), char *fontname, char *l
df = getdefont(display); df = getdefont(display);
display->defaultsubfont = df; display->defaultsubfont = df;
if(df == nil){ if(df == nil){
fprint(2, "imageinit: can't open default subfont: %r\n");
Error: Error:
closedisplay(display); closedisplay(display);
display = nil; display = nil;
@ -70,16 +69,12 @@ geninitdraw(char *devdir, void(*error)(Display*, char*), char *fontname, char *l
df->n-1, deffontname); df->n-1, deffontname);
//BUG: Need something better for this installsubfont("*default*", df); //BUG: Need something better for this installsubfont("*default*", df);
font = buildfont(display, buf, deffontname); font = buildfont(display, buf, deffontname);
if(font == nil){ if(font == nil)
fprint(2, "imageinit: can't open default font: %r\n");
goto Error; goto Error;
}
}else{ }else{
font = openfont(display, fontname); /* BUG: grey fonts */ font = openfont(display, fontname); /* BUG: grey fonts */
if(font == nil){ if(font == nil)
fprint(2, "imageinit: can't open font %s: %r\n", fontname);
goto Error; goto Error;
}
} }
display->defaultfont = font; display->defaultfont = font;
@ -110,14 +105,10 @@ geninitdraw(char *devdir, void(*error)(Display*, char*), char *fontname, char *l
} }
int 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); return geninitdraw(dev, error, fontname, label, dev, Refnone);
} }
@ -138,7 +129,6 @@ retry:
fd = open(winname, OREAD); fd = open(winname, OREAD);
if(fd<0 || (n=read(fd, buf, sizeof buf-1))<=0){ if(fd<0 || (n=read(fd, buf, sizeof buf-1))<=0){
if((image=d->image) == nil){ if((image=d->image) == nil){
fprint(2, "gengetwindow: %r\n");
*winp = nil; *winp = nil;
d->screenimage = nil; d->screenimage = nil;
return -1; return -1;
@ -158,7 +148,6 @@ retry:
strcpy(obuf, buf); strcpy(obuf, buf);
goto retry; goto retry;
} }
fprint(2, "namedimage %s failed: %r\n", buf);
} }
if(*winp != nil){ if(*winp != nil){
_freeimage1(*winp); _freeimage1(*winp);
@ -171,7 +160,6 @@ retry:
d->screenimage = nil; d->screenimage = nil;
return -1; return -1;
} }
assert(image->chan != 0);
} }
d->screenimage = image; d->screenimage = image;
@ -194,7 +182,6 @@ retry:
freeimage(image); freeimage(image);
return -1; return -1;
} }
assert((*winp)->chan != 0);
d->screenimage = *winp; d->screenimage = *winp;
return 1; return 1;
} }
@ -236,13 +223,10 @@ initdisplay(char *dev, char *win, void(*error)(Display*, char*))
sprint(buf, "%s/draw/new", dev); sprint(buf, "%s/draw/new", dev);
ctlfd = open(buf, ORDWR|OCEXEC); ctlfd = open(buf, ORDWR|OCEXEC);
if(ctlfd < 0){ if(ctlfd < 0){
if(bind("#i", dev, MAFTER) < 0){
Error1: Error1:
free(t); free(t);
werrstr("initdisplay: %s: %r", buf); werrstr("initdisplay: %s: %r", buf);
return nil; return nil;
}
ctlfd = open(buf, ORDWR|OCEXEC);
} }
if(ctlfd < 0) if(ctlfd < 0)
goto Error1; goto Error1;
@ -399,10 +383,8 @@ lockdisplay(Display *disp)
{ {
if(debuglockdisplay){ if(debuglockdisplay){
/* avoid busy looping; it's rare we collide anyway */ /* avoid busy looping; it's rare we collide anyway */
while(!canqlock(&disp->qlock)){ while(!canqlock(&disp->qlock))
fprint(1, "proc %d waiting for display lock...\n", getpid());
sleep(1000); sleep(1000);
}
}else }else
qlock(&disp->qlock); qlock(&disp->qlock);
} }

View file

@ -99,10 +99,6 @@ initmouse(char *file, Image *i)
file = "/dev/mouse"; file = "/dev/mouse";
mc->file = strdup(file); mc->file = strdup(file);
mc->mfd = open(file, ORDWR|OCEXEC); 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){ if(mc->mfd < 0){
free(mc); free(mc);
return nil; return nil;