2 Copyright (C) 1994 Miguel de Icaza.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Events received by clients of this library have their coordinates 0 */
24 #include <sys/types.h>
28 #include <signal.h> /* For kill() and SIGQUIT */
30 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(HAS_NO_TERMIOS_H)
36 #include "key.h" /* define sequence */
37 #include "tty.h" /* get ncurses header */
42 * This chunk of NCURSES internals is used to support the keyok() function for
43 * NCURSES versions between 1.9.6 (when the mouse code was introduced in 1995),
44 * and 4.2 (when the keyok function will be release).
47 #ifdef NCURSES_MOUSE_VERSION /* first defined for ncurses 1.9.6 */
48 #ifdef NCURSES_970530 /* defined by configure script */
50 * ncurses 1.9.8a ported to QNX doesn't provide the SP pointer as a global
51 * symbol in the library...
56 struct tries
*sibling
;
64 #if NCURSES_970530 >= 2
65 char *_setbuf
; /*4.0*/
71 #if NCURSES_970530 >= 1
72 short _lines_avail
; /*1.9.9g*/
73 short _topstolen
; /*1.9.9g*/
75 struct _win_st
*_curscr
;
76 struct _win_st
*_newscr
;
77 struct _win_st
*_stdscr
;
78 struct tries
*_keytry
; /* "Try" for use with keypad mode */
79 /* there's more, but this is just for alignment */
81 extern struct screen
*SP
;
84 * Remove a code from the specified tree, freeing the unused nodes. Returns
85 * true if the code was found/removed.
88 int _nc_remove_key(struct tries
**tree
, unsigned short code
)
90 struct tries
*ptr
= (*tree
);
94 if (_nc_remove_key(&(ptr
->child
), code
)) {
97 if (ptr
->value
== code
) {
109 keyok(int code
, bool flag
)
111 _nc_remove_key(&(SP
->_keytry
), code
);
115 #endif /* NCURSES_970530 */
116 #endif /* NCURSES_MOUSE_VERSION */
117 #endif /* HAVE_KEYOK */
120 static int mouse_d
; /* Handle to the mouse server */
124 /* Only used for debugging */
125 static int top_event
= 0;
131 void show_mouse_pointer (int x
, int y
)
134 if (use_mouse_p
== GPM_MOUSE
){
135 Gpm_DrawPointer (x
, y
, gpm_consolefd
);
140 #endif /* HAVE_LIBGPM */
142 int mouse_handler (Gpm_Event
*gpm_event
)
144 MouseEvent
*event
= mouse_events
;
145 int x
= last_x
= gpm_event
->x
;
146 int y
= last_y
= gpm_event
->y
;
149 /* DEBUGM ((log, "Mouse [%d, %d]\n", x, y)); */
151 /* Call any registered event handlers */
152 for (; event
; event
= (MouseEvent
*) event
->next
){
153 if ((event
->x1
<= x
) && (x
<= event
->x2
)
154 && (event
->y1
<= y
) && (y
<= event
->y2
)){
155 gpm_event
->x
-= event
->x1
;
156 gpm_event
->y
-= event
->y1
;
157 last_mouse_event
= event
;
158 redo
= (*(event
->mouse_callback
))(gpm_event
, event
->data
);
159 gpm_event
->x
+= event
->x1
;
160 gpm_event
->y
+= event
->y1
;
167 int redo_mouse (Gpm_Event
*event
)
169 if (last_mouse_event
){
171 event
->x
-= last_mouse_event
->x1
;
172 event
->y
-= last_mouse_event
->y1
;
173 result
= (*(last_mouse_event
->mouse_callback
))
174 (event
,last_mouse_event
->data
);
175 event
->x
+= last_mouse_event
->x1
;
176 event
->y
+= last_mouse_event
->y1
;
183 void init_mouse (void)
186 * MC's use of xterm mouse is incompatible with NCURSES's support. The
187 * simplest solution is to disable NCURSE's mouse.
189 #ifdef NCURSES_MOUSE_VERSION
190 /* See the comment above about QNX/ncurses 1.9.8a ... */
192 keyok(KEY_MOUSE
, FALSE
);
194 #endif /* NCURSES_MOUSE_VERSION */
196 #if defined(NCURSES_970530)
205 conn
.eventMask
= ~GPM_MOVE
;
206 conn
.defaultMask
= GPM_MOVE
;
210 if ((mouse_d
= Gpm_Open (&conn
, 0)) == -1)
214 log
= fopen ("mouse.log", "w");
218 #endif /* HAVE_LIBGPM */
222 /* save old highlight mouse tracking */
223 printf("%c[?1001s",27);
225 /* enable mouse tracking */
226 printf("%c[?1000h",27);
231 define_sequence (MCKEY_MOUSE
, ESC_STR
"[M", MCKEY_NOACTION
);
237 } /* switch (use_mouse_p) */
240 void shut_mouse (void)
242 switch (use_mouse_p
){
251 /* disable mouse tracking */
252 /* Changed the 1 for an 'l' below: */
253 printf("%c[?1000l",27);
255 /* restore old highlight mouse tracking */
256 printf("%c[?1001r",27);
270 void mouse_log (char *function
, char *file
, int line
)
272 fprintf (log
, "%s called from %s:%d\n", function
, file
, line
);