plan9fox/libpanel/event.c
xfnw 856abd2f7d Squashed 'sys/src/cmd/gopher/' content from commit 3680728b6
git-subtree-dir: sys/src/cmd/gopher
git-subtree-split: 3680728b631ed65201b397f4ae3e5d1b03be42f9
2022-07-01 15:46:23 -04:00

49 lines
859 B
C

#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>
#include <panel.h>
#include "pldefs.h"
void plgrabkb(Panel *g){
plkbfocus=g;
}
void plkeyboard(Rune c){
if(plkbfocus)
plkbfocus->type(plkbfocus, c);
}
/*
* Return the most leafward, highest priority panel containing p
*/
Panel *pl_ptinpanel(Point p, Panel *g){
Panel *v;
for(;g;g=g->next) if(ptinrect(p, g->r)){
v=pl_ptinpanel(p, g->child);
if(v && v->pri(v, p)>=g->pri(g, p)) return v;
return g;
}
return 0;
}
void plmouse(Panel *g, Mouse *m){
Panel *hit, *last;
if(g->flags&REMOUSE)
hit=g->lastmouse;
else{
hit=pl_ptinpanel(m->xy, g);
last=g->lastmouse;
if(last && last!=hit){
m->buttons|=OUT;
last->hit(last, m);
m->buttons&=~OUT;
}
}
if(hit){
if(hit->hit(hit, m))
g->flags|=REMOUSE;
else
g->flags&=~REMOUSE;
g->lastmouse=hit;
}
}