9 moveto(Mousectl *m, Point pt)
11 fprint(m->mfd, "m%d %d", pt.x, pt.y);
16 closemouse(Mousectl *mc)
21 postnote(PNPROC, mc->pid, "kill");
23 do; while(nbrecv(mc->c, &mc->Mouse) > 0);
34 readmouse(Mousectl *mc)
37 flushimage(mc->image->display, 1);
38 if(recv(mc->c, &mc->Mouse) < 0){
39 fprint(2, "readmouse: %r\n");
55 threadsetname("mouseproc");
57 memset(&m, 0, sizeof m);
61 n = read(mc->mfd, buf, sizeof buf);
63 yield(); /* if error is due to exiting, we'll exit here */
64 fprint(2, "mouse: bad count %d not 49: %r\n", n);
66 threadexits("read error");
72 send(mc->resizec, &one);
75 m.xy.x = atoi(buf+1+0*12);
76 m.xy.y = atoi(buf+1+1*12);
77 m.buttons = atoi(buf+1+2*12);
78 m.msec = atoi(buf+1+3*12);
81 * mc->Mouse is updated after send so it doesn't have wrong value if we block during send.
82 * This means that programs should receive into mc->Mouse (see readmouse() above) if
83 * they want full synchrony.
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);
112 sl = utfrrune(t, '/');
114 strcpy(sl, "/cursor");
116 strcpy(t, "/dev/cursor");
117 mc->cfd = open(t, ORDWR|OCEXEC);
120 mc->c = chancreate(sizeof(Mouse), 0);
121 chansetname(mc->c, "mousec");
122 mc->resizec = chancreate(sizeof(int), 2);
123 chansetname(mc->resizec, "resizec");
124 proccreate(_ioproc, mc, 4096);
129 setcursor(Mousectl *mc, Cursor *c)
131 char curs[2*4+2*2*16];
134 write(mc->cfd, curs, 0);
136 BPLONG(curs+0*4, c->offset.x);
137 BPLONG(curs+1*4, c->offset.y);
138 memmove(curs+2*4, c->clr, 2*2*16);
139 write(mc->cfd, curs, sizeof curs);