ebread(Slave *s)
{
Ebuf *eb;
- Dir *d;
- ulong l;
-
- for(;;){
- d = dirfstat(epipe[0]);
- if(d == nil)
- drawerror(display, "events: eread stat error");
- l = d->length;
- free(d);
- if(s->head && l==0)
- break;
+
+ while((eb = s->head) == 0)
extract();
- }
- eb = s->head;
- s->head = s->head->next;
+ s->head = eb->next;
if(s->head == 0)
s->tail = 0;
return eb;
memmove(eb->buf, &ebuf[1], n - 1);
eb->next = 0;
if(s->head)
- s->tail = s->tail->next = eb;
+ s->tail->next = eb;
else
- s->head = s->tail = eb;
+ s->head = eb;
+ s->tail = eb;
}
static int
}
static int
-enote(void *v, char *s)
+enote(void*, char *s)
{
- char t[1];
int i, pid;
- USED(v, s);
- pid = getpid();
- if(pid != parentpid){
- for(i=0; i<nslave; i++){
- if(pid == eslave[i].pid){
- t[0] = MAXSLAVE;
- write(epipe[1], t, 1);
- break;
- }
- }
+ if(strncmp(s, "sys:", 4) == 0 || strcmp(s, "alarm") == 0)
return 0;
- }
- close(epipe[0]);
- epipe[0] = -1;
- close(epipe[1]);
- epipe[1] = -1;
- for(i=0; i<nslave; i++){
+ pid = getpid();
+ for(i=0; i<nslave; i++)
if(pid == eslave[i].pid)
- continue; /* don't kill myself */
- postnote(PNPROC, eslave[i].pid, "die");
- }
- return 0;
+ return 1;
+ if(pid != parentpid)
+ return 0;
+ exits("killed");
+ return 1;
}
static void
ekill(void)
{
- enote(0, 0);
+ int i, pid;
+
+ pid = getpid();
+ for(i=0; i<nslave; i++){
+ if(eslave[i].pid == 0 || pid == eslave[i].pid)
+ continue; /* don't kill myself */
+ postnote(PNPROC, eslave[i].pid, "die");
+ }
}
Mouse
{
Mouse m;
Ebuf *eb;
- static but[2];
+ static int lastb;
int b;
if(Smouse < 0)
drawerror(display, "events: mouse not initialized");
- eb = ebread(&eslave[Smouse]);
+ for(;;){
+ eb = ebread(&eslave[Smouse]);
+ b = atoi((char*)eb->buf+1+2*12);
+ if(b != lastb || !ecanmouse())
+ break;
+ free(eb); /* drop queued mouse events */
+ }
+ lastb = b;
+ m.buttons = b;
m.xy.x = atoi((char*)eb->buf+1+0*12);
m.xy.y = atoi((char*)eb->buf+1+1*12);
- b = atoi((char*)eb->buf+1+2*12);
- m.buttons = b;
- m.msec = atoi((char*)eb->buf+1+3*12);
+ m.msec = (ulong)atoll((char*)eb->buf+1+3*12);
if (logfid)
fprint(logfid, "b: %d xy: %P\n", m.buttons, m.xy);
free(eb);
drawerror(display, "events: keyboard not initialzed");
eb = ebread(&eslave[Skeyboard]);
chartorune(&r, (char*)eb->buf);
+ free(eb);
return r;
}
eatomouse(Mouse *m, char *buf, int n)
{
if(n != 1+4*12){
- werrstr("atomouse: bad count");
+ werrstr("eatomouse: bad count");
return -1;
}
m->xy.x = atoi(buf+1+0*12);
m->xy.y = atoi(buf+1+1*12);
m->buttons = atoi(buf+1+2*12);
- m->msec = atoi(buf+1+3*12);
+ m->msec = (ulong)atoll(buf+1+3*12);
return n;
}