]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_mouse.3x
ncurses 6.1 - patch 20180707
[ncurses.git] / man / curs_mouse.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2015,2017 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.47 2017/11/18 23:52:45 tom Exp $
31 .ie \n(.g .ds `` \(lq
32 .el       .ds `` ``
33 .ie \n(.g .ds '' \(rq
34 .el       .ds '' ''
35 .de NS
36 .ie n  .sp
37 .el    .sp .5
38 .ie n  .in +4
39 .el    .in +2
40 .nf
41 .ft C                   \" Courier
42 ..
43 .de NE
44 .fi
45 .ft R
46 .in -4
47 ..
48 .de bP
49 .ie n  .IP \(bu 4
50 .el    .IP \(bu 2
51 ..
52 .TH curs_mouse 3X ""
53 .na
54 .hy 0
55 .SH NAME
56 \fBhas_mouse\fR,
57 \fBgetmouse\fR, \fBungetmouse\fR,
58 \fBmousemask\fR, \fBwenclose\fR,
59 \fBmouse_trafo\fR, \fBwmouse_trafo\fR,
60 \fBmouseinterval\fR \- mouse interface through curses
61 .ad
62 .hy
63 .SH SYNOPSIS
64 \fB#include <curses.h>\fR
65 .PP
66 \fBtypedef unsigned long mmask_t;\fR
67 .PP
68 .nf
69 \fBtypedef struct {\fR
70 \fB    short id;         \fR\fI/* ID to distinguish multiple devices */\fR
71 \fB    int x, y, z;      \fR\fI/* event coordinates */\fR
72 \fB    mmask_t bstate;   \fR\fI/* button state bits */\fR
73 \fB} MEVENT;\fR
74 .fi
75 .PP
76 \fBbool has_mouse(void);\fR
77 .br
78 \fBint getmouse(MEVENT *\fP\fIevent\fP\fB);\fR
79 .br
80 \fBint ungetmouse(MEVENT *\fP\fIevent\fP\fB);\fR
81 .br
82 \fBmmask_t mousemask(mmask_t \fP\fInewmask\fP\fB, mmask_t *\fP\fIoldmask\fP\fB);\fR
83 .br
84 \fBbool wenclose(const WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB);\fR
85 .br
86 \fBbool mouse_trafo(int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB, bool \fP\fIto_screen\fP\fB);\fR
87 .br
88 \fBbool wmouse_trafo(const WINDOW* \fP\fIwin\fP\fB, int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB,\fR
89 .br
90         \fBbool \fP\fIto_screen\fP\fB);\fR
91 .br
92 \fBint mouseinterval(int \fP\fIerval\fP\fB);\fR
93 .br
94 .SH DESCRIPTION
95 These functions provide an interface to mouse events from
96 \fBncurses\fR(3X).
97 Mouse events are represented by \fBKEY_MOUSE\fR
98 pseudo-key values in the \fBwgetch\fR(3X) input stream.
99 .SS mousemask
100 .PP
101 To make mouse events visible, use the \fBmousemask\fR function.
102 This will set
103 the mouse events to be reported.
104 By default, no mouse events are reported.
105 The function will return a mask to indicate which of the specified mouse events
106 can be reported; on complete failure it returns 0.
107 If oldmask is non-NULL,
108 this function fills the indicated location with the previous value of the given
109 window's mouse event mask.
110 .PP
111 As a side effect, setting a zero mousemask may turn off the mouse pointer;
112 setting a nonzero mask may turn it on.
113 Whether this happens is device-dependent.
114 .SS Mouse events
115 .PP
116 Here are the mouse event type masks which may be defined:
117 .PP
118 .TS
119 l l
120 _ _
121 l l.
122 \fIName\fR      \fIDescription\fR
123 BUTTON1_PRESSED mouse button 1 down
124 BUTTON1_RELEASED        mouse button 1 up
125 BUTTON1_CLICKED mouse button 1 clicked
126 BUTTON1_DOUBLE_CLICKED  mouse button 1 double clicked
127 BUTTON1_TRIPLE_CLICKED  mouse button 1 triple clicked
128 _
129 BUTTON2_PRESSED mouse button 2 down
130 BUTTON2_RELEASED        mouse button 2 up
131 BUTTON2_CLICKED mouse button 2 clicked
132 BUTTON2_DOUBLE_CLICKED  mouse button 2 double clicked
133 BUTTON2_TRIPLE_CLICKED  mouse button 2 triple clicked
134 _
135 BUTTON3_PRESSED mouse button 3 down
136 BUTTON3_RELEASED        mouse button 3 up
137 BUTTON3_CLICKED mouse button 3 clicked
138 BUTTON3_DOUBLE_CLICKED  mouse button 3 double clicked
139 BUTTON3_TRIPLE_CLICKED  mouse button 3 triple clicked
140 _
141 BUTTON4_PRESSED mouse button 4 down
142 BUTTON4_RELEASED        mouse button 4 up
143 BUTTON4_CLICKED mouse button 4 clicked
144 BUTTON4_DOUBLE_CLICKED  mouse button 4 double clicked
145 BUTTON4_TRIPLE_CLICKED  mouse button 4 triple clicked
146 _
147 BUTTON5_PRESSED mouse button 5 down
148 BUTTON5_RELEASED        mouse button 5 up
149 BUTTON5_CLICKED mouse button 5 clicked
150 BUTTON5_DOUBLE_CLICKED  mouse button 5 double clicked
151 BUTTON5_TRIPLE_CLICKED  mouse button 5 triple clicked
152 _
153 BUTTON_SHIFT    shift was down during button state change
154 BUTTON_CTRL     control was down during button state change
155 BUTTON_ALT      alt was down during button state change
156 ALL_MOUSE_EVENTS        report all button state changes
157 REPORT_MOUSE_POSITION   report mouse movement
158 _
159 .TE
160 .SS getmouse
161 .PP
162 Once a class of mouse events has been made visible in a window,
163 calling the \fBwgetch\fR function on that window may return
164 \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
165 To read the event data and pop the event off the queue, call
166 \fBgetmouse\fR.
167 This function will return \fBOK\fR if a mouse event
168 is actually visible in the given window, \fBERR\fR otherwise.
169 When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
170 x in the event structure coordinates will be screen-relative character-cell
171 coordinates.
172 The returned state mask will have exactly one bit set to
173 indicate the event type.
174 The corresponding data in the queue is marked invalid.
175 A subsequent call to \fBgetmouse\fP will retrieve the next older
176 item from the queue.
177 .SS ungetmouse
178 .PP
179 The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
180 It pushes
181 a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
182 the given state data and screen-relative character-cell coordinates.
183 .SS wenclose
184 .PP
185 The \fBwenclose\fR function tests whether a given pair of screen-relative
186 character-cell coordinates is enclosed by a given window, returning \fBTRUE\fP
187 if it is and \fBFALSE\fP otherwise.
188 It is useful for determining what subset of
189 the screen windows enclose the location of a mouse event.
190 .SS wmouse_trafo
191 .PP
192 The \fBwmouse_trafo\fR function transforms a given pair of coordinates
193 from stdscr-relative coordinates
194 to coordinates relative to the given window or vice versa.
195 The resulting stdscr-relative coordinates are not always identical
196 to window-relative coordinates due to the mechanism to reserve lines on top
197 or bottom of the screen for other purposes
198 (see the \fBripoffline\fP and \fBslk_init\fR(3X) calls, for example).
199 .bP
200 If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
201 \fBpY, pX\fR must reference the coordinates of a location
202 inside the window \fBwin\fR.
203 They are converted to window-relative coordinates and returned
204 through the pointers.
205 If the conversion was successful, the function returns \fBTRUE\fR.
206 .bP
207 If one of the parameters was NULL or the location is
208 not inside the window, \fBFALSE\fR is returned.
209 .bP
210 If \fBto_screen\fR is
211 \fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
212 coordinates.
213 They are converted to stdscr-relative coordinates if the
214 window \fBwin\fR encloses this point.
215 In this case the function returns \fBTRUE\fR.
216 .bP
217 If one of the parameters is NULL or the point is not inside the
218 window, \fBFALSE\fR is returned.
219 The referenced coordinates
220 are only replaced by the converted coordinates if the transformation was
221 successful.
222 .SS mouse_trafo
223 .PP
224 The \fBmouse_trafo\fR function performs the same translation
225 as \fBwmouse_trafo\fR,
226 using stdscr for \fBwin\fR.
227 .SS mouseinterval
228 .PP
229 The \fBmouseinterval\fR function sets the maximum time (in thousands of a
230 second) that can elapse between press and release events for them to
231 be recognized as a click.
232 Use \fBmouseinterval(0)\fR to disable click resolution.
233 This function returns the previous interval value.
234 Use \fBmouseinterval(\-1)\fR to obtain the interval without altering it.
235 The default is one sixth of a second.
236 .SS has_mouse
237 .PP
238 The \fBhas_mouse\fP function returns \fBTRUE\fP if the mouse driver has been
239 successfully initialized.
240 .PP
241 Note that mouse events will be ignored when input is in cooked mode, and will
242 cause an error beep when cooked mode is being simulated in a window by a
243 function such as \fBgetstr\fR that expects a linefeed for input-loop
244 termination.
245 .SH RETURN VALUE
246 \fBgetmouse\fR and \fBungetmouse\fR
247 return the integer \fBERR\fR upon failure or \fBOK\fR
248 upon successful completion:
249 .RS 3
250 .TP 5
251 \fBgetmouse\fP
252 returns an error.
253 .bP
254 If no mouse driver was initialized, or
255 if the mask parameter is zero,
256 .bP
257 It also returns an error if no more events remain in the queue.
258 .TP 5
259 \fBungetmouse\fP
260 returns an error if the FIFO is full.
261 .RE
262 .PP
263 \fBmousemask\fR
264 returns the mask of reportable events.
265 .PP
266 \fBmouseinterval\fR
267 returns the previous interval value, unless
268 the terminal was not initialized.
269 In that case, it returns the maximum interval value (166).
270 .PP
271 \fBwenclose\fR and \fBwmouse_trafo\fR
272 are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
273 on their test result.
274 .SH PORTABILITY
275 These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
276 curses, 4.4BSD curses, or any other previous version of curses.
277 .PP
278 SVr4 curses had support for the mouse in a variant of \fBxterm\fP.
279 It is mentioned in a few places, but with no supporting documentation:
280 .bP
281 the \*(``libcurses\*('' manual page lists functions for this feature
282 which are prototyped in \fBcurses.h\fP:
283 .NS
284 extern int mouse_set(long int);
285 extern int mouse_on(long int);
286 extern int mouse_off(long int);
287 extern int request_mouse_pos(void);
288 extern int map_button(unsigned long);
289 extern void wmouse_position(WINDOW *, int *, int *);
290 extern unsigned long getmouse(void), getbmap(void);
291 .NE
292 .bP
293 the \*(``terminfo\*('' manual page lists capabilities for the feature
294 .NS
295 buttons           btns    BT       Number of buttons on the mouse
296 get_mouse         getm    Gm       Curses should get button events
297 key_mouse         kmous   Km       0631, Mouse event has occurred
298 mouse_info        minfo   Mi       Mouse status information
299 req_mouse_pos     reqmp   RQ       Request mouse position report
300 .NE
301 .bP
302 the interface made assumptions (as does ncurses) about the escape sequences
303 sent to and received from the terminal.
304 .IP
305 For instance
306 the SVr4 curses library used the \fBget_mouse\fP capability to tell the
307 terminal which mouse button events it should send,
308 passing the mouse-button bit-mask to the terminal.
309 Also, it could ask the terminal where the mouse was using the \fBreq_mouse_pos\fP capability.
310 .IP
311 Those features required a terminal which had been modified to work with curses.
312 They were not part of the X Consortium's xterm.
313 .PP
314 When developing the xterm mouse support for ncurses in September 1995,
315 Eric Raymond was uninterested in using the same interface due to its
316 lack of documentation.
317 Later, in 1998, Mark Hesseling provided support in
318 PDCurses 2.3 using the SVr4 interface.
319 PDCurses, however, does not use video terminals,
320 making it unnecessary to be concerned about compatibility with the
321 escape sequences.
322 .PP
323 The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
324 can be used to test whether these features are present.
325 If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
326 incremented.
327 These values for \fBNCURSES_MOUSE_VERSION\fR may be
328 specified when configuring ncurses:
329 .RS 3
330 .TP 3
331 1
332 has definitions for reserved events.
333 The mask uses 28 bits.
334 .TP 3
335 2
336 adds definitions for button 5,
337 removes the definitions for reserved events.
338 The mask uses 29 bits.
339 .RE
340 .PP
341 The order of the \fBMEVENT\fR structure members is not guaranteed.
342 Additional fields may be added to the structure in the future.
343 .PP
344 Under \fBncurses\fR(3X), these calls are implemented using either
345 xterm's built-in mouse-tracking API or
346 platform-specific drivers including
347 .RS 3
348 .bP
349 Alessandro Rubini's gpm server
350 .bP
351 FreeBSD sysmouse
352 .bP
353 OS/2 EMX
354 .RE
355 .PP
356 If you are using an unsupported configuration,
357 mouse events will not be visible to
358 \fBncurses\fR(3X) (and the \fBmousemask\fR function will always
359 return \fB0\fR).
360 .PP
361 If the terminfo entry contains a \fBXM\fR string,
362 this is used in the xterm mouse driver to control the
363 way the terminal is initialized for mouse operation.
364 The default, if \fBXM\fR is not found,
365 corresponds to private mode 1000 of xterm:
366 .PP
367 .RS 3
368 \\E[?1000%?%p1%{1}%=%th%el%;
369 .RE
370 .PP
371 The \fIz\fP member in the event structure is not presently used.
372 It is intended
373 for use with touch screens (which may be pressure-sensitive) or with
374 3D-mice/trackballs/power gloves.
375 .PP
376 The \fBALL_MOUSE_EVENTS\fP class does not include \fBREPORT_MOUSE_POSITION\fP.
377 They are distinct.
378 For example, in xterm,
379 wheel/scrolling mice send position reports as a sequence of
380 presses of buttons 4 or 5 without matching button-releases.
381 .SH BUGS
382 Mouse events under xterm will not in fact be ignored during cooked mode,
383 if they have been enabled by \fBmousemask\fR.
384 Instead, the xterm mouse
385 report sequence will appear in the string read.
386 .PP
387 Mouse events under xterm will not be detected correctly in a window with
388 its keypad bit off, since they are interpreted as a variety of function key.
389 Your terminfo description should have \fBkmous\fR set to "\\E[M"
390 (the beginning of the response from xterm for mouse clicks).
391 Other values for \fBkmous\fR are permitted,
392 but under the same assumption,
393 i.e., it is the beginning of the response.
394 .PP
395 Because there are no standard terminal responses that would serve to identify
396 terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
397 if your $TERM environment variable contains "xterm",
398 or \fBkmous\fR is defined in
399 the terminal description, then the terminal may send mouse events.
400 .SH SEE ALSO
401 \fBcurses\fR(3X),
402 \fBcurs_kernel\fR(3X),
403 \fBcurs_slk\fR(3X),
404 \fBcurs_variables\fR(3X).