npage: cleanup
This commit is contained in:
parent
f2c136f903
commit
97f742c860
1 changed files with 77 additions and 70 deletions
|
@ -124,6 +124,19 @@ addpage(Page *up, char *label, int (*popen)(Page *), void *pdata, int fd)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
resizewin(Point size)
|
||||||
|
{
|
||||||
|
int wctl;
|
||||||
|
|
||||||
|
if((wctl = open("/dev/wctl", OWRITE)) < 0)
|
||||||
|
return;
|
||||||
|
/* add rio border */
|
||||||
|
size = addpt(size, Pt(Borderwidth*2, Borderwidth*2));
|
||||||
|
fprint(wctl, "resize -dx %d -dy %d\n", size.x, size.y);
|
||||||
|
close(wctl);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
createtmp(ulong id, char *pfx)
|
createtmp(ulong id, char *pfx)
|
||||||
{
|
{
|
||||||
|
@ -555,22 +568,33 @@ prevpage(Page *x)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
loadpage(Page *p)
|
openpage(Page *p)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if(p->open && p->image == nil && p->text == nil){
|
fd = -1;
|
||||||
if((fd = p->open(p)) < 0)
|
if(p->open == nil || (fd = p->open(p)) < 0)
|
||||||
p->open = nil;
|
p->open = nil;
|
||||||
else {
|
else {
|
||||||
pagegen++;
|
|
||||||
if(rotate)
|
if(rotate)
|
||||||
pipeline(fd, "rotate -r %d", rotate);
|
pipeline(fd, "rotate -r %d", rotate);
|
||||||
if(resize.x)
|
if(resize.x)
|
||||||
pipeline(fd, "resize -x %d", resize.x);
|
pipeline(fd, "resize -x %d", resize.x);
|
||||||
else if(resize.y)
|
else if(resize.y)
|
||||||
pipeline(fd, "resize -y %d", resize.y);
|
pipeline(fd, "resize -y %d", resize.y);
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
loadpage(Page *p)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if(p->open && p->image == nil && p->text == nil){
|
||||||
|
if((fd = openpage(p)) >= 0){
|
||||||
|
pagegen++;
|
||||||
p->image = readimage(display, fd, 1);
|
p->image = readimage(display, fd, 1);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
@ -612,19 +636,15 @@ unloadpages(int age)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
resizewin(Point);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
loadpages(Page *p, int ahead, int oviewgen)
|
loadpages(Page *p, int ahead, int oviewgen)
|
||||||
{
|
{
|
||||||
Point size;
|
Point size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
unloadpages(NAHEAD*2);
|
|
||||||
|
|
||||||
ahead++; /* load at least one */
|
ahead++; /* load at least one */
|
||||||
for(i = 0; i < ahead && p; p = nextpage(p)){
|
unloadpages(ahead*2);
|
||||||
|
for(i = 0; i < ahead && p; p = nextpage(p), i++){
|
||||||
if(viewgen != oviewgen)
|
if(viewgen != oviewgen)
|
||||||
break;
|
break;
|
||||||
if(canqlock(p)){
|
if(canqlock(p)){
|
||||||
|
@ -636,7 +656,6 @@ loadpages(Page *p, int ahead, int oviewgen)
|
||||||
}
|
}
|
||||||
size = p->image ? subpt(p->image->r.max, p->image->r.min) : ZP;
|
size = p->image ? subpt(p->image->r.max, p->image->r.min) : ZP;
|
||||||
qunlock(p);
|
qunlock(p);
|
||||||
i++;
|
|
||||||
|
|
||||||
if(p == current){
|
if(p == current){
|
||||||
if(size.x && size.y && newwin){
|
if(size.x && size.y && newwin){
|
||||||
|
@ -711,19 +730,6 @@ gendrawdiff(Image *dst, Rectangle bot, Rectangle top,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
resizewin(Point size)
|
|
||||||
{
|
|
||||||
int wctl;
|
|
||||||
|
|
||||||
if((wctl = open("/dev/wctl", OWRITE)) < 0)
|
|
||||||
return;
|
|
||||||
/* add rio border */
|
|
||||||
size = addpt(size, Pt(Borderwidth, Borderwidth));
|
|
||||||
fprint(wctl, "resize -dx %d -dy %d\n", size.x, size.y);
|
|
||||||
close(wctl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
eresized(int new)
|
eresized(int new)
|
||||||
{
|
{
|
||||||
|
@ -737,7 +743,6 @@ eresized(int new)
|
||||||
sysfatal("getwindow: %r");
|
sysfatal("getwindow: %r");
|
||||||
unlockdisplay(display);
|
unlockdisplay(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((p = current) == nil)
|
if((p = current) == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -745,22 +750,23 @@ eresized(int new)
|
||||||
lockdisplay(display);
|
lockdisplay(display);
|
||||||
if((i = p->image) == nil){
|
if((i = p->image) == nil){
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if((s = p->text) == nil)
|
if((s = p->text) == nil)
|
||||||
goto Out;
|
s = "...";
|
||||||
r.min = ZP;
|
r.min = ZP;
|
||||||
r.max = stringsize(font, p->text);
|
r.max = stringsize(font, p->text);
|
||||||
if((i = allocimage(display, r, screen->chan, 0, DWhite)) == nil)
|
r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2), divpt(r.max, 2)),
|
||||||
goto Out;
|
screen->r.min));
|
||||||
string(i, r.min, display->black, ZP, font, s);
|
draw(screen, r, display->white, nil, ZP);
|
||||||
p->image = i;
|
string(screen, r.min, display->black, ZP, font, s);
|
||||||
}
|
} else {
|
||||||
r = rectaddpt(rectaddpt(Rpt(ZP, subpt(i->r.max, i->r.min)), screen->r.min), pos);
|
r = rectaddpt(rectaddpt(Rpt(ZP, subpt(i->r.max, i->r.min)), screen->r.min), pos);
|
||||||
draw(screen, r, i, nil, i->r.min);
|
draw(screen, r, i, nil, i->r.min);
|
||||||
|
}
|
||||||
gendrawdiff(screen, screen->r, r, display->white, ZP, nil, ZP, S);
|
gendrawdiff(screen, screen->r, r, display->white, ZP, nil, ZP, S);
|
||||||
border(screen, r, -Borderwidth, display->black, ZP);
|
border(screen, r, -Borderwidth, display->black, ZP);
|
||||||
flushimage(display, 1);
|
flushimage(display, 1);
|
||||||
esetcursor(nil);
|
esetcursor(nil);
|
||||||
Out:
|
|
||||||
unlockdisplay(display);
|
unlockdisplay(display);
|
||||||
qunlock(p);
|
qunlock(p);
|
||||||
}
|
}
|
||||||
|
@ -855,6 +861,35 @@ showpage(Page *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
zerox(Page *p)
|
||||||
|
{
|
||||||
|
char nam[64], *argv[4];
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if(p == nil)
|
||||||
|
return;
|
||||||
|
esetcursor(&reading);
|
||||||
|
qlock(p);
|
||||||
|
if((fd = openpage(p)) < 0)
|
||||||
|
goto Out;
|
||||||
|
if(rfork(RFREND|RFFDG|RFPROC|RFENVG|RFNOTEG|RFNOWAIT) == 0){
|
||||||
|
dup(fd, 0);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
snprint(nam, sizeof nam, "/bin/%s", argv0);
|
||||||
|
argv[0] = argv0;
|
||||||
|
argv[1] = "-w";
|
||||||
|
argv[2] = nil;
|
||||||
|
exec(nam, argv);
|
||||||
|
sysfatal("exec: %r");
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
Out:
|
||||||
|
qunlock(p);
|
||||||
|
esetcursor(nil);
|
||||||
|
}
|
||||||
|
|
||||||
void killcohort(void)
|
void killcohort(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -878,37 +913,6 @@ shortname(char *s)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
zerox(Page *p)
|
|
||||||
{
|
|
||||||
char nam[64], *argv[4];
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if(p == nil)
|
|
||||||
return;
|
|
||||||
esetcursor(&reading);
|
|
||||||
qlock(p);
|
|
||||||
if(p->open == nil || (fd = p->open(p)) < 0){
|
|
||||||
p->open = nil;
|
|
||||||
goto Out;
|
|
||||||
}
|
|
||||||
if(rfork(RFREND|RFFDG|RFPROC|RFENVG|RFNOTEG|RFNOWAIT) == 0){
|
|
||||||
dup(fd, 0);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
snprint(nam, sizeof nam, "/bin/%s", argv0);
|
|
||||||
argv[0] = argv0;
|
|
||||||
argv[1] = "-w";
|
|
||||||
argv[2] = nil;
|
|
||||||
exec(nam, argv);
|
|
||||||
sysfatal("exec: %r");
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
Out:
|
|
||||||
qunlock(p);
|
|
||||||
esetcursor(nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
@ -1056,6 +1060,7 @@ main(int argc, char *argv[])
|
||||||
switch(e.kbdc){
|
switch(e.kbdc){
|
||||||
case 'q':
|
case 'q':
|
||||||
case Kdel:
|
case Kdel:
|
||||||
|
case Keof:
|
||||||
exits(0);
|
exits(0);
|
||||||
case Kup:
|
case Kup:
|
||||||
lockdisplay(display);
|
lockdisplay(display);
|
||||||
|
@ -1073,7 +1078,7 @@ main(int argc, char *argv[])
|
||||||
case Kdown:
|
case Kdown:
|
||||||
lockdisplay(display);
|
lockdisplay(display);
|
||||||
o = addpt(pos, pagesize(current));
|
o = addpt(pos, pagesize(current));
|
||||||
if(o.y >= Dy(screen->r)){
|
if(o.y > Dy(screen->r)){
|
||||||
translate(current, Pt(0, -Dy(screen->r)/2));
|
translate(current, Pt(0, -Dy(screen->r)/2));
|
||||||
unlockdisplay(display);
|
unlockdisplay(display);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1094,6 +1099,8 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
fd = -1;
|
fd = -1;
|
||||||
s = plumblookup(pm->attr, "action");
|
s = plumblookup(pm->attr, "action");
|
||||||
|
if(s && strcmp(s, "quit")==0)
|
||||||
|
exits(0);
|
||||||
if(s && strcmp(s, "showdata")==0){
|
if(s && strcmp(s, "showdata")==0){
|
||||||
static ulong plumbid;
|
static ulong plumbid;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue