9 #include "x11-memdraw.h"
12 moveto(Mousectl *m, Point pt)
18 closemouse(Mousectl *mc)
23 /* postnote(PNPROC, mc->pid, "kill");
25 do; while(nbrecv(mc->c, &mc->m) > 0);
30 chanfree(mc->resizec);
35 readmouse(Mousectl *mc)
38 flushimage(mc->display, 1);
39 if(recv(mc->c, &mc->m) < 0){
40 fprint(2, "readmouse: %r\n");
58 threadsetname("mouseproc");
59 memset(&m, 0, sizeof m);
61 mask = MouseMask|ExposureMask|StructureNotifyMask;
62 XSelectInput(_x.mousecon, _x.drawable, mask);
63 fd = XConnectionNumber(_x.mousecon);
65 while(XPending(_x.mousecon) == False)
66 threadfdwait(fd, 'r');
67 XNextEvent(_x.mousecon, &xevent);
70 _xexpose(&xevent, _x.mousecon);
73 if(_xdestroy(&xevent, _x.mousecon)){
74 /* drain it before sending */
75 /* apps that care can notice we sent a 0 */
76 /* otherwise we'll have getwindow send SIGHUP */
77 nbrecv(mc->resizec, 0);
78 nbrecv(mc->resizec, 0);
83 if(_xconfigure(&xevent, _x.mousecon))
84 nbsend(mc->resizec, &one);
86 case SelectionRequest:
87 _xselect(&xevent, _x.mousecon);
92 if(_xtoplan9mouse(_x.mousecon, &xevent, &m) < 0)
96 * mc->Mouse is updated after send so it doesn't have wrong value if we block during send.
97 * This means that programs should receive into mc->Mouse (see readmouse() above) if
98 * they want full synchrony.
107 initmouse(char *file, Image *i)
112 mc = mallocz(sizeof(Mousectl), 1);
114 mc->display = i->display;
115 mc->c = chancreate(sizeof(Mouse), 0);
116 mc->resizec = chancreate(sizeof(int), 2);
117 threadcreate(_ioproc, mc, 16384);
122 setcursor(Mousectl *mc, Cursor *c)