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");
50 memset(&m, 0, sizeof m);
53 n = read(mc->mfd, buf, sizeof buf);
58 if(send(mc->resizec, &one) < 0)
62 m.xy.x = atoi(buf+1+0*12);
63 m.xy.y = atoi(buf+1+1*12);
64 m.buttons = atoi(buf+1+2*12);
65 m.msec = atoi(buf+1+3*12);
66 if(send(mc->c, &m) < 0)
69 * mc->Mouse is updated after send so it doesn't have wrong value if we block during send.
70 * This means that programs should receive into mc->Mouse (see readmouse() above) if
71 * they want full synchrony.
79 chanfree(mc->resizec);
84 initmouse(char *file, Image *i)
89 mc = mallocz(sizeof(Mousectl), 1);
92 mc->file = strdup(file);
93 mc->mfd = open(file, ORDWR|OCEXEC);
94 if(mc->mfd<0 && strcmp(file, "/dev/mouse")==0){
95 bind("#m", "/dev", MAFTER);
96 mc->mfd = open(file, ORDWR|OCEXEC);
102 t = malloc(strlen(file)+16);
109 sl = utfrrune(t, '/');
111 strcpy(sl, "/cursor");
113 strcpy(t, "/dev/cursor");
114 mc->cfd = open(t, ORDWR|OCEXEC);
117 mc->c = chancreate(sizeof(Mouse), 0);
118 mc->resizec = chancreate(sizeof(int), 2);
119 mc->pid = proccreate(_ioproc, mc, 4096);
124 setcursor(Mousectl *mc, Cursor *c)
126 char curs[2*4+2*2*16];
129 write(mc->cfd, curs, 0);
131 BPLONG(curs+0*4, c->offset.x);
132 BPLONG(curs+1*4, c->offset.y);
133 memmove(curs+2*4, c->clr, 2*2*16);
134 write(mc->cfd, curs, sizeof curs);