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