1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
35 * This module is intended to encapsulate ncurses's interface to pointing
38 * The first method used is xterm's internal mouse-tracking facility.
39 * The second is Alessandro Rubini's GPM server.
41 * Notes for implementors of new mouse-interface methods:
43 * The code is logically split into a lower level that accepts event reports
44 * in a device-dependent format and an upper level that parses mouse gestures
45 * and filters events. The mediating data structure is a circular queue of
48 * Functionally, the lower level's job is to pick up primitive events and
49 * put them on the circular queue. This can happen in one of two ways:
50 * either (a) _nc_mouse_event() detects a series of incoming mouse reports
51 * and queues them, or (b) code in lib_getch.c detects the kmous prefix in
52 * the keyboard input stream and calls _nc_mouse_inline to queue up a series
53 * of adjacent mouse reports.
55 * In either case, _nc_mouse_parse() should be called after the series is
56 * accepted to parse the digested mouse reports (low-level MEVENTs) into
57 * a gesture (a high-level or composite MEVENT).
59 * Don't be too shy about adding new event types or modifiers, if you can find
60 * room for them in the 32-bit mask. The API is written so that users get
61 * feedback on which theoretical event types they won't see when they call
62 * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being
63 * used yet, and a couple of bits open at the high end.
72 # define INCL_DOSPROCESS
73 # include <os2.h> /* Need to include before the others */
76 #include <curses.priv.h>
80 #ifndef LINT /* don't need this for llib-lncurses */
81 #undef buttons /* term.h defines this, and gpm uses it! */
83 #include <linux/keyboard.h> /* defines KG_* macros */
87 MODULE_ID("$Id: lib_mouse.c,v 1.52 2000/06/29 23:02:26 tom Exp $")
89 #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
91 #define INVALID_EVENT -1
94 #define M_XTERM -1 /* use xterm's mouse tracking? */
95 #define M_NONE 0 /* no mouse device */
96 #define M_GPM 1 /* use GPM */
97 #define M_QNX 2 /* QNX mouse on console */
98 #define M_QNX_TERM 3 /* QNX mouse on pterm/xterm (using qansi-m) */
102 static Gpm_Connect gpm_connect;
106 static mmask_t eventmask; /* current event mask */
108 static bool _nc_mouse_parse(int);
109 static void _nc_mouse_resume(SCREEN *);
110 static void _nc_mouse_wrap(SCREEN *);
112 /* maintain a circular list of mouse events */
114 /* The definition of the circular list size (EV_MAX), is in curses.priv.h, so
115 * wgetch() may refer to the size and call _nc_mouse_parse() before circular
118 static MEVENT events[EV_MAX]; /* hold the last mouse event seen */
119 static MEVENT *eventp = events; /* next free slot in event queue */
120 #define NEXT(ep) ((ep == events + EV_MAX - 1) ? events : ep + 1)
121 #define PREV(ep) ((ep == events) ? events + EV_MAX - 1 : ep - 1)
125 _trace_slot(const char *tag)
131 for (ep = events; ep < events + EV_MAX; ep++)
132 _tracef("mouse event queue slot %ld = %s",
133 (long) (ep - events),
143 static int mouse_wfd;
144 static int mouse_thread;
145 static int mouse_activated;
146 static char mouse_buttons[] =
149 # define M_FD(sp) sp->_mouse_fd
152 write_event(int down, int button, int x, int y)
155 unsigned long ignore;
157 strcpy(buf, key_mouse);
158 buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40);
159 buf[4] = ' ' + x - LEFT_COL + 1;
160 buf[5] = ' ' + y - TOP_ROW + 1;
161 DosWrite(mouse_wfd, buf, 6, &ignore);
165 mouse_server(unsigned long ignored GCC_UNUSED)
167 unsigned short fWait = MOU_WAIT;
168 /* NOPTRRECT mourt = { 0,0,24,79 }; */
171 unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN;
173 char errmess[] = "Unexpected termination of mouse thread\r\n";
174 unsigned long ignore;
176 /* open the handle for the mouse */
177 if (MouOpen(NULL, &hmou) == 0) {
179 if (MouSetEventMask(&mask, hmou) == 0
180 && MouDrawPtr(hmou) == 0) {
183 /* sit and wait on the event queue */
184 if (MouReadEventQue(&mouev, &fWait, hmou))
186 if (!mouse_activated)
190 * OS/2 numbers a 3-button mouse inconsistently from other
196 if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN)
197 write_event(mouev.fs & MOUSE_BN1_DOWN,
198 mouse_buttons[1], mouev.col, mouev.row);
199 if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN)
200 write_event(mouev.fs & MOUSE_BN2_DOWN,
201 mouse_buttons[3], mouev.col, mouev.row);
202 if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN)
203 write_event(mouev.fs & MOUSE_BN3_DOWN,
204 mouse_buttons[2], mouev.col, mouev.row);
211 DosWrite(2, errmess, strlen(errmess), &ignore);
214 DosExit(EXIT_THREAD, 0L);
217 server_state(const int state)
218 { /* It would be nice to implement pointer-off and stop looping... */
219 mouse_activated = state;
224 static int initialized;
227 initialize_mousetype(void)
229 static const char *xterm_kmous = "\033[M";
231 /* Try gpm first, because gpm may be configured to run in xterm */
233 /* GPM: initialize connection to gpm server */
234 gpm_connect.eventMask = GPM_DOWN | GPM_UP;
235 gpm_connect.defaultMask = ~(gpm_connect.eventMask | GPM_HARD);
236 gpm_connect.minMod = 0;
237 gpm_connect.maxMod = ~((1 << KG_SHIFT) | (1 << KG_SHIFTL) | (1 << KG_SHIFTR));
238 if (Gpm_Open(&gpm_connect, 0) >= 0) { /* returns the file-descriptor */
240 SP->_mouse_fd = gpm_fd;
248 && strstr(cur_term->type.term_names, "xterm") == 0
251 if (pipe(handles) < 0) {
252 perror("mouse pipe error");
256 if (!mouse_buttons[0]) {
257 char *s = getenv("MOUSE_BUTTONS_123");
259 mouse_buttons[0] = 1;
260 if (s && strlen(s) >= 3) {
261 mouse_buttons[1] = s[0] - '0';
262 mouse_buttons[2] = s[1] - '0';
263 mouse_buttons[3] = s[2] - '0';
266 mouse_wfd = handles[1];
267 M_FD(SP) = handles[0];
269 setmode(handles[0], O_BINARY);
270 setmode(handles[1], O_BINARY);
271 /* Do not use CRT functions, we may single-threaded. */
272 rc = DosCreateThread((unsigned long *) &mouse_thread,
273 mouse_server, 0, 0, 8192);
275 printf("mouse thread error %d=%#x", rc, rc);
284 /* we know how to recognize mouse events under "xterm" */
285 if (key_mouse != 0) {
286 if (!strcmp(key_mouse, xterm_kmous)) {
290 } else if (strstr(cur_term->type.term_names, "xterm") != 0) {
291 (void) _nc_add_to_try(&(SP->_keytry), xterm_kmous, KEY_MOUSE);
299 /* initialize the mouse */
306 TR(MY_TRACE, ("_nc_mouse_init() called"));
308 for (i = 0; i < EV_MAX; i++)
309 events[i].id = INVALID_EVENT;
311 initialize_mousetype();
313 T(("_nc_mouse_init() set mousetype to %d", mousetype));
318 _nc_mouse_event(SCREEN * sp GCC_UNUSED)
319 /* query to see if there is a pending mouse event */
322 /* GPM: query server for event, return TRUE if we find one */
326 && (_nc_timed_wait(3, 0, (int *) 0) & 2) != 0
327 && Gpm_GetEvent(&ev) == 1) {
328 eventp->id = 0; /* there's only one mouse... */
331 switch (ev.type & 0x0f) {
333 if (ev.buttons & GPM_B_LEFT)
334 eventp->bstate |= BUTTON1_PRESSED;
335 if (ev.buttons & GPM_B_MIDDLE)
336 eventp->bstate |= BUTTON2_PRESSED;
337 if (ev.buttons & GPM_B_RIGHT)
338 eventp->bstate |= BUTTON3_PRESSED;
341 if (ev.buttons & GPM_B_LEFT)
342 eventp->bstate |= BUTTON1_RELEASED;
343 if (ev.buttons & GPM_B_MIDDLE)
344 eventp->bstate |= BUTTON2_RELEASED;
345 if (ev.buttons & GPM_B_RIGHT)
346 eventp->bstate |= BUTTON3_RELEASED;
352 eventp->x = ev.x - 1;
353 eventp->y = ev.y - 1;
356 /* bump the next-free pointer into the circular list */
357 eventp = NEXT(eventp);
362 /* xterm: never have to query, mouse events are in the keyboard stream */
363 return (FALSE); /* no event waiting */
367 _nc_mouse_inline(SCREEN * sp)
368 /* mouse report received in the keyboard stream -- parse its info */
370 TR(MY_TRACE, ("_nc_mouse_inline() called"));
372 if (mousetype == M_XTERM) {
373 unsigned char kbuf[4];
378 /* This code requires that your xterm entry contain the kmous
379 * capability and that it be set to the \E[M documented in the
380 * Xterm Control Sequences reference. This is how we
381 * arrange for mouse events to be reported via a KEY_MOUSE
382 * return value from wgetch(). After this value is received,
383 * _nc_mouse_inline() gets called and is immediately
384 * responsible for parsing the mouse status information
385 * following the prefix.
387 * The following quotes from the ctrlseqs.ms document in the
388 * X distribution, describing the X mouse tracking feature:
390 * Parameters for all mouse tracking escape sequences
391 * generated by xterm encode numeric parameters in a single
392 * character as value+040. For example, ! is 1.
394 * On button press or release, xterm sends ESC [ M CbCxCy.
395 * The low two bits of Cb encode button information: 0=MB1
396 * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The
397 * upper bits encode what modifiers were down when the
398 * button was pressed and are added together. 4=Shift,
399 * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates
400 * of the mouse event. The upper left corner is (1,1).
402 * (End quote) By the time we get here, we've eaten the
403 * key prefix. FYI, the loop below is necessary because
404 * mouse click info isn't guaranteed to present as a
405 * single clist item. It always does under Linux but often
406 * fails to under Solaris.
408 for (grabbed = 0; grabbed < 3; grabbed += res) {
410 /* For VIO mouse we add extra bit 64 to disambiguate button-up. */
412 res = read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3);
414 res = read(sp->_ifd, kbuf + grabbed, 3 - grabbed);
422 ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
424 eventp->id = 0; /* there's only one mouse... */
426 /* processing code goes here */
428 switch (kbuf[0] & 0x3) {
430 eventp->bstate = BUTTON1_PRESSED;
433 eventp->bstate = BUTTON1_RELEASED;
438 eventp->bstate = BUTTON2_PRESSED;
441 eventp->bstate = BUTTON2_RELEASED;
446 eventp->bstate = BUTTON3_PRESSED;
449 eventp->bstate = BUTTON3_RELEASED;
455 * Release events aren't reported for individual buttons,
456 * just for the button set as a whole...
463 * ...however, because there are no kinds of mouse events under
464 * xterm that can intervene between press and release, we can
465 * deduce which buttons were actually released by looking at the
469 if (!(prev->bstate & BUTTON1_PRESSED))
470 eventp->bstate &= ~BUTTON1_RELEASED;
471 if (!(prev->bstate & BUTTON2_PRESSED))
472 eventp->bstate &= ~BUTTON2_RELEASED;
473 if (!(prev->bstate & BUTTON3_PRESSED))
474 eventp->bstate &= ~BUTTON3_RELEASED;
479 eventp->bstate |= BUTTON_SHIFT;
482 eventp->bstate |= BUTTON_ALT;
485 eventp->bstate |= BUTTON_CTRL;
488 eventp->x = (kbuf[1] - ' ') - 1;
489 eventp->y = (kbuf[2] - ' ') - 1;
491 ("_nc_mouse_inline: primitive mouse-event %s has slot %ld",
493 (long) (eventp - events)));
495 /* bump the next-free pointer into the circular list */
496 eventp = NEXT(eventp);
497 #if 0 /* this return would be needed for QNX's mods to lib_getch.c */
506 mouse_activate(bool on)
508 if (!on && !initialized)
517 #ifdef NCURSES_EXT_FUNCS
518 keyok(KEY_MOUSE, on);
520 TPUTS_TRACE("xterm mouse initialization");
529 SP->_mouse_fd = gpm_fd;
533 /* Make runtime binding to cut down on object size of applications that
534 * do not use the mouse (e.g., 'clear').
536 SP->_mouse_event = _nc_mouse_event;
537 SP->_mouse_inline = _nc_mouse_inline;
538 SP->_mouse_parse = _nc_mouse_parse;
539 SP->_mouse_resume = _nc_mouse_resume;
540 SP->_mouse_wrap = _nc_mouse_wrap;
546 TPUTS_TRACE("xterm mouse deinitialization");
562 /**************************************************************************
564 * Device-independent code
566 **************************************************************************/
569 _nc_mouse_parse(int runcount)
570 /* parse a run of atomic mouse events into a gesture */
572 MEVENT *ep, *runp, *next, *prev = PREV(eventp);
576 TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount));
579 * When we enter this routine, the event list next-free pointer
580 * points just past a run of mouse events that we know were separated
581 * in time by less than the critical click interval. The job of this
582 * routine is to collaps this run into a single higher-level event
585 * We accomplish this in two passes. The first pass merges press/release
586 * pairs into click events. The second merges runs of click events into
587 * double or triple-click events.
589 * It's possible that the run may not resolve to a single event (for
590 * example, if the user quadruple-clicks). If so, leading events
591 * in the run are ignored.
593 * Note that this routine is independent of the format of the specific
594 * format of the pointing-device's reports. We can use it to parse
595 * gestures on anything that reports press/release events on a per-
596 * button basis, as long as the device-dependent mouse code puts stuff
597 * on the queue in MEVENT format.
601 ("_nc_mouse_parse: returning simple mouse event %s at slot %ld",
603 (long) (prev - events)));
604 return (prev->id >= 0)
605 ? ((prev->bstate & eventmask) ? TRUE : FALSE)
609 /* find the start of the run */
611 for (n = runcount; n > 0; n--) {
616 if (_nc_tracing & TRACE_IEVENT) {
617 _trace_slot("before mouse press/release merge:");
618 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
619 (long) (runp - events),
620 (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX,
625 /* first pass; merge press/release pairs */
628 for (ep = runp; next = NEXT(ep), next != eventp; ep = next) {
629 if (ep->x == next->x && ep->y == next->y
630 && (ep->bstate & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED))
631 && (!(ep->bstate & BUTTON1_PRESSED)
632 == !(next->bstate & BUTTON1_RELEASED))
633 && (!(ep->bstate & BUTTON2_PRESSED)
634 == !(next->bstate & BUTTON2_RELEASED))
635 && (!(ep->bstate & BUTTON3_PRESSED)
636 == !(next->bstate & BUTTON3_RELEASED))
638 if ((eventmask & BUTTON1_CLICKED)
639 && (ep->bstate & BUTTON1_PRESSED)) {
640 ep->bstate &= ~BUTTON1_PRESSED;
641 ep->bstate |= BUTTON1_CLICKED;
644 if ((eventmask & BUTTON2_CLICKED)
645 && (ep->bstate & BUTTON2_PRESSED)) {
646 ep->bstate &= ~BUTTON2_PRESSED;
647 ep->bstate |= BUTTON2_CLICKED;
650 if ((eventmask & BUTTON3_CLICKED)
651 && (ep->bstate & BUTTON3_PRESSED)) {
652 ep->bstate &= ~BUTTON3_PRESSED;
653 ep->bstate |= BUTTON3_CLICKED;
657 next->id = INVALID_EVENT;
664 if (_nc_tracing & TRACE_IEVENT) {
665 _trace_slot("before mouse click merge:");
666 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
667 (long) (runp - events),
668 (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX,
674 * Second pass; merge click runs. At this point, click events are
675 * each followed by one invalid event. We merge click events
676 * forward in the queue.
678 * NOTE: There is a problem with this design! If the application
679 * allows enough click events to pile up in the circular queue so
680 * they wrap around, it will cheerfully merge the newest forward
681 * into the oldest, creating a bogus doubleclick and confusing
682 * the queue-traversal logic rather badly. Generally this won't
683 * happen, because calling getmouse() marks old events invalid and
684 * ineligible for merges. The true solution to this problem would
685 * be to timestamp each MEVENT and perform the obvious sanity check,
686 * but the timer element would have to have sub-second resolution,
687 * which would get us into portability trouble.
693 for (ep = runp; next = NEXT(ep), next != eventp; ep = next)
694 if (ep->id != INVALID_EVENT) {
695 if (next->id != INVALID_EVENT)
697 follower = NEXT(next);
698 if (follower->id == INVALID_EVENT)
701 /* merge click events forward */
703 (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))
704 && (follower->bstate &
705 (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) {
706 if ((eventmask & BUTTON1_DOUBLE_CLICKED)
707 && (follower->bstate & BUTTON1_CLICKED)) {
708 follower->bstate &= ~BUTTON1_CLICKED;
709 follower->bstate |= BUTTON1_DOUBLE_CLICKED;
712 if ((eventmask & BUTTON2_DOUBLE_CLICKED)
713 && (follower->bstate & BUTTON2_CLICKED)) {
714 follower->bstate &= ~BUTTON2_CLICKED;
715 follower->bstate |= BUTTON2_DOUBLE_CLICKED;
718 if ((eventmask & BUTTON3_DOUBLE_CLICKED)
719 && (follower->bstate & BUTTON3_CLICKED)) {
720 follower->bstate &= ~BUTTON3_CLICKED;
721 follower->bstate |= BUTTON3_DOUBLE_CLICKED;
725 ep->id = INVALID_EVENT;
728 /* merge double-click events forward */
730 (BUTTON1_DOUBLE_CLICKED
731 | BUTTON2_DOUBLE_CLICKED
732 | BUTTON3_DOUBLE_CLICKED))
733 && (follower->bstate &
734 (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) {
735 if ((eventmask & BUTTON1_TRIPLE_CLICKED)
736 && (follower->bstate & BUTTON1_CLICKED)) {
737 follower->bstate &= ~BUTTON1_CLICKED;
738 follower->bstate |= BUTTON1_TRIPLE_CLICKED;
741 if ((eventmask & BUTTON2_TRIPLE_CLICKED)
742 && (follower->bstate & BUTTON2_CLICKED)) {
743 follower->bstate &= ~BUTTON2_CLICKED;
744 follower->bstate |= BUTTON2_TRIPLE_CLICKED;
747 if ((eventmask & BUTTON3_TRIPLE_CLICKED)
748 && (follower->bstate & BUTTON3_CLICKED)) {
749 follower->bstate &= ~BUTTON3_CLICKED;
750 follower->bstate |= BUTTON3_TRIPLE_CLICKED;
754 ep->id = INVALID_EVENT;
761 if (_nc_tracing & TRACE_IEVENT) {
762 _trace_slot("before mouse event queue compaction:");
763 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
764 (long) (runp - events),
765 (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX,
771 * Now try to throw away trailing events flagged invalid, or that
772 * don't match the current event mask.
774 for (; runcount; prev = PREV(eventp), runcount--)
775 if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) {
779 if (_nc_tracing & TRACE_IEVENT) {
780 _trace_slot("after mouse event queue compaction:");
781 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
782 (long) (runp - events),
783 (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX,
786 for (ep = runp; ep != eventp; ep = NEXT(ep))
787 if (ep->id != INVALID_EVENT)
789 ("_nc_mouse_parse: returning composite mouse event %s at slot %ld",
791 (long) (ep - events)));
794 /* after all this, do we have a valid event? */
795 return (PREV(eventp)->id != INVALID_EVENT);
799 _nc_mouse_wrap(SCREEN * sp GCC_UNUSED)
800 /* release mouse -- called by endwin() before shellout/exit */
802 TR(MY_TRACE, ("_nc_mouse_wrap() called"));
807 mouse_activate(FALSE);
810 /* GPM: pass all mouse events to next client */
818 _nc_mouse_resume(SCREEN * sp GCC_UNUSED)
819 /* re-connect to mouse -- called by doupdate() after shellout */
821 TR(MY_TRACE, ("_nc_mouse_resume() called"));
823 /* xterm: re-enable reporting */
824 if (mousetype == M_XTERM && eventmask)
825 mouse_activate(TRUE);
827 /* GPM: reclaim our event set */
830 /**************************************************************************
832 * Mouse interface entry points for the API
834 **************************************************************************/
837 getmouse(MEVENT * aevent)
838 /* grab a copy of the current mouse event */
840 T((T_CALLED("getmouse(%p)"), aevent));
842 if (aevent && (mousetype != M_NONE)) {
843 /* compute the current-event pointer */
844 MEVENT *prev = PREV(eventp);
846 /* copy the event we find there */
849 TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
851 (long) (prev - events)));
853 prev->id = INVALID_EVENT; /* so the queue slot becomes free */
860 ungetmouse(MEVENT * aevent)
861 /* enqueue a synthesized mouse event to be seen by the next wgetch() */
863 /* stick the given event in the next-free slot */
866 /* bump the next-free pointer into the circular list */
867 eventp = NEXT(eventp);
869 /* push back the notification event on the keyboard queue */
870 return ungetch(KEY_MOUSE);
874 mousemask(mmask_t newmask, mmask_t * oldmask)
875 /* set the mouse event mask */
879 T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask));
882 *oldmask = eventmask;
884 if (!newmask && !initialized)
888 if (mousetype != M_NONE) {
889 eventmask = newmask &
890 (BUTTON_ALT | BUTTON_CTRL | BUTTON_SHIFT
891 | BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED
892 | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED
893 | BUTTON2_PRESSED | BUTTON2_RELEASED | BUTTON2_CLICKED
894 | BUTTON2_DOUBLE_CLICKED | BUTTON2_TRIPLE_CLICKED
895 | BUTTON3_PRESSED | BUTTON3_RELEASED | BUTTON3_CLICKED
896 | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED);
898 mouse_activate(eventmask != 0);
907 wenclose(const WINDOW *win, int y, int x)
908 /* check to see if given window encloses given screen location */
912 return ((win->_begy <= y &&
914 (win->_begx + win->_maxx) >= x &&
915 (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
921 mouseinterval(int maxclick)
922 /* set the maximum mouse interval within which to recognize a click */
927 oldval = SP->_maxclick;
929 SP->_maxclick = maxclick;
931 oldval = DEFAULT_MAXCLICK;
937 /* This may be used by other routines to ask for the existence of mouse
942 return (mousetype == M_NONE ? 0 : 1);
946 wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
950 if (win && pY && pX) {
955 y += win->_begy + win->_yoffset;
957 if (wenclose(win, y, x))
960 if (wenclose(win, y, x)) {
961 y -= (win->_begy + win->_yoffset);
974 /* lib_mouse.c ends here */