diff -ruN -x Makefile -x configure -x config.cache -x config.h -x *.[178] -x gpm.info -x gpmdoc.ps -x gpmdoc.txt -x gpm-root.c -x stamp-h* -x *.elc -x *.d gpm-1.19.6.orig/configure.in gpm-1.19.6/configure.in
--- gpm-1.19.6.orig/configure.in	Thu Nov 22 20:06:37 2001
+++ gpm-1.19.6/configure.in	Thu Nov 22 19:53:17 2001
@@ -59,7 +59,7 @@
         lispdir='${datadir}/emacs/site-lisp'
 fi
 
-AC_CHECK_HEADERS(syslog.h linux/joystick.h ncurses.h ncurses/curses.h curses.h)
+AC_CHECK_HEADERS(syslog.h linux/joystick.h ncurses.h ncurses/curses.h curses.h term.h)
 
 AC_ARG_WITH(curses,
 [  --without-curses        disable curses support even if curses found])
@@ -109,7 +109,7 @@
         else :; fi
     done
     SHARED_LIBS="$LIBS $TERMLIBS -lc"
-    LIBS=$SAVELIBS ;;
+    LIBS="$LIBS $SAVELIBS" ;;
 esac    
 
 GPMXTERM=
diff -ruN -x Makefile -x configure -x config.cache -x config.h -x *.[178] -x gpm.info -x gpmdoc.ps -x gpmdoc.txt -x gpm-root.c -x stamp-h* -x *.elc -x *.d gpm-1.19.6.orig/src/liblow.c gpm-1.19.6/src/liblow.c
--- gpm-1.19.6.orig/src/liblow.c	Mon Oct  1 16:08:47 2001
+++ gpm-1.19.6/src/liblow.c	Thu Nov 22 20:06:17 2001
@@ -46,6 +46,12 @@
 #include <sys/kd.h>        /* KDGETMODE */
 #include <termios.h>       /* winsize */
 
+#ifdef HAVE_TERM_H
+#include <curses.h>
+#include <term.h>
+#undef buttons
+#endif /* HAVE_TERM_H */
+
 
 #include "headers/gpmInt.h"
 #include "headers/general.h"
@@ -178,7 +184,6 @@
 int Gpm_Open(Gpm_Connect *conn, int flag)
 {
    char tty[32];
-   char *term;
    int i;
    static char *vcname = NULL; /* is tty / vc base */
    static char *consolename = NULL; /* is the console */
@@ -186,6 +191,12 @@
    struct winsize win;
    Gpm_Stst *new;
    char* sock_name = 0;
+#ifdef HAVE_TERM_H
+   char *mousecap;
+   int terror;
+#else /* ! HAVE_TERM_H */
+   char *term;
+#endif /* ! HAVE_TERM_H */
 
 
    if(!set_devfs_onet(&consolename,&vcname)) goto err;
@@ -194,14 +205,24 @@
   
   /*....................................... First of all, check xterm */
 
-  if ((term=(char *)getenv("TERM")) && !strncmp(term,"xterm",5))
-    {
+#ifdef HAVE_TERM_H
+  if (setupterm((char *) 0, 1, &terror) == 0 && terror == 1
+      && (mousecap=tigetstr("kmous")) && mousecap != (char *)-1
+      && mousecap[0]) {
+    del_curterm(cur_term);
+#else /* ! HAVE_TERM_H */
+  if ((term=(char *)getenv("TERM")) && !strncmp(term,"xterm",5)) {
+#endif
       if (gpm_tried) return gpm_fd; /* no stack */
       gpm_fd=-2;
       GPM_XTERM_ON;
       gpm_flag=1;
       return gpm_fd;
     }
+#ifdef HAVE_TERM_H
+  if (cur_term)
+    del_curterm(cur_term);
+#endif /* HAVE_TERM_H */
   /*....................................... No xterm, go on */
 
 
