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