+ DosExit(EXIT_THREAD, 0L);
+}
+
+#endif /* USE_EMX_MOUSE */
+
+#if USE_SYSMOUSE
+static void
+sysmouse_server(SCREEN *sp)
+{
+ struct mouse_info the_mouse;
+ MEVENT *work;
+
+ the_mouse.operation = MOUSE_GETINFO;
+ if (sp != 0
+ && sp->_mouse_fd >= 0
+ && sp->_sysmouse_tail < FIFO_SIZE
+ && ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
+
+ if (sp->_sysmouse_head > sp->_sysmouse_tail) {
+ sp->_sysmouse_tail = 0;
+ sp->_sysmouse_head = 0;
+ }
+ work = &(sp->_sysmouse_fifo[sp->_sysmouse_tail]);
+ memset(work, 0, sizeof(*work));
+ work->id = NORMAL_EVENT; /* there's only one mouse... */
+
+ sp->_sysmouse_old_buttons = sp->_sysmouse_new_buttons;
+ sp->_sysmouse_new_buttons = the_mouse.u.data.buttons & 0x7;
+
+ if (sp->_sysmouse_new_buttons) {
+ if (sp->_sysmouse_new_buttons & 1)
+ work->bstate |= BUTTON1_PRESSED;
+ if (sp->_sysmouse_new_buttons & 2)
+ work->bstate |= BUTTON2_PRESSED;
+ if (sp->_sysmouse_new_buttons & 4)
+ work->bstate |= BUTTON3_PRESSED;
+ } else {
+ if (sp->_sysmouse_old_buttons & 1)
+ work->bstate |= BUTTON1_RELEASED;
+ if (sp->_sysmouse_old_buttons & 2)
+ work->bstate |= BUTTON2_RELEASED;
+ if (sp->_sysmouse_old_buttons & 4)
+ work->bstate |= BUTTON3_RELEASED;
+ }
+
+ /* for cosmetic bug in syscons.c on FreeBSD 3.[34] */
+ the_mouse.operation = MOUSE_HIDE;
+ ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+ the_mouse.operation = MOUSE_SHOW;
+ ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+
+ /*
+ * We're only interested if the button is pressed or released.
+ * FIXME: implement continuous event-tracking.
+ */
+ if (sp->_sysmouse_new_buttons != sp->_sysmouse_old_buttons) {
+ sp->_sysmouse_tail += 1;
+ }
+ work->x = the_mouse.u.data.x / sp->_sysmouse_char_width;
+ work->y = the_mouse.u.data.y / sp->_sysmouse_char_height;
+ }
+}
+
+static void
+handle_sysmouse(int sig GCC_UNUSED)
+{
+ sysmouse_server(CURRENT_SCREEN);
+}
+#endif /* USE_SYSMOUSE */
+
+#ifndef USE_TERM_DRIVER
+#define xterm_kmous "\033[M"
+
+static void
+init_xterm_mouse(SCREEN *sp)
+{
+ sp->_mouse_type = M_XTERM;
+ sp->_mouse_format = MF_X10;
+ sp->_mouse_xtermcap = tigetstr("XM");
+ if (VALID_STRING(sp->_mouse_xtermcap)) {
+ char *code = strstr(sp->_mouse_xtermcap, "[?");
+ if (code != 0) {
+ code += 2;
+ while ((*code >= '0') && (*code <= '9')) {
+ char *next = code;
+ while ((*next >= '0') && (*next <= '9')) {
+ ++next;
+ }
+ if (!strncmp(code, "1006", (size_t) (next - code))) {
+ sp->_mouse_format = MF_SGR1006;
+ }
+#ifdef EXP_XTERM_1005
+ if (!strncmp(code, "1005", (size_t) (next - code))) {
+ sp->_mouse_format = MF_XTERM_1005;
+ }
+#endif
+ if (*next == ';') {
+ while (*next == ';') {
+ ++next;
+ }
+ code = next;
+ } else {
+ break;
+ }
+ }
+ }
+ } else {
+ int code = tigetnum("XM");
+ switch (code) {
+ case 1006:
+ break;
+ default:
+ code = 1000;
+ break;
+ }
+ sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
+ }