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 flushimage(mc->image->display, 1);
31 if(recv(mc->c, &mc->Mouse) < 0){
32 fprint(2, "readmouse: %r\n");
48 threadsetname("mouseproc");
49 memset(&m, 0, sizeof m);
52 n = read(mc->mfd, buf, sizeof buf);
54 yield(); /* if error is due to exiting, we'll exit here */
57 fprint(2, "mouse: bad count %d not 49: %r\n", n);
59 threadexits("read error");
66 if(send(mc->resizec, &one) < 0)
70 m.xy.x = atoi(buf+1+0*12);
71 m.xy.y = atoi(buf+1+1*12);
72 m.buttons = atoi(buf+1+2*12);
73 m.msec = atoi(buf+1+3*12);
74 if(send(mc->c, &m) < 0)
77 * mc->Mouse is updated after send so it doesn't have wrong value if we block during send.
78 * This means that programs should receive into mc->Mouse (see readmouse() above) if
79 * they want full synchrony.
87 chanfree(mc->resizec);
92 initmouse(char *file, Image *i)
97 mc = mallocz(sizeof(Mousectl), 1);
100 mc->file = strdup(file);
101 mc->mfd = open(file, ORDWR|OCEXEC);
102 if(mc->mfd<0 && strcmp(file, "/dev/mouse")==0){
103 bind("#m", "/dev", MAFTER);
104 mc->mfd = open(file, ORDWR|OCEXEC);
110 t = malloc(strlen(file)+16);
117 sl = utfrrune(t, '/');
119 strcpy(sl, "/cursor");
121 strcpy(t, "/dev/cursor");
122 mc->cfd = open(t, ORDWR|OCEXEC);
125 mc->c = chancreate(sizeof(Mouse), 0);
126 mc->resizec = chancreate(sizeof(int), 2);
127 mc->pid = proccreate(_ioproc, mc, 4096);
132 setcursor(Mousectl *mc, Cursor *c)
134 char curs[2*4+2*2*16];
137 write(mc->cfd, curs, 0);
139 BPLONG(curs+0*4, c->offset.x);
140 BPLONG(curs+1*4, c->offset.y);
141 memmove(curs+2*4, c->clr, 2*2*16);
142 write(mc->cfd, curs, sizeof curs);