9 #include "x11-memdraw.h"
11 int _windowhasfocus = 1;
12 int _wantfocuschanges;
15 moveto(Mousectl *m, Point pt)
21 closemouse(Mousectl *mc)
26 /* postnote(PNPROC, mc->pid, "kill");
28 do; while(nbrecv(mc->c, &mc->m) > 0);
33 chanfree(mc->resizec);
38 readmouse(Mousectl *mc)
41 flushimage(mc->display, 1);
42 if(recv(mc->c, &mc->m) < 0){
43 fprint(2, "readmouse: %r\n");
62 threadsetname("mouseproc");
63 memset(&m, 0, sizeof m);
65 mask = MouseMask|ExposureMask|StructureNotifyMask;
66 XSelectInput(_x.mousecon, _x.drawable, mask);
67 fd = XConnectionNumber(_x.mousecon);
70 XNextEvent(_x.mousecon, &xevent);
73 _xexpose(&xevent, _x.mousecon);
76 if(_xdestroy(&xevent, _x.mousecon)){
77 /* drain it before sending */
78 /* apps that care can notice we sent a 0 */
79 /* otherwise we'll have getwindow send SIGHUP */
80 nbrecv(mc->resizec, 0);
81 nbrecv(mc->resizec, 0);
86 if(_xconfigure(&xevent, _x.mousecon))
87 nbsend(mc->resizec, &one);
89 case SelectionRequest:
90 _xselect(&xevent, _x.mousecon);
95 /* If the motion notifications are backing up, skip over some. */
96 if(0 && xevent.type == MotionNotify){
97 while(XCheckWindowEvent(_x.mousecon, _x.drawable, MouseMask, &xevent)){
98 if(xevent.type != MotionNotify)
103 if(_xtoplan9mouse(_x.mousecon, &xevent, &m) < 0)
108 * mc->Mouse is updated after send so it doesn't have wrong value if we block during send.
109 * This means that programs should receive into mc->Mouse (see readmouse() above) if
110 * they want full synchrony.
115 if(xevent.xclient.message_type == _x.wmprotos){
116 a = xevent.xclient.data.l[0];
117 if(_wantfocuschanges && a == _x.takefocus){
119 _x.newscreenr = _x.screenr;
120 nbsend(mc->resizec, &one);
121 }else if(_wantfocuschanges && a == _x.losefocus){
123 _x.newscreenr = _x.screenr;
124 nbsend(mc->resizec, &one);
133 initmouse(char *file, Image *i)
137 mc = mallocz(sizeof(Mousectl), 1);
139 mc->display = i->display;
140 mc->c = chancreate(sizeof(Mouse), 0);
141 chansetname(mc->c, "mousec");
142 mc->resizec = chancreate(sizeof(int), 2);
143 chansetname(mc->resizec, "resizec");
144 proccreate(_ioproc, mc, 32768);
149 setcursor(Mousectl *mc, Cursor *c)
155 * Send the mouse event back to the window manager.
156 * So that 9term can tell rio to pop up its button3 menu.
157 * Note that we're using _x.mousecon in a few places,
158 * so we have to be sure that the mouse proc isn't using it
159 * when we call! This is all a bit wonky and should be
160 * avoided unless you know what you're doing.
163 bouncemouse(Mouse *m)
168 e.type = ButtonPress;
173 else if(m->buttons&2)
175 else if(m->buttons&4)
178 XTranslateCoordinates(_x.display, _x.drawable,
179 DefaultRootWindow(_x.display),
180 m->xy.x, m->xy.y, &e.x_root, &e.y_root, &dw);
181 e.root = DefaultRootWindow(_x.mousecon);
187 e.time = CurrentTime;
188 XUngrabPointer(_x.mousecon, m->msec);
189 XSendEvent(_x.mousecon, e.root, True, ButtonPressMask, (XEvent*)&e);