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