+
+#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 */
+
+static void
+init_xterm_mouse(SCREEN *sp)
+{
+ 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%;";
+}
+
+static void
+enable_xterm_mouse(SCREEN *sp, int enable)
+{
+#if USE_EMX_MOUSE
+ sp->_emxmouse_activated = enable;
+#else
+ NCURSES_SP_NAME(_nc_putp) (NCURSES_SP_ARGx
+ "xterm-mouse",
+ TPARM_1(sp->_mouse_xtermcap, enable));
+#endif
+ sp->_mouse_active = enable;
+}
+
+#if USE_GPM_SUPPORT
+static bool
+allow_gpm_mouse(void)
+{
+ bool result = FALSE;
+
+ /* GPM does printf's without checking if stdout is a terminal */
+ if (isatty(fileno(stdout))) {
+ char *list = getenv("NCURSES_GPM_TERMS");
+ char *env = getenv("TERM");
+ if (list != 0) {
+ if (env != 0) {
+ result = _nc_name_match(list, env, "|:");
+ }
+ } else {
+ /* GPM checks the beginning of the $TERM variable to decide if it
+ * should pass xterm events through. There is no real advantage in
+ * allowing GPM to do this. Recent versions relax that check, and
+ * pretend that GPM can work with any terminal having the kmous
+ * capability. Perhaps that works for someone. If so, they can
+ * set the environment variable (above).
+ */
+ if (env != 0 && strstr(env, "linux") != 0) {
+ result = TRUE;
+ }
+ }
+ }
+ return result;
+}
+
+#ifdef HAVE_LIBDL