1 /****************************************************************************
2 * Copyright (c) 1998-2011,2012 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 * and: Thomas E. Dickey 1996-on *
33 * and: Juergen Pfeifer 2008 *
34 ****************************************************************************/
37 * This module is intended to encapsulate ncurses's interface to pointing
40 * The primary method used is xterm's internal mouse-tracking facility.
41 * Additional methods depend on the platform:
42 * Alessandro Rubini's GPM server (Linux)
44 * special-purpose mouse interface for OS/2 EMX.
46 * Notes for implementors of new mouse-interface methods:
48 * The code is logically split into a lower level that accepts event reports
49 * in a device-dependent format and an upper level that parses mouse gestures
50 * and filters events. The mediating data structure is a circular queue of
53 * Functionally, the lower level's job is to pick up primitive events and
54 * put them on the circular queue. This can happen in one of two ways:
55 * either (a) _nc_mouse_event() detects a series of incoming mouse reports
56 * and queues them, or (b) code in lib_getch.c detects the kmous prefix in
57 * the keyboard input stream and calls _nc_mouse_inline to queue up a series
58 * of adjacent mouse reports.
60 * In either case, _nc_mouse_parse() should be called after the series is
61 * accepted to parse the digested mouse reports (low-level MEVENTs) into
62 * a gesture (a high-level or composite MEVENT).
64 * Don't be too shy about adding new event types or modifiers, if you can find
65 * room for them in the 32-bit mask. The API is written so that users get
66 * feedback on which theoretical event types they won't see when they call
67 * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being
68 * used yet, and a couple of bits open at the high end.
77 # define INCL_DOSPROCESS
78 # include <os2.h> /* Need to include before the others */
81 #include <curses.priv.h>
84 #define CUR SP_TERMTYPE
87 MODULE_ID("$Id: lib_mouse.c,v 1.134 2012/01/21 19:21:29 KO.Myung-Hun Exp $")
92 #include <linux/keyboard.h> /* defines KG_* macros */
95 /* use dynamic loader to avoid linkage dependency */
99 #define my_RTLD RTLD_NOW
102 #define my_RTLD RTLD_LAZY
106 #endif /* RTLD_NOW */
107 #endif /* HAVE_LIBDL */
109 #endif /* USE_GPM_SUPPORT */
112 #undef buttons /* symbol conflict in consio.h */
113 #undef mouse_info /* symbol conflict in consio.h */
114 #include <osreldate.h>
115 #if (__FreeBSD_version >= 400017)
116 #include <sys/consio.h>
117 #include <sys/fbio.h>
119 #include <machine/console.h>
121 #endif /* use_SYSMOUSE */
124 #include <sys/socket.h>
125 #define pipe(handles) socketpair(AF_LOCAL, SOCK_STREAM, 0, handles)
126 #define DosWrite(hfile, pbuffer, cbwrite, pcbactual) \
127 write(hfile, pbuffer, cbwrite)
128 #define DosExit(action, result ) /* do nothing */
129 #define DosCreateThread(ptid, pfn, param, flag, cbStack) \
130 (*(ptid) = _beginthread(pfn, NULL, cbStack, \
131 (void *)param), (*(ptid) == -1))
134 #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
136 #define MASK_RELEASE(x) (mmask_t) NCURSES_MOUSE_MASK(x, 001)
137 #define MASK_PRESS(x) (mmask_t) NCURSES_MOUSE_MASK(x, 002)
138 #define MASK_CLICK(x) (mmask_t) NCURSES_MOUSE_MASK(x, 004)
139 #define MASK_DOUBLE_CLICK(x) (mmask_t) NCURSES_MOUSE_MASK(x, 010)
140 #define MASK_TRIPLE_CLICK(x) (mmask_t) NCURSES_MOUSE_MASK(x, 020)
141 #define MASK_RESERVED_EVENT(x) (mmask_t) NCURSES_MOUSE_MASK(x, 040)
143 #if NCURSES_MOUSE_VERSION == 1
144 #define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED)
145 #define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED)
146 #define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED)
147 #define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED)
148 #define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED)
149 #define MAX_BUTTONS 4
151 #define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED | BUTTON5_CLICKED)
152 #define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED)
153 #define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED | BUTTON5_RELEASED)
154 #define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED | BUTTON5_DOUBLE_CLICKED)
155 #define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED | BUTTON5_TRIPLE_CLICKED)
156 #define MAX_BUTTONS 5
159 #define INVALID_EVENT -1
160 #define NORMAL_EVENT 0
162 #define ValidEvent(ep) ((ep)->id != INVALID_EVENT)
163 #define Invalidate(ep) (ep)->id = INVALID_EVENT
167 #ifndef LIBGPM_SONAME
168 #define LIBGPM_SONAME "libgpm.so"
171 #define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(sp->_dlopen_gpm, #name))
173 #endif /* USE_GPM_SUPPORT */
175 static bool _nc_mouse_parse(SCREEN *, int);
176 static void _nc_mouse_resume(SCREEN *);
177 static void _nc_mouse_wrap(SCREEN *);
179 /* maintain a circular list of mouse events */
181 #define FirstEV(sp) ((sp)->_mouse_events)
182 #define LastEV(sp) ((sp)->_mouse_events + EV_MAX - 1)
185 #define NEXT(ep) ((ep >= LastEV(SP_PARM)) \
190 #define PREV(ep) ((ep <= FirstEV(SP_PARM)) \
194 #define IndexEV(sp, ep) (ep - FirstEV(sp))
196 #define RunParams(sp, eventp, runp) \
197 (long) IndexEV(sp, runp), \
198 (long) (IndexEV(sp, eventp) + (EV_MAX - 1)) % EV_MAX
202 _trace_slot(SCREEN *sp, const char *tag)
208 for (ep = FirstEV(sp); ep <= LastEV(sp); ep++)
209 _tracef("mouse event queue slot %ld = %s",
210 (long) IndexEV(sp, ep),
211 _nc_tracemouse(sp, ep));
220 # define M_FD(sp) sp->_mouse_fd
223 write_event(SCREEN *sp, int down, int button, int x, int y)
226 unsigned long ignore;
228 strncpy(buf, key_mouse, 3); /* should be "\033[M" */
229 buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40);
230 buf[4] = ' ' + x - LEFT_COL + 1;
231 buf[5] = ' ' + y - TOP_ROW + 1;
232 DosWrite(sp->_emxmouse_wfd, buf, 6, &ignore);
237 mouse_server(void *param)
239 mouse_server(unsigned long param)
242 SCREEN *sp = (SCREEN *) param;
243 unsigned short fWait = MOU_WAIT;
244 /* NOPTRRECT mourt = { 0,0,24,79 }; */
247 unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN;
253 /* open the handle for the mouse */
254 if (MouOpen(NULL, &hmou) == 0) {
255 rc = MouSetEventMask(&mask, hmou);
256 if (rc) { /* retry with 2 buttons */
257 mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN;
258 rc = MouSetEventMask(&mask, hmou);
261 if (rc == 0 && MouDrawPtr(hmou) == 0) {
263 /* sit and wait on the event queue */
264 rc = MouReadEventQue(&mouev, &fWait, hmou);
266 sprintf(err, "Error reading mouse queue, rc=%lu.\r\n", rc);
269 if (!sp->_emxmouse_activated)
273 * OS/2 numbers a 3-button mouse inconsistently from other
279 if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN)
280 write_event(sp, mouev.fs & MOUSE_BN1_DOWN,
281 sp->_emxmouse_buttons[1], mouev.col, mouev.row);
282 if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN)
283 write_event(sp, mouev.fs & MOUSE_BN2_DOWN,
284 sp->_emxmouse_buttons[3], mouev.col, mouev.row);
285 if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN)
286 write_event(sp, mouev.fs & MOUSE_BN3_DOWN,
287 sp->_emxmouse_buttons[2], mouev.col, mouev.row);
293 sprintf(err, "Error setting event mask, buttons=%d, rc=%lu.\r\n",
296 DosWrite(2, err, strlen(err), &rc);
299 DosExit(EXIT_THREAD, 0L);
302 #endif /* USE_EMX_MOUSE */
306 sysmouse_server(SCREEN *sp)
308 struct mouse_info the_mouse;
311 the_mouse.operation = MOUSE_GETINFO;
313 && sp->_mouse_fd >= 0
314 && sp->_sysmouse_tail < FIFO_SIZE
315 && ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
317 if (sp->_sysmouse_head > sp->_sysmouse_tail) {
318 sp->_sysmouse_tail = 0;
319 sp->_sysmouse_head = 0;
321 work = &(sp->_sysmouse_fifo[sp->_sysmouse_tail]);
322 memset(work, 0, sizeof(*work));
323 work->id = NORMAL_EVENT; /* there's only one mouse... */
325 sp->_sysmouse_old_buttons = sp->_sysmouse_new_buttons;
326 sp->_sysmouse_new_buttons = the_mouse.u.data.buttons & 0x7;
328 if (sp->_sysmouse_new_buttons) {
329 if (sp->_sysmouse_new_buttons & 1)
330 work->bstate |= BUTTON1_PRESSED;
331 if (sp->_sysmouse_new_buttons & 2)
332 work->bstate |= BUTTON2_PRESSED;
333 if (sp->_sysmouse_new_buttons & 4)
334 work->bstate |= BUTTON3_PRESSED;
336 if (sp->_sysmouse_old_buttons & 1)
337 work->bstate |= BUTTON1_RELEASED;
338 if (sp->_sysmouse_old_buttons & 2)
339 work->bstate |= BUTTON2_RELEASED;
340 if (sp->_sysmouse_old_buttons & 4)
341 work->bstate |= BUTTON3_RELEASED;
344 /* for cosmetic bug in syscons.c on FreeBSD 3.[34] */
345 the_mouse.operation = MOUSE_HIDE;
346 ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
347 the_mouse.operation = MOUSE_SHOW;
348 ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
351 * We're only interested if the button is pressed or released.
352 * FIXME: implement continuous event-tracking.
354 if (sp->_sysmouse_new_buttons != sp->_sysmouse_old_buttons) {
355 sp->_sysmouse_tail += 1;
357 work->x = the_mouse.u.data.x / sp->_sysmouse_char_width;
358 work->y = the_mouse.u.data.y / sp->_sysmouse_char_height;
363 handle_sysmouse(int sig GCC_UNUSED)
365 sysmouse_server(CURRENT_SCREEN);
367 #endif /* USE_SYSMOUSE */
369 #ifndef USE_TERM_DRIVER
370 #define xterm_kmous "\033[M"
373 init_xterm_mouse(SCREEN *sp)
375 sp->_mouse_type = M_XTERM;
376 sp->_mouse_xtermcap = tigetstr("XM");
377 if (!VALID_STRING(sp->_mouse_xtermcap))
378 sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
383 enable_xterm_mouse(SCREEN *sp, int enable)
386 sp->_emxmouse_activated = enable;
388 NCURSES_SP_NAME(_nc_putp) (NCURSES_SP_ARGx
390 TPARM_1(sp->_mouse_xtermcap, enable));
392 sp->_mouse_active = enable;
397 allow_gpm_mouse(void)
401 /* GPM does printf's without checking if stdout is a terminal */
402 if (isatty(fileno(stdout))) {
403 char *list = getenv("NCURSES_GPM_TERMS");
404 char *env = getenv("TERM");
407 result = _nc_name_match(list, env, "|:");
410 /* GPM checks the beginning of the $TERM variable to decide if it
411 * should pass xterm events through. There is no real advantage in
412 * allowing GPM to do this. Recent versions relax that check, and
413 * pretend that GPM can work with any terminal having the kmous
414 * capability. Perhaps that works for someone. If so, they can
415 * set the environment variable (above).
417 if (env != 0 && strstr(env, "linux") != 0) {
427 unload_gpm_library(SCREEN *sp)
429 if (sp->_dlopen_gpm != 0) {
430 T(("unload GPM library"));
431 sp->_mouse_gpm_loaded = FALSE;
433 dlclose(sp->_dlopen_gpm);
439 load_gpm_library(SCREEN *sp)
441 sp->_mouse_gpm_found = FALSE;
442 if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
443 if (GET_DLSYM(gpm_fd) == 0 ||
444 GET_DLSYM(Gpm_Open) == 0 ||
445 GET_DLSYM(Gpm_Close) == 0 ||
446 GET_DLSYM(Gpm_GetEvent) == 0) {
447 T(("GPM initialization failed: %s", dlerror()));
448 unload_gpm_library(sp);
450 sp->_mouse_gpm_found = TRUE;
451 sp->_mouse_gpm_loaded = TRUE;
458 enable_gpm_mouse(SCREEN *sp, bool enable)
462 T((T_CALLED("enable_gpm_mouse(%d)"), enable));
464 if (enable && !sp->_mouse_active) {
466 if (sp->_mouse_gpm_found && !sp->_mouse_gpm_loaded) {
467 load_gpm_library(sp);
470 if (sp->_mouse_gpm_loaded) {
473 /* GPM: initialize connection to gpm server */
474 sp->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP;
475 sp->_mouse_gpm_connect.defaultMask =
476 (unsigned short) (~(sp->_mouse_gpm_connect.eventMask | GPM_HARD));
477 sp->_mouse_gpm_connect.minMod = 0;
478 sp->_mouse_gpm_connect.maxMod =
479 (unsigned short) (~((1 << KG_SHIFT) |
483 * Note: GPM hardcodes \E[?1001s and \E[?1000h during its open.
484 * The former is recognized by wscons (SunOS), and the latter by
485 * xterm. Those will not show up in ncurses' traces.
487 code = my_Gpm_Open(&sp->_mouse_gpm_connect, 0);
488 result = (code >= 0);
491 * GPM can return a -2 if it is trying to do something with xterm.
492 * Ignore that, since it conflicts with our use of stdin.
500 sp->_mouse_active = result;
501 T(("GPM open %s", result ? "succeeded" : "failed"));
503 if (!enable && sp->_mouse_active) {
504 /* GPM: close connection to gpm server */
506 sp->_mouse_active = FALSE;
513 unload_gpm_library(sp);
518 #endif /* USE_GPM_SUPPORT */
521 initialize_mousetype(SCREEN *sp)
523 T((T_CALLED("initialize_mousetype()")));
525 /* Try gpm first, because gpm may be configured to run in xterm */
527 if (allow_gpm_mouse()) {
528 if (!sp->_mouse_gpm_loaded) {
530 load_gpm_library(sp);
531 #else /* !HAVE_LIBDL */
532 sp->_mouse_gpm_found = TRUE;
533 sp->_mouse_gpm_loaded = TRUE;
538 * The gpm_fd file-descriptor may be negative (xterm). So we have to
539 * maintain our notion of whether the mouse connection is active
540 * without testing the file-descriptor.
542 if (sp->_mouse_gpm_found && enable_gpm_mouse(sp, TRUE)) {
543 sp->_mouse_type = M_GPM;
544 sp->_mouse_fd = *(my_gpm_fd);
545 T(("GPM mouse_fd %d", sp->_mouse_fd));
549 #endif /* USE_GPM_SUPPORT */
553 if (!sp->_emxmouse_thread
554 && strstr(TerminalOf(sp)->type.term_names, "xterm") == 0
558 if (pipe(handles) < 0) {
559 perror("mouse pipe error");
564 if (!sp->_emxmouse_buttons[0]) {
565 char *s = getenv("MOUSE_BUTTONS_123");
567 sp->_emxmouse_buttons[0] = 1;
568 if (s && strlen(s) >= 3) {
569 sp->_emxmouse_buttons[1] = s[0] - '0';
570 sp->_emxmouse_buttons[2] = s[1] - '0';
571 sp->_emxmouse_buttons[3] = s[2] - '0';
573 sp->_emxmouse_buttons[1] = 1;
574 sp->_emxmouse_buttons[2] = 3;
575 sp->_emxmouse_buttons[3] = 2;
578 sp->_emxmouse_wfd = handles[1];
579 M_FD(sp) = handles[0];
581 setmode(handles[0], O_BINARY);
582 setmode(handles[1], O_BINARY);
583 /* Do not use CRT functions, we may single-threaded. */
584 rc = DosCreateThread((unsigned long *) &sp->_emxmouse_thread,
585 mouse_server, (long) sp, 0, 8192);
587 printf("mouse thread error %d=%#x", rc, rc);
589 sp->_mouse_type = M_XTERM;
594 #endif /* USE_EMX_MOUSE */
598 struct mouse_info the_mouse;
599 char *the_device = 0;
601 if (isatty(sp->_ifd))
602 the_device = ttyname(sp->_ifd);
604 the_device = "/dev/tty";
606 sp->_mouse_fd = open(the_device, O_RDWR);
608 if (sp->_mouse_fd >= 0) {
610 * sysmouse does not have a usable user interface for obtaining
611 * mouse events. The logical way to proceed (reading data on a
612 * stream) only works if one opens the device as root. Even in
613 * that mode, careful examination shows we lose events
614 * occasionally. The interface provided for user programs is to
615 * establish a signal handler. really.
617 * Take over SIGUSR2 for this purpose since SIGUSR1 is more
618 * likely to be used by an application. getch() will have to
619 * handle the misleading EINTR's.
621 signal(SIGUSR2, SIG_IGN);
622 the_mouse.operation = MOUSE_MODE;
623 the_mouse.u.mode.mode = 0;
624 the_mouse.u.mode.signal = SIGUSR2;
625 if (ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) {
626 signal(SIGUSR2, handle_sysmouse);
627 the_mouse.operation = MOUSE_SHOW;
628 ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse);
630 #if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) /* FreeBSD > 2.x */
632 #ifndef FBIO_GETMODE /* FreeBSD 3.x */
633 #define FBIO_GETMODE CONS_GET
634 #define FBIO_MODEINFO CONS_MODEINFO
635 #endif /* FBIO_GETMODE */
636 video_info_t the_video;
638 if (ioctl(sp->_mouse_fd,
640 &the_video.vi_mode) != -1
641 && ioctl(sp->_mouse_fd,
644 sp->_sysmouse_char_width = the_video.vi_cwidth;
645 sp->_sysmouse_char_height = the_video.vi_cheight;
648 #endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */
650 if (sp->_sysmouse_char_width <= 0)
651 sp->_sysmouse_char_width = 8;
652 if (sp->_sysmouse_char_height <= 0)
653 sp->_sysmouse_char_height = 16;
654 sp->_mouse_type = M_SYSMOUSE;
659 #endif /* USE_SYSMOUSE */
661 #ifdef USE_TERM_DRIVER
662 CallDriver(sp, initmouse);
664 /* we know how to recognize mouse events under "xterm" */
665 if (key_mouse != 0) {
666 if (!strcmp(key_mouse, xterm_kmous)
667 || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
668 init_xterm_mouse(sp);
670 } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
671 if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
672 init_xterm_mouse(sp);
680 _nc_mouse_init(SCREEN *sp)
681 /* initialize the mouse */
687 if (!sp->_mouse_initialized) {
688 sp->_mouse_initialized = TRUE;
690 TR(MY_TRACE, ("_nc_mouse_init() called"));
692 sp->_mouse_eventp = FirstEV(sp);
693 for (i = 0; i < EV_MAX; i++)
694 Invalidate(sp->_mouse_events + i);
696 initialize_mousetype(sp);
698 T(("_nc_mouse_init() set mousetype to %d", sp->_mouse_type));
700 result = sp->_mouse_initialized;
706 * Query to see if there is a pending mouse event. This is called from
707 * fifo_push() in lib_getch.c
710 _nc_mouse_event(SCREEN *sp)
712 MEVENT *eventp = sp->_mouse_eventp;
717 switch (sp->_mouse_type) {
719 /* xterm: never have to query, mouse events are in the keyboard stream */
724 int i, res = read(M_FD(sp), &kbuf, 3); /* Eat the prefix */
726 printf("Got %d chars instead of 3 for prefix.\n", res);
727 for (i = 0; i < res; i++) {
728 if (kbuf[i] != key_mouse[i])
729 printf("Got char %d instead of %d for prefix.\n",
730 (int) kbuf[i], (int) key_mouse[i]);
734 #endif /* USE_EMX_MOUSE */
739 if (sp->_mouse_fd >= 0) {
740 /* query server for event, return TRUE if we find one */
743 switch (my_Gpm_GetEvent(&ev)) {
745 /* Connection closed, drop the mouse. */
749 /* there's only one mouse... */
750 eventp->id = NORMAL_EVENT;
753 switch (ev.type & 0x0f) {
755 if (ev.buttons & GPM_B_LEFT)
756 eventp->bstate |= BUTTON1_PRESSED;
757 if (ev.buttons & GPM_B_MIDDLE)
758 eventp->bstate |= BUTTON2_PRESSED;
759 if (ev.buttons & GPM_B_RIGHT)
760 eventp->bstate |= BUTTON3_PRESSED;
763 if (ev.buttons & GPM_B_LEFT)
764 eventp->bstate |= BUTTON1_RELEASED;
765 if (ev.buttons & GPM_B_MIDDLE)
766 eventp->bstate |= BUTTON2_RELEASED;
767 if (ev.buttons & GPM_B_RIGHT)
768 eventp->bstate |= BUTTON3_RELEASED;
771 eventp->bstate |= REPORT_MOUSE_POSITION;
775 eventp->x = ev.x - 1;
776 eventp->y = ev.y - 1;
779 /* bump the next-free pointer into the circular list */
780 sp->_mouse_eventp = NEXT(eventp);
790 if (sp->_sysmouse_head < sp->_sysmouse_tail) {
791 *eventp = sp->_sysmouse_fifo[sp->_sysmouse_head];
794 * Point the fifo-head to the next possible location. If there
795 * are none, reset the indices. This may be interrupted by the
796 * signal handler, doing essentially the same reset.
798 sp->_sysmouse_head += 1;
799 if (sp->_sysmouse_head == sp->_sysmouse_tail) {
800 sp->_sysmouse_tail = 0;
801 sp->_sysmouse_head = 0;
804 /* bump the next-free pointer into the circular list */
805 sp->_mouse_eventp = eventp = NEXT(eventp);
809 #endif /* USE_SYSMOUSE */
811 #ifdef USE_TERM_DRIVER
813 while (sp->_drv_mouse_head < sp->_drv_mouse_tail) {
814 *eventp = sp->_drv_mouse_fifo[sp->_drv_mouse_head];
817 * Point the fifo-head to the next possible location. If there
818 * are none, reset the indices.
820 sp->_drv_mouse_head += 1;
821 if (sp->_drv_mouse_head == sp->_drv_mouse_tail) {
822 sp->_drv_mouse_tail = 0;
823 sp->_drv_mouse_head = 0;
826 /* bump the next-free pointer into the circular list */
827 sp->_mouse_eventp = eventp = NEXT(eventp);
837 return result; /* true if we found an event */
841 _nc_mouse_inline(SCREEN *sp)
842 /* mouse report received in the keyboard stream -- parse its info */
846 MEVENT *eventp = sp->_mouse_eventp;
848 TR(MY_TRACE, ("_nc_mouse_inline() called"));
850 if (sp->_mouse_type == M_XTERM) {
851 unsigned char kbuf[4];
855 /* This code requires that your xterm entry contain the kmous
856 * capability and that it be set to the \E[M documented in the
857 * Xterm Control Sequences reference. This is how we
858 * arrange for mouse events to be reported via a KEY_MOUSE
859 * return value from wgetch(). After this value is received,
860 * _nc_mouse_inline() gets called and is immediately
861 * responsible for parsing the mouse status information
862 * following the prefix.
864 * The following quotes from the ctrlseqs.ms document in the
865 * X distribution, describing the X mouse tracking feature:
867 * Parameters for all mouse tracking escape sequences
868 * generated by xterm encode numeric parameters in a single
869 * character as value+040. For example, ! is 1.
871 * On button press or release, xterm sends ESC [ M CbCxCy.
872 * The low two bits of Cb encode button information: 0=MB1
873 * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The
874 * upper bits encode what modifiers were down when the
875 * button was pressed and are added together. 4=Shift,
876 * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates
877 * of the mouse event. The upper left corner is (1,1).
879 * (End quote) By the time we get here, we've eaten the
880 * key prefix. FYI, the loop below is necessary because
881 * mouse click info isn't guaranteed to present as a
884 * Wheel mice may return buttons 4 and 5 when the wheel is turned.
885 * We encode those as button presses.
887 # if USE_PTHREADS_EINTR
888 # if USE_WEAK_SYMBOLS
889 if ((pthread_self) && (pthread_kill) && (pthread_equal))
891 _nc_globals.read_thread = pthread_self();
893 for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) {
895 /* For VIO mouse we add extra bit 64 to disambiguate button-up. */
897 res = (int) read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3);
899 res = (int) read(sp->_ifd, kbuf + grabbed, 3 - grabbed);
904 #if USE_PTHREADS_EINTR
905 _nc_globals.read_thread = 0;
910 ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
912 /* there's only one mouse... */
913 eventp->id = NORMAL_EVENT;
915 /* processing code goes here */
919 #define PRESS_POSITION(n) \
921 eventp->bstate = MASK_PRESS(n); \
922 sp->_mouse_bstate |= MASK_PRESS(n); \
923 if (kbuf[0] & 0x40) { \
924 eventp->bstate = MASK_RELEASE(n); \
925 sp->_mouse_bstate &= ~MASK_PRESS(n); \
929 #define PRESS_POSITION(n) \
931 eventp->bstate = (mmask_t) (sp->_mouse_bstate & MASK_PRESS(n) \
932 ? REPORT_MOUSE_POSITION \
934 sp->_mouse_bstate |= MASK_PRESS(n); \
938 switch (kbuf[0] & 0x3) {
940 if ((kbuf[0] & 96) == 96) {
941 eventp->bstate = MASK_PRESS(4);
942 /* Do not record in sp->_mouse_bstate; there will be no
943 * corresponding release event.
951 if ((kbuf[0] & 96) == 96) {
952 #if NCURSES_MOUSE_VERSION == 2
953 eventp->bstate = MASK_PRESS(5);
954 /* See comment above for button 4 */
956 /* Ignore this event as it is not a true press of the button */
957 eventp->bstate = REPORT_MOUSE_POSITION;
970 * Release events aren't reported for individual buttons, just for
971 * the button set as a whole. However, because there are normally
972 * no mouse events under xterm that intervene between press and
973 * release, we can infer the button actually released by looking at
974 * the previous event.
976 if (sp->_mouse_bstate & BUTTON_PRESSED) {
977 eventp->bstate = BUTTON_RELEASED;
978 for (b = 1; b <= MAX_BUTTONS; ++b) {
979 if (!(sp->_mouse_bstate & MASK_PRESS(b)))
980 eventp->bstate &= ~MASK_RELEASE(b);
982 sp->_mouse_bstate = 0;
985 * XFree86 xterm will return a stream of release-events to
986 * let the application know where the mouse is going, if the
987 * private mode 1002 or 1003 is enabled.
989 eventp->bstate = REPORT_MOUSE_POSITION;
993 result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE;
996 eventp->bstate |= BUTTON_SHIFT;
999 eventp->bstate |= BUTTON_ALT;
1002 eventp->bstate |= BUTTON_CTRL;
1005 eventp->x = (kbuf[1] - ' ') - 1;
1006 eventp->y = (kbuf[2] - ' ') - 1;
1008 ("_nc_mouse_inline: primitive mouse-event %s has slot %ld",
1009 _nc_tracemouse(sp, eventp),
1010 (long) IndexEV(sp, eventp)));
1012 /* bump the next-free pointer into the circular list */
1013 sp->_mouse_eventp = NEXT(eventp);
1014 #if 0 /* this return would be needed for QNX's mods to lib_getch.c */
1023 mouse_activate(SCREEN *sp, int on)
1025 if (!on && !sp->_mouse_initialized)
1028 if (!_nc_mouse_init(sp))
1032 sp->_mouse_bstate = 0;
1033 switch (sp->_mouse_type) {
1035 #if NCURSES_EXT_FUNCS
1036 NCURSES_SP_NAME(keyok) (NCURSES_SP_ARGx KEY_MOUSE, on);
1038 TPUTS_TRACE("xterm mouse initialization");
1039 enable_xterm_mouse(sp, 1);
1043 if (enable_gpm_mouse(sp, TRUE)) {
1044 sp->_mouse_fd = *(my_gpm_fd);
1045 T(("GPM mouse_fd %d", sp->_mouse_fd));
1051 signal(SIGUSR2, handle_sysmouse);
1052 sp->_mouse_active = TRUE;
1055 #ifdef USE_TERM_DRIVER
1057 sp->_mouse_active = TRUE;
1063 /* Make runtime binding to cut down on object size of applications that
1064 * do not use the mouse (e.g., 'clear').
1066 sp->_mouse_event = _nc_mouse_event;
1067 sp->_mouse_inline = _nc_mouse_inline;
1068 sp->_mouse_parse = _nc_mouse_parse;
1069 sp->_mouse_resume = _nc_mouse_resume;
1070 sp->_mouse_wrap = _nc_mouse_wrap;
1073 switch (sp->_mouse_type) {
1075 TPUTS_TRACE("xterm mouse deinitialization");
1076 enable_xterm_mouse(sp, 0);
1080 enable_gpm_mouse(sp, FALSE);
1085 signal(SIGUSR2, SIG_IGN);
1086 sp->_mouse_active = FALSE;
1089 #ifdef USE_TERM_DRIVER
1091 sp->_mouse_active = FALSE;
1098 NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
1101 /**************************************************************************
1103 * Device-independent code
1105 **************************************************************************/
1108 _nc_mouse_parse(SCREEN *sp, int runcount)
1109 /* parse a run of atomic mouse events into a gesture */
1111 MEVENT *eventp = sp->_mouse_eventp;
1113 MEVENT *first_valid = NULL;
1114 MEVENT *first_invalid = NULL;
1120 TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount));
1123 * When we enter this routine, the event list next-free pointer
1124 * points just past a run of mouse events that we know were separated
1125 * in time by less than the critical click interval. The job of this
1126 * routine is to collapse this run into a single higher-level event
1129 * We accomplish this in two passes. The first pass merges press/release
1130 * pairs into click events. The second merges runs of click events into
1131 * double or triple-click events.
1133 * It's possible that the run may not resolve to a single event (for
1134 * example, if the user quadruple-clicks). If so, leading events
1135 * in the run are ignored if user does not call getmouse in a loop (getting
1136 * them from newest to older).
1138 * Note that this routine is independent of the format of the specific
1139 * format of the pointing-device's reports. We can use it to parse
1140 * gestures on anything that reports press/release events on a per-
1141 * button basis, as long as the device-dependent mouse code puts stuff
1142 * on the queue in MEVENT format.
1146 * Reset all events that were not set, in case the user sometimes calls
1147 * getmouse only once and other times until there are no more events in
1150 * This also allows reaching the beginning of the run.
1153 for (n = runcount; n < EV_MAX; n++) {
1159 if (USE_TRACEF(TRACE_IEVENT)) {
1160 _trace_slot(sp, "before mouse press/release merge:");
1161 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
1162 RunParams(sp, eventp, ep),
1164 _nc_unlock_global(tracef);
1168 /* first pass; merge press/release pairs */
1172 if (next == eventp) {
1173 /* Will end the loop, but compact before */
1177 #define MASK_CHANGED(x) (!(ep->bstate & MASK_PRESS(x)) \
1178 == !(next->bstate & MASK_RELEASE(x)))
1180 if (ValidEvent(ep) && ValidEvent(next)
1181 && ep->x == next->x && ep->y == next->y
1182 && (ep->bstate & BUTTON_PRESSED)
1183 && (!(next->bstate & BUTTON_PRESSED))) {
1184 bool changed = TRUE;
1186 for (b = 1; b <= MAX_BUTTONS; ++b) {
1187 if (!MASK_CHANGED(b)) {
1195 for (b = 1; b <= MAX_BUTTONS; ++b) {
1196 if ((sp->_mouse_mask & MASK_CLICK(b))
1197 && (ep->bstate & MASK_PRESS(b))) {
1198 next->bstate &= ~MASK_RELEASE(b);
1199 next->bstate |= MASK_CLICK(b);
1210 /* Compact valid events */
1211 if (!ValidEvent(ep)) {
1212 if ((first_valid != NULL) && (first_invalid == NULL)) {
1216 if (first_valid == NULL) {
1218 } else if (first_invalid != NULL) {
1219 *first_invalid = *ep;
1221 first_invalid = NEXT(first_invalid);
1228 if (first_invalid != NULL) {
1229 eventp = first_invalid;
1232 if (USE_TRACEF(TRACE_IEVENT)) {
1233 _trace_slot(sp, "before mouse click merge:");
1234 if (first_valid == NULL) {
1235 _tracef("_nc_mouse_parse: no valid event");
1237 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
1238 RunParams(sp, eventp, first_valid),
1240 _nc_unlock_global(tracef);
1246 * Second pass; merge click runs. We merge click events forward in the
1247 * queue. For example, double click can be changed to triple click.
1249 * NOTE: There is a problem with this design! If the application
1250 * allows enough click events to pile up in the circular queue so
1251 * they wrap around, it will cheerfully merge the newest forward
1252 * into the oldest, creating a bogus doubleclick and confusing
1253 * the queue-traversal logic rather badly. Generally this won't
1254 * happen, because calling getmouse() marks old events invalid and
1255 * ineligible for merges. The true solution to this problem would
1256 * be to timestamp each MEVENT and perform the obvious sanity check,
1257 * but the timer element would have to have sub-second resolution,
1258 * which would get us into portability trouble.
1260 first_invalid = NULL;
1261 endLoop = (first_valid == NULL);
1266 if (next == eventp) {
1267 /* Will end the loop, but check event type and compact before */
1269 } else if (!ValidEvent(next)) {
1272 /* merge click events forward */
1273 if ((ep->bstate & BUTTON_CLICKED)
1274 && (next->bstate & BUTTON_CLICKED)) {
1276 for (b = 1; b <= MAX_BUTTONS; ++b) {
1277 if ((sp->_mouse_mask & MASK_DOUBLE_CLICK(b))
1278 && (ep->bstate & MASK_CLICK(b))
1279 && (next->bstate & MASK_CLICK(b))) {
1280 next->bstate &= ~MASK_CLICK(b);
1281 next->bstate |= MASK_DOUBLE_CLICK(b);
1290 /* merge double-click events forward */
1291 if ((ep->bstate & BUTTON_DOUBLE_CLICKED)
1292 && (next->bstate & BUTTON_CLICKED)) {
1294 for (b = 1; b <= MAX_BUTTONS; ++b) {
1295 if ((sp->_mouse_mask & MASK_TRIPLE_CLICK(b))
1296 && (ep->bstate & MASK_DOUBLE_CLICK(b))
1297 && (next->bstate & MASK_CLICK(b))) {
1298 next->bstate &= ~MASK_CLICK(b);
1299 next->bstate |= MASK_TRIPLE_CLICK(b);
1309 /* Discard event if it does not match event mask */
1310 if (!(ep->bstate & sp->_mouse_mask2)) {
1314 /* Compact valid events */
1315 if (!ValidEvent(ep)) {
1316 if (ep == first_valid) {
1318 } else if (first_invalid == NULL) {
1321 } else if (first_invalid != NULL) {
1322 *first_invalid = *ep;
1324 first_invalid = NEXT(first_invalid);
1330 if (first_invalid == NULL) {
1331 first_invalid = eventp;
1333 sp->_mouse_eventp = first_invalid;
1336 if (first_valid != NULL) {
1337 if (USE_TRACEF(TRACE_IEVENT)) {
1338 _trace_slot(sp, "after mouse event queue compaction:");
1339 _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d",
1340 RunParams(sp, first_invalid, first_valid),
1342 _nc_unlock_global(tracef);
1344 for (ep = first_valid; ep != first_invalid; ep = NEXT(ep)) {
1347 ("_nc_mouse_parse: returning composite mouse event %s at slot %ld",
1348 _nc_tracemouse(sp, ep),
1349 (long) IndexEV(sp, ep)));
1354 /* after all this, do we have a valid event? */
1355 return ValidEvent(PREV(first_invalid));
1359 _nc_mouse_wrap(SCREEN *sp)
1360 /* release mouse -- called by endwin() before shellout/exit */
1362 TR(MY_TRACE, ("_nc_mouse_wrap() called"));
1364 switch (sp->_mouse_type) {
1366 if (sp->_mouse_mask)
1367 mouse_activate(sp, FALSE);
1370 /* GPM: pass all mouse events to next client */
1372 if (sp->_mouse_mask)
1373 mouse_activate(sp, FALSE);
1378 mouse_activate(sp, FALSE);
1381 #ifdef USE_TERM_DRIVER
1383 mouse_activate(sp, FALSE);
1392 _nc_mouse_resume(SCREEN *sp)
1393 /* re-connect to mouse -- called by doupdate() after shellout */
1395 TR(MY_TRACE, ("_nc_mouse_resume() called"));
1397 switch (sp->_mouse_type) {
1399 /* xterm: re-enable reporting */
1400 if (sp->_mouse_mask)
1401 mouse_activate(sp, TRUE);
1406 /* GPM: reclaim our event set */
1407 if (sp->_mouse_mask)
1408 mouse_activate(sp, TRUE);
1414 mouse_activate(sp, TRUE);
1418 #ifdef USE_TERM_DRIVER
1420 mouse_activate(sp, TRUE);
1429 /**************************************************************************
1431 * Mouse interface entry points for the API
1433 **************************************************************************/
1436 NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
1440 T((T_CALLED("getmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
1442 if ((aevent != 0) && (SP_PARM != 0) && (SP_PARM->_mouse_type != M_NONE)) {
1443 MEVENT *eventp = SP_PARM->_mouse_eventp;
1444 /* compute the current-event pointer */
1445 MEVENT *prev = PREV(eventp);
1448 * Discard events not matching mask (there could be still some if
1449 * _nc_mouse_parse was not called, e.g., when _nc_mouse_inline returns
1452 while (ValidEvent(prev) && (!(prev->bstate & SP_PARM->_mouse_mask2))) {
1456 if (ValidEvent(prev)) {
1457 /* copy the event we find there */
1460 TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld",
1461 _nc_tracemouse(SP_PARM, prev),
1462 (long) IndexEV(SP_PARM, prev)));
1464 Invalidate(prev); /* so the queue slot becomes free */
1465 SP_PARM->_mouse_eventp = prev;
1468 /* Reset the provided event */
1479 #if NCURSES_SP_FUNCS
1480 /* grab a copy of the current mouse event */
1482 getmouse(MEVENT * aevent)
1484 return NCURSES_SP_NAME(getmouse) (CURRENT_SCREEN, aevent);
1489 NCURSES_SP_NAME(ungetmouse) (NCURSES_SP_DCLx MEVENT * aevent)
1493 T((T_CALLED("ungetmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
1495 if (aevent != 0 && SP_PARM != 0) {
1496 MEVENT *eventp = SP_PARM->_mouse_eventp;
1498 /* stick the given event in the next-free slot */
1501 /* bump the next-free pointer into the circular list */
1502 SP_PARM->_mouse_eventp = NEXT(eventp);
1504 /* push back the notification event on the keyboard queue */
1505 result = NCURSES_SP_NAME(ungetch) (NCURSES_SP_ARGx KEY_MOUSE);
1510 #if NCURSES_SP_FUNCS
1511 /* enqueue a synthesized mouse event to be seen by the next wgetch() */
1513 ungetmouse(MEVENT * aevent)
1515 return NCURSES_SP_NAME(ungetmouse) (CURRENT_SCREEN, aevent);
1519 NCURSES_EXPORT(mmask_t)
1520 NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask)
1521 /* set the mouse event mask */
1526 T((T_CALLED("mousemask(%p,%#lx,%p)"),
1528 (unsigned long) newmask,
1533 *oldmask = SP_PARM->_mouse_mask;
1535 if (newmask || SP_PARM->_mouse_initialized) {
1536 _nc_mouse_init(SP_PARM);
1537 if (SP_PARM->_mouse_type != M_NONE) {
1539 (REPORT_MOUSE_POSITION
1546 | BUTTON_DOUBLE_CLICKED
1547 | BUTTON_TRIPLE_CLICKED);
1549 mouse_activate(SP_PARM, (bool) (result != 0));
1551 SP_PARM->_mouse_mask = result;
1552 SP_PARM->_mouse_mask2 = result;
1555 * Make a mask corresponding to the states we will need to
1556 * retain (temporarily) while building up the state that the
1559 for (b = 1; b <= MAX_BUTTONS; ++b) {
1560 if (SP_PARM->_mouse_mask2 & MASK_TRIPLE_CLICK(b))
1561 SP_PARM->_mouse_mask2 |= MASK_DOUBLE_CLICK(b);
1562 if (SP_PARM->_mouse_mask2 & MASK_DOUBLE_CLICK(b))
1563 SP_PARM->_mouse_mask2 |= MASK_CLICK(b);
1564 if (SP_PARM->_mouse_mask2 & MASK_CLICK(b))
1565 SP_PARM->_mouse_mask2 |= (MASK_PRESS(b) |
1571 returnMMask(result);
1574 #if NCURSES_SP_FUNCS
1575 NCURSES_EXPORT(mmask_t)
1576 mousemask(mmask_t newmask, mmask_t * oldmask)
1578 return NCURSES_SP_NAME(mousemask) (CURRENT_SCREEN, newmask, oldmask);
1582 NCURSES_EXPORT(bool)
1583 wenclose(const WINDOW *win, int y, int x)
1584 /* check to see if given window encloses given screen location */
1586 bool result = FALSE;
1588 T((T_CALLED("wenclose(%p,%d,%d)"), (const void *) win, y, x));
1592 result = ((win->_begy <= y &&
1594 (win->_begx + win->_maxx) >= x &&
1595 (win->_begy + win->_maxy) >= y) ? TRUE : FALSE);
1601 NCURSES_SP_NAME(mouseinterval) (NCURSES_SP_DCLx int maxclick)
1602 /* set the maximum mouse interval within which to recognize a click */
1606 T((T_CALLED("mouseinterval(%p,%d)"), (void *) SP_PARM, maxclick));
1609 oldval = SP_PARM->_maxclick;
1611 SP_PARM->_maxclick = maxclick;
1613 oldval = DEFAULT_MAXCLICK;
1619 #if NCURSES_SP_FUNCS
1621 mouseinterval(int maxclick)
1623 return NCURSES_SP_NAME(mouseinterval) (CURRENT_SCREEN, maxclick);
1627 /* This may be used by other routines to ask for the existence of mouse
1629 NCURSES_EXPORT(bool)
1630 _nc_has_mouse(SCREEN *sp)
1632 return (((0 == sp) || (sp->_mouse_type == M_NONE)) ? FALSE : TRUE);
1635 NCURSES_EXPORT(bool)
1636 NCURSES_SP_NAME(has_mouse) (NCURSES_SP_DCL0)
1638 return _nc_has_mouse(SP_PARM);
1641 #if NCURSES_SP_FUNCS
1642 NCURSES_EXPORT(bool)
1645 return _nc_has_mouse(CURRENT_SCREEN);
1649 NCURSES_EXPORT(bool)
1650 wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen)
1652 bool result = FALSE;
1654 T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"),
1660 if (win && pY && pX) {
1665 y += win->_begy + win->_yoffset;
1667 if (wenclose(win, y, x))
1670 if (wenclose(win, y, x)) {
1671 y -= (win->_begy + win->_yoffset);