+#endif /* USE_EMX_MOUSE */
+
+#if USE_SYSMOUSE
+ {
+ struct mouse_info the_mouse;
+ char *the_device = 0;
+
+ if (isatty(sp->_ifd))
+ the_device = ttyname(sp->_ifd);
+ if (the_device == 0)
+ the_device = "/dev/tty";
+
+ sp->_mouse_fd = open(the_device, O_RDWR);
+
+ if (sp->_mouse_fd >= 0) {
+ /*
+ * sysmouse does not have a usable user interface for obtaining
+ * mouse events. The logical way to proceed (reading data on a
+ * stream) only works if one opens the device as root. Even in
+ * that mode, careful examination shows we lose events
+ * occasionally. The interface provided for user programs is to
+ * establish a signal handler. really.
+ *
+ * Take over SIGUSR2 for this purpose since SIGUSR1 is more
+ * likely to be used by an application. getch() will have to
+ * handle the misleading EINTR's.
+ */
+ signal(SIGUSR2, SIG_IGN);
+ the_mouse.operation = MOUSE_MODE;
+ the_mouse.u.mode.mode = 0;
+ the_mouse.u.mode.signal = SIGUSR2;
+ if (ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
+ signal(SIGUSR2, handle_sysmouse);
+ the_mouse.operation = MOUSE_SHOW;
+ ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
+
+#if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) /* FreeBSD > 2.x */
+ {
+#ifndef FBIO_GETMODE /* FreeBSD 3.x */
+#define FBIO_GETMODE CONS_GET
+#define FBIO_MODEINFO CONS_MODEINFO
+#endif /* FBIO_GETMODE */
+ video_info_t the_video;
+
+ if (ioctl(sp->_mouse_fd,
+ FBIO_GETMODE,
+ &the_video.vi_mode) != -1
+ && ioctl(sp->_mouse_fd,
+ FBIO_MODEINFO,
+ &the_video) != -1) {
+ sp->_sysmouse_char_width = the_video.vi_cwidth;
+ sp->_sysmouse_char_height = the_video.vi_cheight;
+ }
+ }
+#endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */
+
+ if (sp->_sysmouse_char_width <= 0)
+ sp->_sysmouse_char_width = 8;
+ if (sp->_sysmouse_char_height <= 0)
+ sp->_sysmouse_char_height = 16;
+ sp->_mouse_type = M_SYSMOUSE;
+ returnVoid;
+ }
+ }
+ }
+#endif /* USE_SYSMOUSE */