]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_mouse.3x
7140261f459d5e9c67bac57f1cef9bd7eb06e19c
[ncurses.git] / man / curs_mouse.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_mouse.3x,v 1.34 2010/01/02 21:45:42 tom Exp $
31 .TH curs_mouse 3X ""
32 .na
33 .hy 0
34 .SH NAME
35 \fBhas_mouse\fR,
36 \fBgetmouse\fR, \fBungetmouse\fR,
37 \fBmousemask\fR, \fBwenclose\fR,
38 \fBmouse_trafo\fR, \fBwmouse_trafo\fR,
39 \fBmouseinterval\fR - mouse interface through curses
40 .ad
41 .hy
42 .SH SYNOPSIS
43 .nf
44 \fB#include <curses.h>
45 .PP
46 \fBtypedef unsigned long mmask_t;
47 .PP
48 typedef struct
49 {
50     short id;         \fI/* ID to distinguish multiple devices */\fB
51     int x, y, z;      \fI/* event coordinates */\fB
52     mmask_t bstate;   \fI/* button state bits */\fB
53 }
54 MEVENT;\fR
55 .fi
56 .br
57 \fBbool has_mouse(void);\fR
58 .br
59 \fBint getmouse(MEVENT *event);\fR
60 .br
61 \fBint ungetmouse(MEVENT *event);\fR
62 .br
63 \fBmmask_t mousemask(mmask_t newmask, mmask_t *oldmask);\fR
64 .br
65 \fBbool wenclose(const WINDOW *win, int y, int x);\fR
66 .br
67 \fBbool mouse_trafo(int* pY, int* pX, bool to_screen);\fR
68 .br
69 \fBbool wmouse_trafo(const WINDOW* win, int* pY, int* pX,\fR
70 .br
71         \fBbool to_screen);\fR
72 .br
73 \fBint mouseinterval(int erval);\fR
74 .br
75 .SH DESCRIPTION
76 These functions provide an interface to mouse events from
77 \fBncurses\fR(3X).
78 Mouse events are represented by \fBKEY_MOUSE\fR
79 pseudo-key values in the \fBwgetch\fR input stream.
80 .PP
81 To make mouse events visible, use the \fBmousemask\fR function.
82 This will set
83 the mouse events to be reported.
84 By default, no mouse events are reported.
85 The function will return a mask to indicate which of the specified mouse events
86 can be reported; on complete failure it returns 0.
87 If oldmask is non-NULL,
88 this function fills the indicated location with the previous value of the given
89 window's mouse event mask.
90 .PP
91 As a side effect, setting a zero mousemask may turn off the mouse pointer;
92 setting a nonzero mask may turn it on.
93 Whether this happens is device-dependent.
94 .PP
95 Here are the mouse event type masks which may be defined:
96 .PP
97 .TS
98 l l
99 _ _
100 l l.
101 \fIName\fR      \fIDescription\fR
102 BUTTON1_PRESSED mouse button 1 down
103 BUTTON1_RELEASED        mouse button 1 up
104 BUTTON1_CLICKED mouse button 1 clicked
105 BUTTON1_DOUBLE_CLICKED  mouse button 1 double clicked
106 BUTTON1_TRIPLE_CLICKED  mouse button 1 triple clicked
107 _
108 BUTTON2_PRESSED mouse button 2 down
109 BUTTON2_RELEASED        mouse button 2 up
110 BUTTON2_CLICKED mouse button 2 clicked
111 BUTTON2_DOUBLE_CLICKED  mouse button 2 double clicked
112 BUTTON2_TRIPLE_CLICKED  mouse button 2 triple clicked
113 _
114 BUTTON3_PRESSED mouse button 3 down
115 BUTTON3_RELEASED        mouse button 3 up
116 BUTTON3_CLICKED mouse button 3 clicked
117 BUTTON3_DOUBLE_CLICKED  mouse button 3 double clicked
118 BUTTON3_TRIPLE_CLICKED  mouse button 3 triple clicked
119 _
120 BUTTON4_PRESSED mouse button 4 down
121 BUTTON4_RELEASED        mouse button 4 up
122 BUTTON4_CLICKED mouse button 4 clicked
123 BUTTON4_DOUBLE_CLICKED  mouse button 4 double clicked
124 BUTTON4_TRIPLE_CLICKED  mouse button 4 triple clicked
125 _
126 BUTTON5_PRESSED mouse button 5 down
127 BUTTON5_RELEASED        mouse button 5 up
128 BUTTON5_CLICKED mouse button 5 clicked
129 BUTTON5_DOUBLE_CLICKED  mouse button 5 double clicked
130 BUTTON5_TRIPLE_CLICKED  mouse button 5 triple clicked
131 _
132 BUTTON_SHIFT    shift was down during button state change
133 BUTTON_CTRL     control was down during button state change
134 BUTTON_ALT      alt was down during button state change
135 ALL_MOUSE_EVENTS        report all button state changes
136 REPORT_MOUSE_POSITION   report mouse movement
137 _
138 .TE
139 .PP
140 Once a class of mouse events have been made visible in a window,
141 calling the \fBwgetch\fR function on that window may return
142 \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
143 To read the event data and pop the event off the queue, call
144 \fBgetmouse\fR.
145 This function will return \fBOK\fR if a mouse event
146 is actually visible in the given window, \fBERR\fR otherwise.
147 When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
148 x in the event structure coordinates will be screen-relative character-cell
149 coordinates.
150 The returned state mask will have exactly one bit set to
151 indicate the event type.
152 The corresponding data in the queue is marked invalid.
153 A subsequent call to \fBgetmouse\fP will retrieve the next older
154 item from the queue.
155 .PP
156 The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
157 It pushes
158 a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
159 the given state data and screen-relative character-cell coordinates.
160 .PP
161 The \fBwenclose\fR function tests whether a given pair of screen-relative
162 character-cell coordinates is enclosed by a given window, returning TRUE
163 if it is and FALSE otherwise.
164 It is useful for determining what subset of
165 the screen windows enclose the location of a mouse event.
166 .PP
167 The \fBwmouse_trafo\fR function transforms a given pair of coordinates
168 from stdscr-relative coordinates
169 to coordinates relative to the given window or vice versa.
170 Please remember, that stdscr-relative coordinates are not always identical
171 to window-relative coordinates due to the mechanism to reserve lines on top
172 or bottom of the screen for other purposes
173 (see the \fBripoffline()\fP and \fBslk_init\fR calls, for example).
174 If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
175 \fBpY, pX\fR must reference the coordinates of a location
176 inside the window \fBwin\fR.
177 They are converted to window-relative coordinates and returned
178 through the pointers.
179 If the conversion was successful, the function returns \fBTRUE\fR.
180 If one of the parameters was NULL or the location is
181 not inside the window, \fBFALSE\fR is returned.
182 If \fBto_screen\fR is
183 \fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
184 coordinates.
185 They are converted to stdscr-relative coordinates if the
186 window \fBwin\fR encloses this point.
187 In this case the function returns \fBTRUE\fR.
188 If one of the parameters is NULL or the point is not inside the
189 window, \fBFALSE\fR is returned.
190 Please notice, that the referenced coordinates
191 are only replaced by the converted coordinates if the transformation was
192 successful.
193 .PP
194 The \fBmouse_trafo\fR function performs the same translation
195 as \fBwmouse_trafo\fR,
196 using stdscr for \fBwin\fR.
197 .PP
198 The \fBmouseinterval\fR function sets the maximum time (in thousands of a
199 second) that can elapse between press and release events for them to
200 be recognized as a click.
201 Use \fBmouseinterval(0)\fR to disable click resolution.
202 This function returns the previous interval value.
203 Use \fBmouseinterval(-1)\fR to obtain the interval without altering it.
204 The default is one sixth of a second.
205 .PP
206 The \fBhas_mouse\fP function returns TRUE if the mouse driver has been
207 successfully initialized.
208 .PP
209 Note that mouse events will be ignored when input is in cooked mode, and will
210 cause an error beep when cooked mode is being simulated in a window by a
211 function such as \fBgetstr\fR that expects a linefeed for input-loop
212 termination.
213 .SH RETURN VALUE
214 \fBgetmouse\fR and \fBungetmouse\fR
215 return the integer \fBERR\fR upon failure or \fBOK\fR
216 upon successful completion.
217 .RS
218 .TP 5
219 \fBgetmouse\fP
220 returns an error.
221 If no mouse driver was initialized, or
222 if the mask parameter is zero,
223 It also returns an error if no more events remain in the queue.
224 .TP 5
225 \fBungetmouse\fP
226 returns an error if the FIFO is full.
227 .RE
228 .PP
229 \fBmousemask\fR
230 returns the mask of reportable events.
231 .PP
232 \fBmouseinterval\fR
233 returns the previous interval value, unless
234 the terminal was not initialized.
235 In that case, it returns the maximum interval value (166).
236 .PP
237 \fBwenclose\fR and \fBwmouse_trafo\fR
238 are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
239 on their test result.
240 .SH PORTABILITY
241 These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
242 curses, 4.4BSD curses, or any other previous version of curses.
243 .PP
244 The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
245 can be used to test whether these features are present.
246 If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
247 incremented.
248 These values for \fBNCURSES_MOUSE_VERSION\fR may be
249 specified when configuring ncurses:
250 .RS
251 .TP 3
252 1
253 has definitions for reserved events.
254 The mask uses 28 bits.
255 .TP 3
256 2
257 adds definitions for button 5,
258 removes the definitions for reserved events.
259 The mask uses 29 bits.
260 .RE
261 .PP
262 The order of the \fBMEVENT\fR structure members is not guaranteed.
263 Additional fields may be added to the structure in the future.
264 .PP
265 Under \fBncurses\fR(3X), these calls are implemented using either
266 xterm's built-in mouse-tracking API or
267 platform-specific drivers including
268 .RS
269 Alessandro Rubini's gpm server
270 .br
271 FreeBSD sysmouse
272 .br
273 OS/2 EMX
274 .RE
275 If you are using an unsupported configuration,
276 mouse events will not be visible to
277 \fBncurses\fR(3X) (and the \fBmousemask\fR function will always
278 return \fB0\fR).
279 .PP
280 If the terminfo entry contains a \fBXM\fR string,
281 this is used in the xterm mouse driver to control the
282 way the terminal is initialized for mouse operation.
283 The default, if \fBXM\fR is not found,
284 corresponds to private mode 1000 of xterm:
285 .RS
286 \\E[?1000%?%p1%{1}%=%th%el%;
287 .RE
288 The z member in the event structure is not presently used.
289 It is intended
290 for use with touch screens (which may be pressure-sensitive) or with
291 3D-mice/trackballs/power gloves.
292 .SH BUGS
293 Mouse events under xterm will not in fact be ignored during cooked mode,
294 if they have been enabled by \fBmousemask\fR.
295 Instead, the xterm mouse
296 report sequence will appear in the string read.
297 .PP
298 Mouse events under xterm will not be detected correctly in a window with
299 its keypad bit off, since they are interpreted as a variety of function key.
300 Your terminfo description should have \fBkmous\fR set to "\\E[M"
301 (the beginning of the response from xterm for mouse clicks).
302 Other values for \fBkmous\fR are permitted,
303 but under the same assumption,
304 i.e., it is the beginning of the response.
305 .PP
306 Because there are no standard terminal responses that would serve to identify
307 terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
308 if your $TERM environment variable contains "xterm",
309 or \fBkmous\fR is defined in
310 the terminal description, then the terminal may send mouse events.
311 .SH SEE ALSO
312 \fBcurses\fR(3X),
313 \fBcurs_kernel\fR(3X),
314 \fBcurs_slk\fR(3X).
315 .\"#
316 .\"# The following sets edit modes for GNU EMACS
317 .\"# Local Variables:
318 .\"# mode:nroff
319 .\"# fill-column:79
320 .\"# End: