]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libdraw/event.c
python: arm64 support
[plan9front.git] / sys / src / libdraw / event.c
index 1cf223c36dd50d0c67bbaf057e2e94bb38382c75..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;
@@ -199,7 +188,7 @@ static void
 ekeyslave(int fd)
 {
        Rune r;
-       char t[3], k[10];
+       char t[1+UTFmax], k[10];
        int kr, kn, w;
 
        if(eforkslave(Ekeyboard) < MAXSLAVE)
@@ -215,10 +204,9 @@ ekeyslave(int fd)
                }
                w = chartorune(&r, k);
                kn -= w;
+               memmove(t+1, k, w);
                memmove(k, &k[w], kn);
-               t[1] = r;
-               t[2] = r>>8;
-               if(write(epipe[1], t, 3) != 3)
+               if(write(epipe[1], t, sizeof(t)) != sizeof(t))
                        break;
        }
 breakout:;
@@ -302,7 +290,7 @@ loop:
                s->head = (Ebuf *)1;
                return;
        }
-       if(i == Skeyboard && n != 3)
+       if(i == Skeyboard && n != (1+UTFmax))
                drawerror(display, "events: protocol error: keyboard");
        if(i == Smouse){
                if(n < 1+1+2*12)
@@ -323,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
@@ -357,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
@@ -397,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);
@@ -418,14 +407,14 @@ int
 ekbd(void)
 {
        Ebuf *eb;
-       int c;
+       Rune r;
 
        if(Skeyboard < 0)
                drawerror(display, "events: keyboard not initialzed");
        eb = ebread(&eslave[Skeyboard]);
-       c = eb->buf[0] + (eb->buf[1]<<8);
+       chartorune(&r, (char*)eb->buf);
        free(eb);
-       return c;
+       return r;
 }
 
 void
@@ -472,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;
        }
 
@@ -481,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;
 }