mothra: mothmode cleanup

This commit is contained in:
cinap_lenrek 2011-10-02 14:27:03 +02:00
parent 2036c49394
commit b86a38ed13
2 changed files with 44 additions and 52 deletions

View file

@ -238,6 +238,16 @@ int mkmfile(char *stem, int mode){
f=create(stem, OWRITE, mode); f=create(stem, OWRITE, mode);
return f; return f;
} }
void donecurs(void){
if(current == nil)
return;
if(mothmode)
esetcursor(&mothcurs);
else
esetcursor(current->alldone ? 0 : &readingcurs);
}
void main(int argc, char *argv[]){ void main(int argc, char *argv[]){
Event e; Event e;
enum { Eplumb = 128 }; enum { Eplumb = 128 };
@ -327,8 +337,7 @@ void main(int argc, char *argv[]){
current->changed=0; current->changed=0;
current->alldone=1; current->alldone=1;
message(mothra); message(mothra);
if(mothmode==0) donecurs();
esetcursor(0);
} }
else if(current->changed){ else if(current->changed){
updtext(current); updtext(current);
@ -369,11 +378,6 @@ void main(int argc, char *argv[]){
break; break;
case Emouse: case Emouse:
mouse=e.mouse; mouse=e.mouse;
if(mouse.buttons > 1){
mothmode = 0;
esetcursor(current && current->alldone?0:&readingcurs);
message(mothra);
}
plmouse(root, e.mouse); plmouse(root, e.mouse);
break; break;
case Eplumb: case Eplumb:
@ -457,13 +461,6 @@ char *genwww(Panel *, int index){
return buf; return buf;
} }
void donecurs(void){
if(mothmode)
esetcursor(current && current->alldone?0:&mothcurs);
else
esetcursor(current && current->alldone?0:&readingcurs);
}
/* /*
* selected text should be a url. * selected text should be a url.
* get the document, scroll to the given tag * get the document, scroll to the given tag
@ -661,47 +658,42 @@ void doprev(Panel *p, int buttons, int index){
* convert a url into a local file name. * convert a url into a local file name.
*/ */
char *urltofile(char *url){ char *urltofile(char *url){
static char file[128]; char *slash;
if(strrchr(url, '/')){ if(slash = strrchr(url, '/'))
snprint(file, sizeof(file), "%s", strrchr(url, '/')+1); url = slash+1;
if(file[0]==0) if(url[0] == 0)
strcpy(file, "index"); return "index";
}else return url;
snprint(file, sizeof(file), "%s", url);
return file;
} }
/* /*
* Follow an html link * Follow an html link
*/ */
void dolink(Panel *p, int buttons, Rtext *word){ void dolink(Panel *p, int buttons, Rtext *word){
char file[128], mapurl[NNAME]; char *file, mapurl[NNAME];
Point coord;
int yoffs;
Action *a; Action *a;
Url u; Url u;
Point coord;
int fd, yoffs;
USED(p);
a=word->user; a=word->user;
if(mothmode && a){ if(a == nil || a->image == nil && a->link == nil)
if(a->image){ return;
seturl(&u, a->image, current->url->fullname); if(mothmode){
snprint(file, sizeof(file), "%s", urltofile(a->image)); seturl(&u, a->image ? a->image : a->link, current->url->fullname);
}else{ save(&u, file=urltofile(u.reltext));
seturl(&u, a->link, current->url->fullname);
snprint(file, sizeof(file), "%s", urltofile(a->link));
}
save(&u, file);
message("saved %s", file); message("saved %s", file);
esetcursor(&mothcurs); return;
}else if(a && a->link){
if(a->ismap){
yoffs=plgetpostextview(p);
coord=subpt(subpt(mouse.xy, word->r.min), p->r.min);
snprint(mapurl, sizeof(mapurl), "%s?%d,%d", a->link, coord.x, coord.y+yoffs);
hiturl(buttons, mapurl, 1);
}else
hiturl(buttons, a->link, 0);
} }
if(a->ismap){
yoffs=plgetpostextview(p);
coord=subpt(subpt(mouse.xy, word->r.min), p->r.min);
snprint(mapurl, sizeof(mapurl), "%s?%d,%d", a->link, coord.x, coord.y+yoffs);
hiturl(buttons, mapurl, 1);
}else
hiturl(buttons, a->link ? a->link : a->image, 0);
} }
void filter(char *cmd, int fd){ void filter(char *cmd, int fd){
flushimage(display, 1); flushimage(display, 1);
switch(rfork(RFFDG|RFPROC|RFNOWAIT)){ switch(rfork(RFFDG|RFPROC|RFNOWAIT)){
@ -1116,9 +1108,11 @@ void hit3(int button, int item){
pldraw(root, screen); pldraw(root, screen);
break; break;
case 1: case 1:
mothmode = 1; if(mothmode = !mothmode)
message("moth mode"); message("moth mode!");
esetcursor(&mothcurs); else
message(mothra);
donecurs();
break; break;
case 2: case 2:
snarf(cmd); snarf(cmd);

View file

@ -147,7 +147,8 @@ void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){
space=1000000; space=1000000;
} }
} }
plrtstr(&g->dst->text, space, indent, f->font, strdup(s), g->state->link[0]!=0, ap); plrtstr(&g->dst->text, space, indent, f->font, strdup(s),
g->state->link[0] || g->state->image[0], ap);
g->para=0; g->para=0;
g->linebrk=0; g->linebrk=0;
g->dst->changed=1; g->dst->changed=1;
@ -639,11 +640,8 @@ void plrdhtml(char *name, int fd, Www *dst){
case Tag_meta: case Tag_meta:
break; break;
case Tag_img: case Tag_img:
if(str=pl_getattr(g.attr, "src")){ if(str=pl_getattr(g.attr, "src"))
strncpy(g.state->image, str, sizeof(g.state->image)); strncpy(g.state->image, str, sizeof(g.state->image));
if(g.state->link[0]==0)
strncpy(g.state->link, str, sizeof(g.state->link));
}
g.state->ismap=pl_hasattr(g.attr, "ismap"); g.state->ismap=pl_hasattr(g.attr, "ismap");
if(str=pl_getattr(g.attr, "width")) if(str=pl_getattr(g.attr, "width"))
g.state->width = strtolength(&g, HORIZ, str); g.state->width = strtolength(&g, HORIZ, str);