1 /****************************************************************************
2 * Copyright (c) 1998,1999 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.
73 # define INCL_DOSPROCESS
74 # include <os2.h> /* Need to include before the others */
77 #include <curses.priv.h>
81 #ifndef LINT /* don't need this for llib-lncurses */
82 #undef buttons /* term.h defines this, and gpm uses it! */
84 #include <linux/keyboard.h> /* defines KG_* macros */
88 MODULE_ID("$Id: lib_mouse.c,v 1.45 1999/10/22 21:39:02 tom Exp $")
90 #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
92 #define INVALID_EVENT -1
95 #define M_XTERM -1 /* use xterm's mouse tracking? */
96 #define M_NONE 0 /* no mouse device */
97 #define M_GPM 1 /* use GPM */
98 #define M_QNX 2 /* QNX mouse on console */
99 #define M_QNX_TERM 3 /* QNX mouse on pterm/xterm (using qansi-m) */
103 static Gpm_Connect gpm_connect;
107 static mmask_t eventmask; /* current event mask */
109 static bool _nc_mouse_parse(int);
110 static void _nc_mouse_resume(SCREEN *);
111 static void _nc_mouse_wrap(SCREEN *);
113 /* maintain a circular list of mouse events */
115 /* The definition of the circular list size (EV_MAX), is in curses.priv.h, so
116 * wgetch() may refer to the size and call _nc_mouse_parse() before circular
119 static MEVENT events[EV_MAX]; /* hold the last mouse event seen */
120 static MEVENT *eventp = events; /* next free slot in event queue */
121 #define NEXT(ep) ((ep == events + EV_MAX - 1) ? events : ep + 1)
122 #define PREV(ep) ((ep == events) ? events + EV_MAX - 1 : ep - 1)
125 static void _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[] = { 0, 1, 3, 2};
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;
226 static void _nc_mouse_init(void)
227 /* initialize the mouse */
236 TR(MY_TRACE, ("_nc_mouse_init() called"));
238 for (i = 0; i < EV_MAX; i++)
239 events[i].id = INVALID_EVENT;
241 /* we know how to recognize mouse events under xterm */
243 && getenv("DISPLAY") != 0)
247 else if (!strncmp(cur_term->type.term_names, "linux", 5))
249 /* GPM: initialize connection to gpm server */
250 gpm_connect.eventMask = GPM_DOWN|GPM_UP;
251 gpm_connect.defaultMask = ~(gpm_connect.eventMask|GPM_HARD);
252 gpm_connect.minMod = 0;
253 gpm_connect.maxMod = ~((1<<KG_SHIFT)|(1<<KG_SHIFTL)|(1<<KG_SHIFTR));
254 if (Gpm_Open (&gpm_connect, 0) >= 0) { /* returns the file-descriptor */
256 SP->_mouse_fd = gpm_fd;
263 if (!mouse_thread && mousetype != M_XTERM && key_mouse) {
265 if (pipe(handles) < 0) {
266 perror("mouse pipe error");
270 if (!mouse_buttons[0]) {
271 char *s = getenv("MOUSE_BUTTONS_123");
273 mouse_buttons[0] = 1;
274 if (s && strlen(s) >= 3) {
275 mouse_buttons[1] = s[0] - '0';
276 mouse_buttons[2] = s[1] - '0';
277 mouse_buttons[3] = s[2] - '0';
280 mouse_wfd = handles[1];
281 M_FD(SP) = handles[0];
283 setmode(handles[0], O_BINARY);
284 setmode(handles[1], O_BINARY);
285 /* Do not use CRT functions, we may single-threaded. */
286 rc = DosCreateThread((unsigned long*)&mouse_thread, mouse_server, 0, 0, 8192);
288 printf("mouse thread error %d=%#x", rc, rc);
295 T(("_nc_mouse_init() set mousetype to %d", mousetype));
298 static bool _nc_mouse_event(SCREEN *sp GCC_UNUSED)
299 /* query to see if there is a pending mouse event */
302 /* GPM: query server for event, return TRUE if we find one */
306 && _nc_timed_wait(2, 0, (int *)0)
307 && Gpm_GetEvent(&ev) == 1)
309 eventp->id = 0; /* there's only one mouse... */
312 switch (ev.type & 0x0f)
315 if (ev.buttons & GPM_B_LEFT) eventp->bstate |= BUTTON1_PRESSED;
316 if (ev.buttons & GPM_B_MIDDLE) eventp->bstate |= BUTTON2_PRESSED;
317 if (ev.buttons & GPM_B_RIGHT) eventp->bstate |= BUTTON3_PRESSED;
320 if (ev.buttons & GPM_B_LEFT) eventp->bstate |= BUTTON1_RELEASED;
321 if (ev.buttons & GPM_B_MIDDLE) eventp->bstate |= BUTTON2_RELEASED;
322 if (ev.buttons & GPM_B_RIGHT) eventp->bstate |= BUTTON3_RELEASED;
328 eventp->x = ev.x - 1;
329 eventp->y = ev.y - 1;
332 /* bump the next-free pointer into the circular list */
333 eventp = NEXT(eventp);
338 /* xterm: never have to query, mouse events are in the keyboard stream */
339 return(FALSE); /* no event waiting */
342 static bool _nc_mouse_inline(SCREEN *sp)
343 /* mouse report received in the keyboard stream -- parse its info */
345 TR(MY_TRACE, ("_nc_mouse_inline() called"));
347 if (mousetype == M_XTERM)
349 unsigned char kbuf[4];
354 /* This code requires that your xterm entry contain the kmous
355 * capability and that it be set to the \E[M documented in the
356 * Xterm Control Sequences reference. This is how we
357 * arrange for mouse events to be reported via a KEY_MOUSE
358 * return value from wgetch(). After this value is received,
359 * _nc_mouse_inline() gets called and is immediately
360 * responsible for parsing the mouse status information
361 * following the prefix.
363 * The following quotes from the ctrlseqs.ms document in the
364 * X distribution, describing the X mouse tracking feature:
366 * Parameters for all mouse tracking escape sequences
367 * generated by xterm encode numeric parameters in a single
368 * character as value+040. For example, ! is 1.
370 * On button press or release, xterm sends ESC [ M CbCxCy.
371 * The low two bits of Cb encode button information: 0=MB1
372 * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The
373 * upper bits encode what modifiers were down when the
374 * button was pressed and are added together. 4=Shift,
375 * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates
376 * of the mouse event. The upper left corner is (1,1).
378 * (End quote) By the time we get here, we've eaten the
379 * key prefix. FYI, the loop below is necessary because
380 * mouse click info isn't guaranteed to present as a
381 * single clist item. It always does under Linux but often
382 * fails to under Solaris.
384 for (grabbed = 0; grabbed < 3; grabbed += res)
387 /* For VIO mouse we add extra bit 64 to disambiguate button-up. */
389 res = read( M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3);
391 res = read(sp->_ifd, kbuf + grabbed, 3-grabbed);
398 TR(TRACE_IEVENT, ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
400 eventp->id = 0; /* there's only one mouse... */
402 /* processing code goes here */
404 switch (kbuf[0] & 0x3)
407 eventp->bstate = BUTTON1_PRESSED;
410 eventp->bstate = BUTTON1_RELEASED;
415 eventp->bstate = BUTTON2_PRESSED;
418 eventp->bstate = BUTTON2_RELEASED;
423 eventp->bstate = BUTTON3_PRESSED;
426 eventp->bstate = BUTTON3_RELEASED;
432 * Release events aren't reported for individual buttons,
433 * just for the button set as a whole...
440 * ...however, because there are no kinds of mouse events under
441 * xterm that can intervene between press and release, we can
442 * deduce which buttons were actually released by looking at the
446 if (!(prev->bstate & BUTTON1_PRESSED))
447 eventp->bstate &=~ BUTTON1_RELEASED;
448 if (!(prev->bstate & BUTTON2_PRESSED))
449 eventp->bstate &=~ BUTTON2_RELEASED;
450 if (!(prev->bstate & BUTTON3_PRESSED))
451 eventp->bstate &=~ BUTTON3_RELEASED;
456 eventp->bstate |= BUTTON_SHIFT;
459 eventp->bstate |= BUTTON_ALT;
462 eventp->bstate |= BUTTON_CTRL;
465 eventp->x = (kbuf[1] - ' ') - 1;
466 eventp->y = (kbuf[2] - ' ') - 1;
467 TR(MY_TRACE, ("_nc_mouse_inline: primitive mouse-event %s has slot %ld",
469 (long) (eventp - events)));
471 /* bump the next-free pointer into the circular list */
472 eventp = NEXT(eventp);
473 #if 0 /* this return would be needed for QNX's mods to lib_getch.c */
481 static void mouse_activate(bool on)
483 if (!on && !initialized)
492 #ifdef NCURSES_EXT_FUNCS
493 keyok(KEY_MOUSE, on);
495 TPUTS_TRACE("xterm mouse initialization");
504 SP->_mouse_fd = gpm_fd;
508 /* Make runtime binding to cut down on object size of applications that
509 * do not use the mouse (e.g., 'clear').
511 SP->_mouse_event = _nc_mouse_event;
512 SP->_mouse_inline = _nc_mouse_inline;
513 SP->_mouse_parse = _nc_mouse_parse;
514 SP->_mouse_resume = _nc_mouse_resume;
515 SP->_mouse_wrap = _nc_mouse_wrap;
521 TPUTS_TRACE("xterm mouse deinitialization");
537 /**************************************************************************
539 * Device-independent code
541 **************************************************************************/
543 static bool _nc_mouse_parse(int runcount)
544 /* parse a run of atomic mouse events into a gesture */
546 MEVENT *ep, *runp, *next, *prev = PREV(eventp);
550 TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount));
553 * When we enter this routine, the event list next-free pointer
554 * points just past a run of mouse events that we know were separated
555 * in time by less than the critical click interval. The job of this
556 * routine is to collaps this run into a single higher-level event
559 * We accomplish this in two passes. The first pass merges press/release
560 * pairs into click events. The second merges runs of click events into
561 * double or triple-click events.
563 * It's possible that the run may not resolve to a single event (for
564 * example, if the user quadruple-clicks). If so, leading events
565 * in the run are ignored.
567 * Note that this routine is independent of the format of the specific
568 * format of the pointing-device's reports. We can use it to parse
569 * gestures on anything that reports press/release events on a per-
570 * button basis, as long as the device-dependent mouse code puts stuff
571 * on the queue in MEVENT format.
575 TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %ld",
577 (long) (prev - events)));
578 return (prev->id >= 0)
579 ? ((prev->bstate & eventmask) ? TRUE : FALSE)
583 /* find the start of the run */
585 for (n = runcount; n > 0; n--) {
590 if (_nc_tracing & TRACE_IEVENT)
592 _trace_slot("before mouse press/release merge:");
593 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
594 (long) (runp - events),
595 (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX,
600 /* first pass; merge press/release pairs */
603 for (ep = runp; next = NEXT(ep), next != eventp; ep = next)
605 if (ep->x == next->x && ep->y == next->y
606 && (ep->bstate & (BUTTON1_PRESSED|BUTTON2_PRESSED|BUTTON3_PRESSED))
607 && (!(ep->bstate & BUTTON1_PRESSED)
608 == !(next->bstate & BUTTON1_RELEASED))
609 && (!(ep->bstate & BUTTON2_PRESSED)
610 == !(next->bstate & BUTTON2_RELEASED))
611 && (!(ep->bstate & BUTTON3_PRESSED)
612 == !(next->bstate & BUTTON3_RELEASED))
615 if ((eventmask & BUTTON1_CLICKED)
616 && (ep->bstate & BUTTON1_PRESSED))
618 ep->bstate &=~ BUTTON1_PRESSED;
619 ep->bstate |= BUTTON1_CLICKED;
622 if ((eventmask & BUTTON2_CLICKED)
623 && (ep->bstate & BUTTON2_PRESSED))
625 ep->bstate &=~ BUTTON2_PRESSED;
626 ep->bstate |= BUTTON2_CLICKED;
629 if ((eventmask & BUTTON3_CLICKED)
630 && (ep->bstate & BUTTON3_PRESSED))
632 ep->bstate &=~ BUTTON3_PRESSED;
633 ep->bstate |= BUTTON3_CLICKED;
637 next->id = INVALID_EVENT;
644 if (_nc_tracing & TRACE_IEVENT)
646 _trace_slot("before mouse click merge:");
647 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
648 (long) (runp - events),
649 (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX,
655 * Second pass; merge click runs. At this point, click events are
656 * each followed by one invalid event. We merge click events
657 * forward in the queue.
659 * NOTE: There is a problem with this design! If the application
660 * allows enough click events to pile up in the circular queue so
661 * they wrap around, it will cheerfully merge the newest forward
662 * into the oldest, creating a bogus doubleclick and confusing
663 * the queue-traversal logic rather badly. Generally this won't
664 * happen, because calling getmouse() marks old events invalid and
665 * ineligible for merges. The true solution to this problem would
666 * be to timestamp each MEVENT and perform the obvious sanity check,
667 * but the timer element would have to have sub-second resolution,
668 * which would get us into portability trouble.
674 for (ep = runp; next = NEXT(ep), next != eventp; ep = next)
675 if (ep->id != INVALID_EVENT)
677 if (next->id != INVALID_EVENT)
679 follower = NEXT(next);
680 if (follower->id == INVALID_EVENT)
683 /* merge click events forward */
685 (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))
686 && (follower->bstate &
687 (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)))
689 if ((eventmask & BUTTON1_DOUBLE_CLICKED)
690 && (follower->bstate & BUTTON1_CLICKED))
692 follower->bstate &=~ BUTTON1_CLICKED;
693 follower->bstate |= BUTTON1_DOUBLE_CLICKED;
696 if ((eventmask & BUTTON2_DOUBLE_CLICKED)
697 && (follower->bstate & BUTTON2_CLICKED))
699 follower->bstate &=~ BUTTON2_CLICKED;
700 follower->bstate |= BUTTON2_DOUBLE_CLICKED;
703 if ((eventmask & BUTTON3_DOUBLE_CLICKED)
704 && (follower->bstate & BUTTON3_CLICKED))
706 follower->bstate &=~ BUTTON3_CLICKED;
707 follower->bstate |= BUTTON3_DOUBLE_CLICKED;
711 ep->id = INVALID_EVENT;
714 /* merge double-click events forward */
716 (BUTTON1_DOUBLE_CLICKED
717 | BUTTON2_DOUBLE_CLICKED
718 | BUTTON3_DOUBLE_CLICKED))
719 && (follower->bstate &
720 (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)))
722 if ((eventmask & BUTTON1_TRIPLE_CLICKED)
723 && (follower->bstate & BUTTON1_CLICKED))
725 follower->bstate &=~ BUTTON1_CLICKED;
726 follower->bstate |= BUTTON1_TRIPLE_CLICKED;
729 if ((eventmask & BUTTON2_TRIPLE_CLICKED)
730 && (follower->bstate & BUTTON2_CLICKED))
732 follower->bstate &=~ BUTTON2_CLICKED;
733 follower->bstate |= BUTTON2_TRIPLE_CLICKED;
736 if ((eventmask & BUTTON3_TRIPLE_CLICKED)
737 && (follower->bstate & BUTTON3_CLICKED))
739 follower->bstate &=~ BUTTON3_CLICKED;
740 follower->bstate |= BUTTON3_TRIPLE_CLICKED;
744 ep->id = INVALID_EVENT;
751 if (_nc_tracing & TRACE_IEVENT)
753 _trace_slot("before mouse event queue compaction:");
754 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
755 (long) (runp - events),
756 (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX,
762 * Now try to throw away trailing events flagged invalid, or that
763 * don't match the current event mask.
765 for (; runcount; prev = PREV(eventp), runcount--)
766 if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) {
771 if (_nc_tracing & TRACE_IEVENT)
773 _trace_slot("after mouse event queue compaction:");
774 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
775 (long) (runp - events),
776 (long) ((eventp - events) + (EV_MAX-1)) % EV_MAX,
779 for (ep = runp; ep != eventp; ep = NEXT(ep))
780 if (ep->id != INVALID_EVENT)
781 TR(MY_TRACE, ("_nc_mouse_parse: returning composite mouse event %s at slot %ld",
783 (long) (ep - events)));
786 /* after all this, do we have a valid event? */
787 return(PREV(eventp)->id != INVALID_EVENT);
790 static void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED)
791 /* release mouse -- called by endwin() before shellout/exit */
793 TR(MY_TRACE, ("_nc_mouse_wrap() called"));
798 mouse_activate(FALSE);
801 /* GPM: pass all mouse events to next client */
808 static void _nc_mouse_resume(SCREEN *sp GCC_UNUSED)
809 /* re-connect to mouse -- called by doupdate() after shellout */
811 TR(MY_TRACE, ("_nc_mouse_resume() called"));
813 /* xterm: re-enable reporting */
814 if (mousetype == M_XTERM && eventmask)
815 mouse_activate(TRUE);
817 /* GPM: reclaim our event set */
820 /**************************************************************************
822 * Mouse interface entry points for the API
824 **************************************************************************/
826 int getmouse(MEVENT *aevent)
827 /* grab a copy of the current mouse event */
829 T((T_CALLED("getmouse(%p)"), aevent));
831 if (aevent && (mousetype != M_NONE))
833 /* compute the current-event pointer */
834 MEVENT *prev = PREV(eventp);
836 /* copy the event we find there */
839 TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
841 (long) (prev - events)));
843 prev->id = INVALID_EVENT; /* so the queue slot becomes free */
849 int ungetmouse(MEVENT *aevent)
850 /* enqueue a synthesized mouse event to be seen by the next wgetch() */
852 /* stick the given event in the next-free slot */
855 /* bump the next-free pointer into the circular list */
856 eventp = NEXT(eventp);
858 /* push back the notification event on the keyboard queue */
859 return ungetch(KEY_MOUSE);
862 mmask_t mousemask(mmask_t newmask, mmask_t *oldmask)
863 /* set the mouse event mask */
867 T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask));
870 *oldmask = eventmask;
872 if (!newmask && !initialized)
876 if ( mousetype != M_NONE )
878 eventmask = newmask &
879 (BUTTON_ALT | BUTTON_CTRL | BUTTON_SHIFT
880 | BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED
881 | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED
882 | BUTTON2_PRESSED | BUTTON2_RELEASED | BUTTON2_CLICKED
883 | BUTTON2_DOUBLE_CLICKED | BUTTON2_TRIPLE_CLICKED
884 | BUTTON3_PRESSED | BUTTON3_RELEASED | BUTTON3_CLICKED
885 | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED);
887 mouse_activate(eventmask != 0);
895 bool wenclose(const WINDOW *win, int y, int x)
896 /* check to see if given window encloses given screen location */
901 return ((win->_begy <= y &&
903 (win->_begx + win->_maxx) >= x &&
904 (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
909 int mouseinterval(int maxclick)
910 /* set the maximum mouse interval within which to recognize a click */
915 oldval = SP->_maxclick;
917 SP->_maxclick = maxclick;
919 oldval = DEFAULT_MAXCLICK;
925 /* This may be used by other routines to ask for the existence of mouse
927 int _nc_has_mouse(void) {
928 return (mousetype==M_NONE ? 0:1);
931 bool wmouse_trafo(const WINDOW* win, int* pY, int* pX, bool to_screen)
937 int y = *pY; int x = *pX;
941 y += win->_begy + win->_yoffset;
943 if (wenclose(win,y,x))
948 if (wenclose(win,y,x))
950 y -= (win->_begy + win->_yoffset);
964 /* lib_mouse.c ends here */