]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_mouse.c
ncurses 5.7 - patch 20100410
[ncurses.git] / ncurses / base / lib_mouse.c
index 4034c9a77726247e3a0c02afec8c5bb692c960db..43bf43cfbd89488a6d00cf1e6981a7605d1f8d00 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -84,7 +84,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_mouse.c,v 1.110 2009/10/24 23:21:31 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.113 2010/03/24 23:06:46 tom Exp $")
 
 #include <tic.h>
 
@@ -450,6 +450,8 @@ enable_gpm_mouse(SCREEN *sp, bool enable)
        }
 #endif
        if (sp->_mouse_gpm_loaded) {
+           int code;
+
            /* GPM: initialize connection to gpm server */
            sp->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP;
            sp->_mouse_gpm_connect.defaultMask =
@@ -464,7 +466,16 @@ enable_gpm_mouse(SCREEN *sp, bool enable)
             * 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);
+           code = my_Gpm_Open(&sp->_mouse_gpm_connect, 0);
+           result = (code >= 0);
+
+           /*
+            * GPM can return a -2 if it is trying to do something with xterm.
+            * Ignore that, since it conflicts with our use of stdin.
+            */
+           if (code == -2) {
+               my_Gpm_Close();
+           }
        } else {
            result = FALSE;
        }
@@ -678,7 +689,7 @@ _nc_mouse_init(SCREEN *sp)
  * fifo_push() in lib_getch.c
  */
 static bool
-_nc_mouse_event(SCREEN *sp GCC_UNUSED)
+_nc_mouse_event(SCREEN *sp)
 {
     MEVENT *eventp = sp->_mouse_eventp;
     bool result = FALSE;
@@ -778,6 +789,28 @@ _nc_mouse_event(SCREEN *sp GCC_UNUSED)
        break;
 #endif /* USE_SYSMOUSE */
 
+#ifdef USE_TERM_DRIVER
+    case M_TERM_DRIVER:
+       while (sp->_drv_mouse_head < sp->_drv_mouse_tail) {
+           *eventp = sp->_drv_mouse_fifo[sp->_drv_mouse_head];
+
+           /*
+            * Point the fifo-head to the next possible location.  If there
+            * are none, reset the indices.
+            */
+           sp->_drv_mouse_head += 1;
+           if (sp->_drv_mouse_head == sp->_drv_mouse_tail) {
+               sp->_drv_mouse_tail = 0;
+               sp->_drv_mouse_head = 0;
+           }
+
+           /* bump the next-free pointer into the circular list */
+           sp->_mouse_eventp = eventp = NEXT(eventp);
+           result = TRUE;
+       }
+       break;
+#endif
+
     case M_NONE:
        break;
     }
@@ -974,6 +1007,11 @@ mouse_activate(SCREEN *sp, bool on)
            signal(SIGUSR2, handle_sysmouse);
            sp->_mouse_active = TRUE;
            break;
+#endif
+#ifdef USE_TERM_DRIVER
+       case M_TERM_DRIVER:
+           sp->_mouse_active = TRUE;
+           break;
 #endif
        case M_NONE:
            return;
@@ -1003,6 +1041,11 @@ mouse_activate(SCREEN *sp, bool on)
            signal(SIGUSR2, SIG_IGN);
            sp->_mouse_active = FALSE;
            break;
+#endif
+#ifdef USE_TERM_DRIVER
+       case M_TERM_DRIVER:
+           sp->_mouse_active = FALSE;
+           break;
 #endif
        case M_NONE:
            return;
@@ -1240,6 +1283,11 @@ _nc_mouse_wrap(SCREEN *sp)
     case M_SYSMOUSE:
        mouse_activate(sp, FALSE);
        break;
+#endif
+#ifdef USE_TERM_DRIVER
+    case M_TERM_DRIVER:
+       mouse_activate(sp, FALSE);
+       break;
 #endif
     case M_NONE:
        break;
@@ -1272,6 +1320,13 @@ _nc_mouse_resume(SCREEN *sp)
        mouse_activate(sp, TRUE);
        break;
 #endif
+
+#ifdef USE_TERM_DRIVER
+    case M_TERM_DRIVER:
+       mouse_activate(sp, TRUE);
+       break;
+#endif
+
     case M_NONE:
        break;
     }
@@ -1286,6 +1341,8 @@ _nc_mouse_resume(SCREEN *sp)
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
 {
+    int result = ERR;
+
     T((T_CALLED("getmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
 
     if ((aevent != 0) && (SP_PARM != 0) && (SP_PARM->_mouse_type != M_NONE)) {
@@ -1293,17 +1350,20 @@ NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
        /* compute the current-event pointer */
        MEVENT *prev = PREV(eventp);
 
-       /* copy the event we find there */
-       *aevent = *prev;
+       if (prev->id != INVALID_EVENT) {
+           /* copy the event we find there */
+           *aevent = *prev;
 
-       TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
-                         _nc_tracemouse(SP_PARM, prev),
-                         (long) IndexEV(SP_PARM, prev)));
+           TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
+                             _nc_tracemouse(SP_PARM, prev),
+                             (long) IndexEV(SP_PARM, prev)));
 
-       prev->id = INVALID_EVENT;       /* so the queue slot becomes free */
-       returnCode(OK);
+           prev->id = INVALID_EVENT;   /* so the queue slot becomes free */
+           SP_PARM->_mouse_eventp = PREV(prev);
+           result = OK;
+       }
     }
-    returnCode(ERR);
+    returnCode(result);
 }
 
 #if NCURSES_SP_FUNCS