X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_mouse.c;h=f12686c0af8ba043c62219ca3eb69c440479c022;hp=c7af9ce24f16734579a13be572e6915afaaf5cd1;hb=41677b308e138027b7e435f741ee7fe5651237b0;hpb=b94faec6aab7c3613c1e7d217f6df6f42d929234 diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c index c7af9ce2..f12686c0 100644 --- a/ncurses/base/lib_mouse.c +++ b/ncurses/base/lib_mouse.c @@ -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 1992,1995 * * and: Eric S. Raymond * * and: Thomas E. Dickey 1996-on * + * and: Juergen Pfeifer 2008 * ****************************************************************************/ /* @@ -79,7 +80,11 @@ #include -MODULE_ID("$Id: lib_mouse.c,v 1.105 2009/02/28 21:09:20 tom Exp $") +#ifndef CUR +#define CUR SP_TERMTYPE +#endif + +MODULE_ID("$Id: lib_mouse.c,v 1.118 2010/05/15 21:31:12 tom Exp $") #include @@ -117,12 +122,12 @@ make an error #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT -#define MASK_RELEASE(x) NCURSES_MOUSE_MASK(x, 001) -#define MASK_PRESS(x) NCURSES_MOUSE_MASK(x, 002) -#define MASK_CLICK(x) NCURSES_MOUSE_MASK(x, 004) -#define MASK_DOUBLE_CLICK(x) NCURSES_MOUSE_MASK(x, 010) -#define MASK_TRIPLE_CLICK(x) NCURSES_MOUSE_MASK(x, 020) -#define MASK_RESERVED_EVENT(x) NCURSES_MOUSE_MASK(x, 040) +#define MASK_RELEASE(x) (mmask_t) NCURSES_MOUSE_MASK(x, 001) +#define MASK_PRESS(x) (mmask_t) NCURSES_MOUSE_MASK(x, 002) +#define MASK_CLICK(x) (mmask_t) NCURSES_MOUSE_MASK(x, 004) +#define MASK_DOUBLE_CLICK(x) (mmask_t) NCURSES_MOUSE_MASK(x, 010) +#define MASK_TRIPLE_CLICK(x) (mmask_t) NCURSES_MOUSE_MASK(x, 020) +#define MASK_RESERVED_EVENT(x) (mmask_t) NCURSES_MOUSE_MASK(x, 040) #if NCURSES_MOUSE_VERSION == 1 #define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED) @@ -149,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 */ @@ -184,7 +189,7 @@ _trace_slot(SCREEN *sp, const char *tag) { MEVENT *ep; - _tracef(tag); + _tracef("%s", tag); for (ep = FirstEV(sp); ep <= LastEV(sp); ep++) _tracef("mouse event queue slot %ld = %s", @@ -343,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) { @@ -351,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) @@ -441,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 = @@ -455,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; } @@ -479,8 +499,6 @@ enable_gpm_mouse(SCREEN *sp, bool enable) } #endif /* USE_GPM_SUPPORT */ -#define xterm_kmous "\033[M" - static void initialize_mousetype(SCREEN *sp) { @@ -515,7 +533,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]; @@ -622,16 +640,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; } @@ -666,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; @@ -735,7 +758,7 @@ _nc_mouse_event(SCREEN *sp GCC_UNUSED) eventp->z = 0; /* bump the next-free pointer into the circular list */ - sp->_mouse_eventp = eventp = NEXT(eventp); + sp->_mouse_eventp = NEXT(eventp); result = TRUE; break; } @@ -766,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; } @@ -821,17 +866,24 @@ _nc_mouse_inline(SCREEN *sp) * Wheel mice may return buttons 4 and 5 when the wheel is turned. * We encode those as button presses. */ +# if USE_PTHREADS_EINTR + if ((pthread_self) && (pthread_kill) && (pthread_equal)) + _nc_globals.read_thread = pthread_self(); +# endif for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) { /* For VIO mouse we add extra bit 64 to disambiguate button-up. */ #if USE_EMX_MOUSE - res = read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3); + res = (int) read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3); #else - res = read(sp->_ifd, kbuf + grabbed, 3 - grabbed); + res = (int) read(sp->_ifd, kbuf + grabbed, 3 - grabbed); #endif if (res == -1) break; } +#if USE_PTHREADS_EINTR + _nc_globals.read_thread = 0; +#endif kbuf[3] = '\0'; TR(TRACE_IEVENT, @@ -962,6 +1014,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; @@ -991,6 +1048,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; @@ -1228,6 +1290,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; @@ -1260,6 +1327,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; } @@ -1274,24 +1348,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 @@ -1308,7 +1387,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; @@ -1340,7 +1419,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) @@ -1383,7 +1465,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; @@ -1401,7 +1483,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; @@ -1449,7 +1531,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;