]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_mouse.c
ncurses 5.7 - patch 20100102
[ncurses.git] / ncurses / base / lib_mouse.c
index f0ad82fc40d5b574c7547c7b0fd4f438f767bcf2..e60e6be8df79f4fea18b23e5578e705ddef3a60c 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            *
@@ -30,6 +30,7 @@
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                         2008                    *
  ****************************************************************************/
 
 /*
 #include <curses.priv.h>
 
 #ifndef CUR
-#define CUR SP_TERMTYPE 
+#define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_mouse.c,v 1.107 2009/05/10 00:48:29 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.111 2010/01/02 21:06:52 tom Exp $")
 
 #include <tic.h>
 
@@ -153,7 +154,7 @@ make an error
 #define LIBGPM_SONAME "libgpm.so"
 #endif
 
-#define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(SP_PARM->_dlopen_gpm, #name))
+#define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(sp->_dlopen_gpm, #name))
 
 #endif                         /* USE_GPM_SUPPORT */
 
@@ -347,6 +348,9 @@ handle_sysmouse(int sig GCC_UNUSED)
 }
 #endif /* USE_SYSMOUSE */
 
+#ifndef USE_TERM_DRIVER
+#define xterm_kmous "\033[M"
+
 static void
 init_xterm_mouse(SCREEN *sp)
 {
@@ -355,6 +359,7 @@ init_xterm_mouse(SCREEN *sp)
     if (!VALID_STRING(sp->_mouse_xtermcap))
        sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
 }
+#endif
 
 static void
 enable_xterm_mouse(SCREEN *sp, int enable)
@@ -483,8 +488,6 @@ enable_gpm_mouse(SCREEN *sp, bool enable)
 }
 #endif /* USE_GPM_SUPPORT */
 
-#define xterm_kmous "\033[M"
-
 static void
 initialize_mousetype(SCREEN *sp)
 {
@@ -519,7 +522,7 @@ initialize_mousetype(SCREEN *sp)
     /* OS/2 VIO */
 #if USE_EMX_MOUSE
     if (!sp->_emxmouse_thread
-       && strstr(cur_term->type.term_names, "xterm") == 0
+       && strstr(TerminalOf(sp)->type.term_names, "xterm") == 0
        && key_mouse) {
        int handles[2];
 
@@ -626,16 +629,21 @@ initialize_mousetype(SCREEN *sp)
     }
 #endif /* USE_SYSMOUSE */
 
+#ifdef USE_TERM_DRIVER
+    CallDriver(sp, initmouse);
+#else
     /* we know how to recognize mouse events under "xterm" */
     if (key_mouse != 0) {
        if (!strcmp(key_mouse, xterm_kmous)
-           || strstr(cur_term->type.term_names, "xterm") != 0) {
+           || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
            init_xterm_mouse(sp);
        }
-    } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
+    } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
        if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
            init_xterm_mouse(sp);
     }
+#endif
+
     returnVoid;
 }
 
@@ -1278,24 +1286,29 @@ _nc_mouse_resume(SCREEN *sp)
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
 {
-    T((T_CALLED("getmouse(%p,%p)"), SP_PARM, 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)) {
        MEVENT *eventp = SP_PARM->_mouse_eventp;
        /* 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
@@ -1312,7 +1325,7 @@ NCURSES_SP_NAME(ungetmouse) (NCURSES_SP_DCLx MEVENT * aevent)
 {
     int result = ERR;
 
-    T((T_CALLED("ungetmouse(%p,%p)"), SP_PARM, aevent));
+    T((T_CALLED("ungetmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
 
     if (aevent != 0 && SP_PARM != 0) {
        MEVENT *eventp = SP_PARM->_mouse_eventp;
@@ -1344,7 +1357,10 @@ NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask)
 {
     mmask_t result = 0;
 
-    T((T_CALLED("mousemask(%p,%#lx,%p)"), SP_PARM, (unsigned long) newmask, oldmask));
+    T((T_CALLED("mousemask(%p,%#lx,%p)"),
+       (void *) SP_PARM,
+       (unsigned long) newmask,
+       (void *) oldmask));
 
     if (SP_PARM != 0) {
        if (oldmask)
@@ -1387,7 +1403,7 @@ wenclose(const WINDOW *win, int y, int x)
 {
     bool result = FALSE;
 
-    T((T_CALLED("wenclose(%p,%d,%d)"), win, y, x));
+    T((T_CALLED("wenclose(%p,%d,%d)"), (const void *) win, y, x));
 
     if (win != 0) {
        y -= win->_yoffset;
@@ -1405,7 +1421,7 @@ NCURSES_SP_NAME(mouseinterval) (NCURSES_SP_DCLx int maxclick)
 {
     int oldval;
 
-    T((T_CALLED("mouseinterval(%p,%d)"), SP_PARM, maxclick));
+    T((T_CALLED("mouseinterval(%p,%d)"), (void *) SP_PARM, maxclick));
 
     if (SP_PARM != 0) {
        oldval = SP_PARM->_maxclick;
@@ -1453,7 +1469,11 @@ wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
 {
     bool result = FALSE;
 
-    T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"), win, pY, pX, to_screen));
+    T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"),
+       (const void *) win,
+       (void *) pY,
+       (void *) pX,
+       to_screen));
 
     if (win && pY && pX) {
        int y = *pY;