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