]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_mouse.c
ncurses 5.6 - patch 20081018
[ncurses.git] / ncurses / base / lib_mouse.c
index 731025e30d3a12666ea06cc6888202c4b32bb18e..95f29aa69111a47c8577536b921c31d823efa3cc 100644 (file)
@@ -79,7 +79,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_mouse.c,v 1.99 2008/09/25 21:47:51 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.102 2008/10/18 21:48:55 tom Exp $")
 
 #include <term.h>
 #include <tic.h>
@@ -255,13 +255,13 @@ mouse_server(unsigned long param)
                 *      3 = middle.
                 */
                if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN)
-                   write_event(mouev.fs & MOUSE_BN1_DOWN,
+                   write_event(sp, mouev.fs & MOUSE_BN1_DOWN,
                                sp->_emxmouse_buttons[1], mouev.col, mouev.row);
                if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN)
-                   write_event(mouev.fs & MOUSE_BN2_DOWN,
+                   write_event(sp, mouev.fs & MOUSE_BN2_DOWN,
                                sp->_emxmouse_buttons[3], mouev.col, mouev.row);
                if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN)
-                   write_event(mouev.fs & MOUSE_BN3_DOWN,
+                   write_event(sp, mouev.fs & MOUSE_BN3_DOWN,
                                sp->_emxmouse_buttons[2], mouev.col, mouev.row);
 
              finish:
@@ -365,20 +365,33 @@ enable_xterm_mouse(SCREEN *sp, int enable)
 }
 
 #if USE_GPM_SUPPORT
-static int
+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");
-       /* 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;
+       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 FALSE;
+    return result;
 }
 
 #ifdef HAVE_LIBDL
@@ -388,6 +401,7 @@ unload_gpm_library(SCREEN *sp)
     if (SP->_dlopen_gpm != 0) {
        T(("unload GPM library"));
        sp->_mouse_gpm_loaded = FALSE;
+       sp->_mouse_fd = -1;
        dlclose(sp->_dlopen_gpm);
        sp->_dlopen_gpm = 0;
     }
@@ -531,7 +545,7 @@ initialize_mousetype(SCREEN *sp)
            setmode(handles[1], O_BINARY);
            /* Do not use CRT functions, we may single-threaded. */
            rc = DosCreateThread((unsigned long *) &sp->_emxmouse_thread,
-                                mouse_server, sp, 0, 8192);
+                                mouse_server, (long) sp, 0, 8192);
            if (rc) {
                printf("mouse thread error %d=%#x", rc, rc);
            } else {