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