]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libdraw/event.c
python: arm64 support
[plan9front.git] / sys / src / libdraw / event.c
index 5f99199dd00806bd6a2891c3f94986e972e5c98c..b02bbeb28abb8f7ffb0b0d89cb4f6d6d21fc1aae 100644 (file)
@@ -45,21 +45,10 @@ Ebuf*
 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;
@@ -322,9 +311,10 @@ loop:
        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
@@ -356,39 +346,33 @@ eforkslave(ulong key)
 }
 
 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
@@ -396,17 +380,23 @@ emouse(void)
 {
        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);
@@ -423,6 +413,7 @@ ekbd(void)
                drawerror(display, "events: keyboard not initialzed");
        eb = ebread(&eslave[Skeyboard]);
        chartorune(&r, (char*)eb->buf);
+       free(eb);
        return r;
 }
 
@@ -470,7 +461,7 @@ int
 eatomouse(Mouse *m, char *buf, int n)
 {
        if(n != 1+4*12){
-               werrstr("atomouse: bad count");
+               werrstr("eatomouse: bad count");
                return -1;
        }
 
@@ -479,6 +470,6 @@ eatomouse(Mouse *m, char *buf, int n)
        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;
 }