+void
+mousereport(XEvent *e) {
+ int x = X2COL(e->xbutton.x);
+ int y = Y2ROW(e->xbutton.y);
+ int button = e->xbutton.button;
+ int state = e->xbutton.state;
+ char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 };
+
+ if(!IS_SET(MODE_MOUSE))
+ return;
+
+ /* from urxvt */
+ if(e->xbutton.type == ButtonRelease || button == AnyButton)
+ button = 3;
+ else {
+ button -= Button1;
+ if(button >= 3)
+ button += 64 - 3;
+ }
+
+ buf[3] = 32 + button + (state & ShiftMask ? 4 : 0)
+ + (state & Mod4Mask ? 8 : 0)
+ + (state & ControlMask ? 16 : 0);
+
+ ttywrite(buf, sizeof(buf));
+}
+