+ if (sp->_mouse_bstate & BUTTON_PRESSED) {
+ int b;
+
+ eventp->bstate = BUTTON_RELEASED;
+ for (b = 1; b <= MAX_BUTTONS; ++b) {
+ if (!(sp->_mouse_bstate & MASK_PRESS(b)))
+ eventp->bstate &= ~MASK_RELEASE(b);
+ }
+ sp->_mouse_bstate = 0;
+ } else {
+ /*
+ * xterm will return a stream of release-events to let the
+ * application know where the mouse is going, if private mode
+ * 1002 or 1003 is enabled.
+ */
+ eventp->bstate = REPORT_MOUSE_POSITION;
+ }
+ }
+
+ if (intro & 4) {
+ eventp->bstate |= BUTTON_SHIFT;
+ }
+ if (intro & 8) {
+ eventp->bstate |= BUTTON_ALT;
+ }
+ if (intro & 16) {
+ eventp->bstate |= BUTTON_CTRL;
+ }
+ result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE;
+ return result;
+}
+
+/* This code requires that your xterm entry contain the kmous capability and
+ * that it be set to the \E[M documented in the Xterm Control Sequences
+ * reference. This is how we arrange for mouse events to be reported via a
+ * KEY_MOUSE return value from wgetch(). After this value is received,
+ * _nc_mouse_inline() gets called and is immediately responsible for parsing
+ * the mouse status information following the prefix.
+ *
+ * The following quotes from the ctlseqs.ms document in the XTerm distribution,
+ * describing the mouse tracking feature:
+ *
+ * Parameters for all mouse tracking escape sequences generated by xterm encode
+ * numeric parameters in a single character as value+040. For example, ! is
+ * 1.
+ *
+ * On button press or release, xterm sends ESC [ M CbCxCy. The low two bits of
+ * Cb encode button information: 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed,
+ * 3=release. The upper bits encode what modifiers were down when the button
+ * was pressed and are added together. 4=Shift, 8=Meta, 16=Control. Cx and Cy
+ * are the x and y coordinates of the mouse event. The upper left corner is
+ * (1,1).
+ *
+ * (End quote) By the time we get here, we've eaten the key prefix. FYI, the
+ * loop below is necessary because mouse click info isn't guaranteed to present
+ * as a single clist item.
+ *
+ * Wheel mice may return buttons 4 and 5 when the wheel is turned. We encode
+ * those as button presses.
+ */
+static bool
+decode_xterm_X10(SCREEN *sp, MEVENT * eventp)
+{
+#define MAX_KBUF 3
+ unsigned char kbuf[MAX_KBUF + 1];
+ size_t grabbed;
+ int res;
+ bool result;