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