mothra: allow plmouse() to update mouse state, use a pipe to signal screen update

This commit is contained in:
cinap_lenrek 2012-01-01 16:59:42 +01:00
parent d09c46c352
commit 31109f5047
9 changed files with 34 additions and 20 deletions

View file

@ -35,7 +35,7 @@ void getimage(Rtext *t, Www *w){
for(p=w->pix;p!=nil; p=p->next) for(p=w->pix;p!=nil; p=p->next)
if(strcmp(ap->image, p->name)==0 && ap->width==p->width && ap->height==p->height){ if(strcmp(ap->image, p->name)==0 && ap->width==p->width && ap->height==p->height){
t->b = p->b; t->b = p->b;
w->changed=1; update(w);
return; return;
} }
fd=urlopen(&url, GET, 0); fd=urlopen(&url, GET, 0);
@ -44,7 +44,7 @@ void getimage(Rtext *t, Www *w){
snprint(err, sizeof(err), "[%s: %r]", url.fullname); snprint(err, sizeof(err), "[%s: %r]", url.fullname);
free(t->text); free(t->text);
t->text=strdup(err); t->text=strdup(err);
w->changed=1; update(w);
close(fd); close(fd);
return; return;
} }
@ -82,7 +82,7 @@ void getimage(Rtext *t, Www *w){
p->next=w->pix; p->next=w->pix;
w->pix=p; w->pix=p;
t->b=b; t->b=b;
w->changed=1; update(w);
} }
void getpix(Rtext *t, Www *w){ void getpix(Rtext *t, Www *w){

View file

@ -26,21 +26,21 @@ Panel *pl_ptinpanel(Point p, Panel *g){
} }
return 0; return 0;
} }
void plmouse(Panel *g, Mouse mouse){ void plmouse(Panel *g, Mouse *m){
Panel *hit, *last; Panel *hit, *last;
if(g->flags&REMOUSE) if(g->flags&REMOUSE)
hit=g->lastmouse; hit=g->lastmouse;
else{ else{
hit=pl_ptinpanel(mouse.xy, g); hit=pl_ptinpanel(m->xy, g);
last=g->lastmouse; last=g->lastmouse;
if(last && last!=hit){ if(last && last!=hit){
mouse.buttons|=OUT; m->buttons|=OUT;
last->hit(last, &mouse); last->hit(last, m);
mouse.buttons&=~OUT; m->buttons&=~OUT;
} }
} }
if(hit){ if(hit){
if(hit->hit(hit, &mouse)) if(hit->hit(hit, m))
g->flags|=REMOUSE; g->flags|=REMOUSE;
else else
g->flags&=~REMOUSE; g->flags&=~REMOUSE;

View file

@ -104,7 +104,7 @@ void pldraw(Panel *, Image *); /* display the panel on the bitmap */
void plfree(Panel *); /* give back space */ void plfree(Panel *); /* give back space */
void plgrabkb(Panel *); /* this Panel should receive keyboard events */ void plgrabkb(Panel *); /* this Panel should receive keyboard events */
void plkeyboard(Rune); /* send a keyboard event to the appropriate Panel */ void plkeyboard(Rune); /* send a keyboard event to the appropriate Panel */
void plmouse(Panel *, Mouse); /* send a Mouse event to a Panel tree */ void plmouse(Panel *, Mouse *); /* send a Mouse event to a Panel tree */
void plscroll(Panel *, Panel *, Panel *); /* link up scroll bars */ void plscroll(Panel *, Panel *, Panel *); /* link up scroll bars */
char *plentryval(Panel *); /* entry delivers its value */ char *plentryval(Panel *); /* entry delivers its value */
void plsetbutton(Panel *, int); /* set or clear the mark on a button */ void plsetbutton(Panel *, int); /* set or clear the mark on a button */

View file

@ -74,7 +74,7 @@ int pl_hitpopup(Panel *g, Mouse *m){
g->state=UP; g->state=UP;
} }
} }
plmouse(p, *m); plmouse(p, m);
return (m->buttons&7)!=0; return (m->buttons&7)!=0;
} }
void pl_typepopup(Panel *g, Rune c){ void pl_typepopup(Panel *g, Rune c){

View file

@ -96,7 +96,7 @@ int pl_hitpulldown(Panel *g, Mouse *m){
} }
} }
if(g->state!=oldstate) pldraw(g, g->b); if(g->state!=oldstate) pldraw(g, g->b);
if(hitme) plmouse(hitme, *m); if(hitme) plmouse(hitme, m);
return g->state==DOWN; return g->state==DOWN;
} }
void pl_typepulldown(Panel *p, Rune c){ void pl_typepulldown(Panel *p, Rune c){

View file

@ -103,7 +103,7 @@ void pl_drawtextview(Panel *p){
* If t is a panel word, pass the mouse event on to it * If t is a panel word, pass the mouse event on to it
*/ */
void pl_passon(Rtext *t, Mouse *m){ void pl_passon(Rtext *t, Mouse *m){
if(t && t->b==0 && t->p!=0) plmouse(t->p, *m); if(t && t->b==0 && t->p!=0) plmouse(t->p, m);
} }
int pl_hittextview(Panel *p, Mouse *m){ int pl_hittextview(Panel *p, Mouse *m){
Rtext *oldhitword; Rtext *oldhitword;

View file

@ -90,6 +90,8 @@ Www *current=0;
Url *selection=0; Url *selection=0;
int logfile; int logfile;
int mothmode; int mothmode;
int kickpipe[2];
void docmd(Panel *, char *); void docmd(Panel *, char *);
void doprev(Panel *, int, int); void doprev(Panel *, int, int);
char *urlstr(Url *); char *urlstr(Url *);
@ -310,7 +312,9 @@ void main(int argc, char *argv[]){
pltabsize(chrwidth, 8*chrwidth); pltabsize(chrwidth, 8*chrwidth);
einit(Emouse|Ekeyboard); einit(Emouse|Ekeyboard);
eplumb(Eplumb, "web"); eplumb(Eplumb, "web");
etimer(0, 1000); if(pipe(kickpipe) < 0)
sysfatal("pipe: %r");
estart(0, kickpipe[0], 256);
plinit(screen->depth); plinit(screen->depth);
if(debug) notify(dienow); if(debug) notify(dienow);
getfonts(); getfonts();
@ -394,7 +398,7 @@ void main(int argc, char *argv[]){
break; break;
case Emouse: case Emouse:
mouse=e.mouse; mouse=e.mouse;
plmouse(root, e.mouse); plmouse(root, &mouse);
break; break;
case Eplumb: case Eplumb:
pm=e.v; pm=e.v;
@ -1084,6 +1088,14 @@ void updtext(Www *w){
plsetpostextview(text, w->yoffs); plsetpostextview(text, w->yoffs);
pldraw(root, screen); pldraw(root, screen);
} }
void update(Www *w){
w->changed = 1;
write(kickpipe[1], "C", 1);
}
void finish(Www *w){
w->finished = 1;
write(kickpipe[1], "F", 1);
}
void void
mothon(Www *w, int on) mothon(Www *w, int on)

View file

@ -78,6 +78,8 @@ enum{
POST, POST,
}; };
void update(Www *w);
void finish(Www *w);
void plrdhtml(char *, int, Www *); void plrdhtml(char *, int, Www *);
void plrdplain(char *, int, Www *); void plrdplain(char *, int, Www *);
void htmlerror(char *, int, char *, ...); /* user-supplied routine */ void htmlerror(char *, int, char *, ...); /* user-supplied routine */

View file

@ -100,7 +100,7 @@ void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){
if(g->tp!=g->text && g->tp!=g->etext && g->tp[-1]!=' ') if(g->tp!=g->text && g->tp!=g->etext && g->tp[-1]!=' ')
*g->tp++=' '; *g->tp++=' ';
while(g->tp!=g->etext && *s) *g->tp++=*s++; while(g->tp!=g->etext && *s) *g->tp++=*s++;
if(g->state->tag==Tag_title) g->dst->changed=1; if(g->state->tag==Tag_title) update(g->dst);
*g->tp='\0'; *g->tp='\0';
} }
return; return;
@ -151,7 +151,7 @@ void pl_htmloutput(Hglob *g, int nsp, char *s, Field *field){
g->state->link[0] || g->state->image[0], ap); 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; update(g->dst);
} }
/* /*
@ -588,7 +588,7 @@ void plrdplain(char *name, int fd, Www *dst){
g.form=0; g.form=0;
strncpy(g.text, name, NTITLE); strncpy(g.text, name, NTITLE);
plaintext(&g); plaintext(&g);
dst->finished=1; finish(dst);
} }
void plrdhtml(char *name, int fd, Www *dst){ void plrdhtml(char *name, int fd, Www *dst){
Stack *sp; Stack *sp;
@ -1049,9 +1049,9 @@ void plrdhtml(char *name, int fd, Www *dst){
htmlerror(g.name, g.lineno, htmlerror(g.name, g.lineno,
"missing </%s> at EOF", tag[g.state->tag].name); "missing </%s> at EOF", tag[g.state->tag].name);
*g.tp='\0'; *g.tp='\0';
dst->changed=1; update(dst);
getpix(dst->text, dst); getpix(dst->text, dst);
dst->finished=1; finish(dst);
return; return;
} }
} }