+handle_sysmouse(int sig GCC_UNUSED)
+{
+ 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;
+ }
+}
+#endif /* USE_SYSMOUSE */
+
+static void
+init_xterm_mouse(void)
+{
+ SP->_mouse_type = M_XTERM;
+ SP->_mouse_xtermcap = tigetstr("XM");
+ if (!VALID_STRING(SP->_mouse_xtermcap))
+ SP->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";