diff options
Diffstat (limited to 'lib/libcurses/lib_mouse.c')
-rw-r--r-- | lib/libcurses/lib_mouse.c | 127 |
1 files changed, 89 insertions, 38 deletions
diff --git a/lib/libcurses/lib_mouse.c b/lib/libcurses/lib_mouse.c index d7ddf67883d..1076b1bd78c 100644 --- a/lib/libcurses/lib_mouse.c +++ b/lib/libcurses/lib_mouse.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_mouse.c,v 1.3 1997/12/03 05:21:23 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -61,14 +63,12 @@ #endif #endif -MODULE_ID("Id: lib_mouse.c,v 0.22 1997/02/15 22:33:37 tom Exp $") +MODULE_ID("Id: lib_mouse.c,v 0.31 1997/10/11 22:40:49 tom Exp $") #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT #define INVALID_EVENT -1 -int _nc_max_click_interval = 166; /* max press/release separation */ - static int mousetype; #define M_XTERM -1 /* use xterm's mouse tracking? */ #define M_NONE 0 /* no mouse device */ @@ -82,6 +82,10 @@ static Gpm_Connect gpm_connect; static mmask_t eventmask; /* current event mask */ +static bool _nc_mouse_parse(int); +static void _nc_mouse_resume(SCREEN *); +static void _nc_mouse_wrap(SCREEN *); + /* maintain a circular list of mouse events */ #define EV_MAX 8 /* size of circular event queue */ static MEVENT events[EV_MAX]; /* hold the last mouse event seen */ @@ -101,10 +105,25 @@ static void _trace_slot(const char *tag) } #endif -void _nc_mouse_init(SCREEN *sp GCC_UNUSED) -/* initialize the mouse -- called at screen-setup time */ +/* FIXME: The list of names should be configurable */ +static int is_xterm(const char *name) +{ + return (!strncmp(name, "xterm", 5) + || !strncmp(name, "rxvt", 4) + || !strncmp(name, "kterm", 5) + || !strncmp(name, "color_xterm", 11)); +} + +static void _nc_mouse_init(void) +/* initialize the mouse */ { int i; + static int initialized; + + if (initialized) { + return; + } + initialized = TRUE; TR(MY_TRACE, ("_nc_mouse_init() called")); @@ -113,11 +132,12 @@ void _nc_mouse_init(SCREEN *sp GCC_UNUSED) #ifdef EXTERN_TERMINFO /* we know how to recognize mouse events under xterm */ - if (!strncmp(cur_term->name, "xterm", 5) && key_mouse) + if (key_mouse != 0 && is_xterm(cur_term->name)) mousetype = M_XTERM; #else /* we know how to recognize mouse events under xterm */ - if (!strncmp(cur_term->type.term_names, "xterm", 5) && key_mouse) + if (key_mouse != 0 + && is_xterm(cur_term->type.term_names)) mousetype = M_XTERM; #endif @@ -129,24 +149,15 @@ void _nc_mouse_init(SCREEN *sp GCC_UNUSED) gpm_connect.defaultMask = ~gpm_connect.eventMask; gpm_connect.minMod = 0; gpm_connect.maxMod = ~0; - if (Gpm_Open (&gpm_connect, 0) >= 0) /* returns the file-descriptor */ + if (Gpm_Open (&gpm_connect, 0) >= 0) { /* returns the file-descriptor */ mousetype = M_GPM; + SP->_mouse_fd = gpm_fd; + } } #endif } -int _nc_mouse_fd(void) -{ - if (mousetype == M_XTERM) - return -1; -#if USE_GPM_SUPPORT - else if (mousetype == M_GPM) - return gpm_fd; -#endif - return -1; -} - -bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) +static bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) /* query to see if there is a pending mouse event */ { #if USE_GPM_SUPPORT @@ -159,7 +170,7 @@ bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) { eventp->id = 0; /* there's only one mouse... */ - eventp->bstate = 0; + eventp->bstate = 0; switch (ev.type & 0x0f) { case(GPM_DOWN): @@ -178,7 +189,7 @@ bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) eventp->x = ev.x - 1; eventp->y = ev.y - 1; - eventp->z = 0; + eventp->z = 0; /* bump the next-free pointer into the circular list */ eventp = NEXT(eventp); @@ -189,7 +200,7 @@ bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) return(FALSE); /* no event waiting */ } -bool _nc_mouse_inline(SCREEN *sp) +static bool _nc_mouse_inline(SCREEN *sp) /* mouse report received in the keyboard stream -- parse its info */ { TR(MY_TRACE, ("_nc_mouse_inline() called")); @@ -307,8 +318,10 @@ bool _nc_mouse_inline(SCREEN *sp) static void mouse_activate(bool on) { + _nc_mouse_init(); if (mousetype == M_XTERM) { + keyok(KEY_MOUSE, on); if (on) { TPUTS_TRACE("xterm mouse initialization"); @@ -321,6 +334,22 @@ static void mouse_activate(bool on) } (void) fflush(SP->_ofp); } + + /* Make runtime binding to cut down on object size of applications that do + * not use the mouse (e.g., 'clear'). + */ + if (on) + { + SP->_mouse_event = _nc_mouse_event; + SP->_mouse_inline = _nc_mouse_inline; + SP->_mouse_parse = _nc_mouse_parse; + SP->_mouse_resume = _nc_mouse_resume; + SP->_mouse_wrap = _nc_mouse_wrap; +#if USE_GPM_SUPPORT + if (mousetype == M_GPM) + SP->_mouse_fd = gpm_fd; +#endif + } } /************************************************************************** @@ -329,7 +358,7 @@ static void mouse_activate(bool on) * **************************************************************************/ -bool _nc_mouse_parse(int runcount) +static bool _nc_mouse_parse(int runcount) /* parse a run of atomic mouse events into a gesture */ { MEVENT *ep, *runp, *next, *prev = PREV(eventp); @@ -363,7 +392,9 @@ bool _nc_mouse_parse(int runcount) { TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %d", _tracemouse(prev), prev-events)); - return (PREV(prev)->id >= 0) ? (PREV(prev)->bstate & eventmask) : 0; + return (prev->id >= 0) + ? ((prev->bstate & eventmask) ? TRUE : FALSE) + : FALSE; } /* find the start of the run */ @@ -562,7 +593,7 @@ bool _nc_mouse_parse(int runcount) return(PREV(eventp)->id != INVALID_EVENT); } -void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) +static void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) /* release mouse -- called by endwin() before shellout/exit */ { TR(MY_TRACE, ("_nc_mouse_wrap() called")); @@ -574,7 +605,7 @@ void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) /* GPM: pass all mouse events to next client */ } -void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) +static void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) /* re-connect to mouse -- called by doupdate() after shellout */ { TR(MY_TRACE, ("_nc_mouse_resume() called")); @@ -595,6 +626,8 @@ void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) int getmouse(MEVENT *aevent) /* grab a copy of the current mouse event */ { + T((T_CALLED("getmouse(%p)"), aevent)); + if (aevent && (mousetype == M_XTERM || mousetype == M_GPM)) { /* compute the current-event pointer */ @@ -607,9 +640,9 @@ int getmouse(MEVENT *aevent) _tracemouse(prev), prev-events)); prev->id = INVALID_EVENT; /* so the queue slot becomes free */ - return(OK); + returnCode(OK); } - return(ERR); + returnCode(ERR); } int ungetmouse(MEVENT *aevent) @@ -628,9 +661,14 @@ int ungetmouse(MEVENT *aevent) mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) /* set the mouse event mask */ { + mmask_t result = 0; + + T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask)); + if (oldmask) *oldmask = eventmask; + _nc_mouse_init(); if (mousetype == M_XTERM || mousetype == M_GPM) { eventmask = newmask & @@ -644,22 +682,22 @@ mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) mouse_activate(eventmask != 0); - return(eventmask); + result = eventmask; } - return(0); + returnCode(result); } -bool wenclose(WINDOW *win, int y, int x) +bool wenclose(const WINDOW *win, int y, int x) /* check to see if given window encloses given screen location */ { if (win) { y -= win->_yoffset; - return (win->_begy <= y && - win->_begx <= x && - (win->_begx + win->_maxx) >= x && - (win->_begy + win->_maxy) >= y); + return ((win->_begy <= y && + win->_begx <= x && + (win->_begx + win->_maxx) >= x && + (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); } return FALSE; } @@ -667,10 +705,23 @@ bool wenclose(WINDOW *win, int y, int x) int mouseinterval(int maxclick) /* set the maximum mouse interval within which to recognize a click */ { - int oldval = _nc_max_click_interval; + int oldval; + + if (SP != 0) { + oldval = SP->_maxclick; + if (maxclick >= 0) + SP->_maxclick = maxclick; + } else { + oldval = DEFAULT_MAXCLICK; + } - _nc_max_click_interval = maxclick; return(oldval); } +/* This may be used by other routines to ask for the existence of mouse + support */ +int _nc_has_mouse(void) { + return (mousetype==M_NONE ? 0:1); +} + /* lib_mouse.c ends here */ |