9 moveto(Mousectl *m, Point pt)
11 fprint(m->mfd, "m%d %d", pt.x, pt.y);
16 closemouse(Mousectl *mc)
22 mc->mfd = mc->cfd = -1;
27 readmouse(Mousectl *mc)
30 Display *d = mc->image->display;
34 if(recv(mc->c, &mc->Mouse) < 0){
35 fprint(2, "readmouse: %r\n");
51 threadsetname("mouseproc");
52 memset(&m, 0, sizeof m);
55 n = read(mc->mfd, buf, sizeof buf);
57 yield(); /* if error is due to exiting, we'll exit here */
60 fprint(2, "mouse: bad count %d not 49: %r\n", n);
62 threadexits("read error");
69 if(send(mc->resizec, &one) < 0)
73 m.xy.x = atoi(buf+1+0*12);
74 m.xy.y = atoi(buf+1+1*12);
75 m.buttons = atoi(buf+1+2*12);
76 m.msec = atoi(buf+1+3*12);
77 if(send(mc->c, &m) < 0)
80 * mc->Mouse is updated after send so it doesn't have wrong value if we block during send.
81 * This means that programs should receive into mc->Mouse (see readmouse() above) if
82 * they want full synchrony.
90 chanfree(mc->resizec);
95 initmouse(char *file, Image *i)
100 mc = mallocz(sizeof(Mousectl), 1);
103 mc->file = strdup(file);
104 mc->mfd = open(file, ORDWR|OCEXEC);
109 t = malloc(strlen(file)+16);
116 sl = utfrrune(t, '/');
118 strcpy(sl, "/cursor");
120 strcpy(t, "/dev/cursor");
121 mc->cfd = open(t, ORDWR|OCEXEC);
124 mc->c = chancreate(sizeof(Mouse), 0);
125 mc->resizec = chancreate(sizeof(int), 2);
126 mc->pid = proccreate(_ioproc, mc, 4096);
131 setcursor(Mousectl *mc, Cursor *c)
133 char curs[2*4+2*2*16];
136 write(mc->cfd, curs, 0);
138 BPLONG(curs+0*4, c->offset.x);
139 BPLONG(curs+1*4, c->offset.y);
140 memmove(curs+2*4, c->clr, 2*2*16);
141 write(mc->cfd, curs, sizeof curs);