+
+#if USE_GPM_SUPPORT
+static int
+allow_gpm_mouse(void)
+{
+ /* GPM does printf's without checking if stdout is a terminal */
+ if (isatty(fileno(stdout))) {
+ char *env = getenv("TERM");
+ /* 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.
+ */
+ if (env == 0 || strncmp(env, "xterm", 5))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static bool
+enable_gpm_mouse(int enable)
+{
+ bool result;
+
+ T((T_CALLED("enable_gpm_mouse(%d)"), enable));
+
+ if (enable && !SP->_mouse_active) {
+ /* GPM: initialize connection to gpm server */
+ SP->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP;
+ SP->_mouse_gpm_connect.defaultMask =
+ ~(SP->_mouse_gpm_connect.eventMask | GPM_HARD);
+ SP->_mouse_gpm_connect.minMod = 0;
+ SP->_mouse_gpm_connect.maxMod =
+ (unsigned short) (~((1 << KG_SHIFT) |
+ (1 << KG_SHIFTL) |
+ (1 << KG_SHIFTR)));
+ /*
+ * Note: GPM hardcodes \E[?1001s and \E[?1000h during its open.
+ * The former is recognized by wscons (SunOS), and the latter by
+ * xterm. Those will not show up in ncurses' traces.
+ */
+ result = (my_Gpm_Open(&SP->_mouse_gpm_connect, 0) >= 0);
+ SP->_mouse_active = result;
+ T(("GPM open %s", result ? "succeeded" : "failed"));
+ } else {
+ if (!enable && SP->_mouse_active) {
+ /* GPM: close connection to gpm server */
+ my_Gpm_Close();
+ SP->_mouse_active = FALSE;
+ T(("GPM closed"));
+ }
+ result = FALSE;
+ }
+ returnBool(result);
+}
+#endif /* USE_GPM_SUPPORT */
+
+#define xterm_kmous "\033[M"