]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_mouse.3x
ncurses 6.2 - patch 20200301
[ncurses.git] / man / curs_mouse.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2019,2020 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.52 2020/02/02 23:34:34 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\fR,
59 \fBgetmouse\fR, \fBungetmouse\fR,
60 \fBmousemask\fR, \fBwenclose\fR,
61 \fBmouse_trafo\fR, \fBwmouse_trafo\fR,
62 \fBmouseinterval\fR \- mouse interface through curses
63 .ad
64 .hy
65 .SH SYNOPSIS
66 \fB#include <curses.h>\fR
67 .PP
68 \fBtypedef unsigned long mmask_t;\fR
69 .PP
70 .nf
71 \fBtypedef struct {\fR
72 \fB    short id;         \fR\fI/* ID to distinguish multiple devices */\fR
73 \fB    int x, y, z;      \fR\fI/* event coordinates */\fR
74 \fB    mmask_t bstate;   \fR\fI/* button state bits */\fR
75 \fB} MEVENT;\fR
76 .fi
77 .PP
78 \fBbool has_mouse(void);\fR
79 .br
80 \fBint getmouse(MEVENT *\fP\fIevent\fP\fB);\fR
81 .br
82 \fBint ungetmouse(MEVENT *\fP\fIevent\fP\fB);\fR
83 .br
84 \fBmmask_t mousemask(mmask_t \fP\fInewmask\fP\fB, mmask_t *\fP\fIoldmask\fP\fB);\fR
85 .br
86 \fBbool wenclose(const WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB);\fR
87 .br
88 \fBbool mouse_trafo(int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB, bool \fP\fIto_screen\fP\fB);\fR
89 .br
90 \fBbool wmouse_trafo(const WINDOW* \fP\fIwin\fP\fB, int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB,\fR
91 .br
92         \fBbool \fP\fIto_screen\fP\fB);\fR
93 .br
94 \fBint mouseinterval(int \fP\fIerval\fP\fB);\fR
95 .br
96 .SH DESCRIPTION
97 These functions provide an interface to mouse events from
98 \fBncurses\fR(3X).
99 Mouse events are represented by \fBKEY_MOUSE\fR
100 pseudo-key values in the \fBwgetch\fR(3X) input stream.
101 .SS mousemask
102 .PP
103 To make mouse events visible, use the \fBmousemask\fR function.
104 This will set
105 the mouse events to be reported.
106 By default, no mouse events are reported.
107 The function will return a mask to indicate which of the specified mouse events
108 can be reported; on complete failure it returns 0.
109 If oldmask is non-NULL,
110 this function fills the indicated location with the previous value of the given
111 window's mouse event mask.
112 .PP
113 As a side effect, setting a zero mousemask may turn off the mouse pointer;
114 setting a nonzero mask may turn it on.
115 Whether this happens is device-dependent.
116 .SS Mouse events
117 .PP
118 Here are the mouse event type masks which may be defined:
119 .PP
120 .TS
121 l l
122 _ _
123 l l.
124 \fIName\fR      \fIDescription\fR
125 BUTTON1_PRESSED mouse button 1 down
126 BUTTON1_RELEASED        mouse button 1 up
127 BUTTON1_CLICKED mouse button 1 clicked
128 BUTTON1_DOUBLE_CLICKED  mouse button 1 double clicked
129 BUTTON1_TRIPLE_CLICKED  mouse button 1 triple clicked
130 _
131 BUTTON2_PRESSED mouse button 2 down
132 BUTTON2_RELEASED        mouse button 2 up
133 BUTTON2_CLICKED mouse button 2 clicked
134 BUTTON2_DOUBLE_CLICKED  mouse button 2 double clicked
135 BUTTON2_TRIPLE_CLICKED  mouse button 2 triple clicked
136 _
137 BUTTON3_PRESSED mouse button 3 down
138 BUTTON3_RELEASED        mouse button 3 up
139 BUTTON3_CLICKED mouse button 3 clicked
140 BUTTON3_DOUBLE_CLICKED  mouse button 3 double clicked
141 BUTTON3_TRIPLE_CLICKED  mouse button 3 triple clicked
142 _
143 BUTTON4_PRESSED mouse button 4 down
144 BUTTON4_RELEASED        mouse button 4 up
145 BUTTON4_CLICKED mouse button 4 clicked
146 BUTTON4_DOUBLE_CLICKED  mouse button 4 double clicked
147 BUTTON4_TRIPLE_CLICKED  mouse button 4 triple clicked
148 _
149 BUTTON5_PRESSED mouse button 5 down
150 BUTTON5_RELEASED        mouse button 5 up
151 BUTTON5_CLICKED mouse button 5 clicked
152 BUTTON5_DOUBLE_CLICKED  mouse button 5 double clicked
153 BUTTON5_TRIPLE_CLICKED  mouse button 5 triple clicked
154 _
155 BUTTON_SHIFT    shift was down during button state change
156 BUTTON_CTRL     control was down during button state change
157 BUTTON_ALT      alt was down during button state change
158 ALL_MOUSE_EVENTS        report all button state changes
159 REPORT_MOUSE_POSITION   report mouse movement
160 _
161 .TE
162 .SS getmouse
163 .PP
164 Once a class of mouse events has been made visible in a window,
165 calling the \fBwgetch\fR function on that window may return
166 \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
167 To read the event data and pop the event off the queue, call
168 \fBgetmouse\fR.
169 This function will return \fBOK\fR if a mouse event
170 is actually visible in the given window, \fBERR\fR otherwise.
171 When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
172 x in the event structure coordinates will be screen-relative character-cell
173 coordinates.
174 The returned state mask will have exactly one bit set to
175 indicate the event type.
176 The corresponding data in the queue is marked invalid.
177 A subsequent call to \fBgetmouse\fP will retrieve the next older
178 item from the queue.
179 .SS ungetmouse
180 .PP
181 The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
182 It pushes
183 a \fBKEY_MOUSE\fR 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 .PP
187 The \fBwenclose\fR function tests whether a given pair of screen-relative
188 character-cell coordinates is enclosed by a given window, returning \fBTRUE\fP
189 if it is and \fBFALSE\fP otherwise.
190 It is useful for determining what subset of
191 the screen windows enclose the location of a mouse event.
192 .SS wmouse_trafo
193 .PP
194 The \fBwmouse_trafo\fR 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 \fBripoffline\fP and \fBslk_init\fR(3X) calls, for example).
201 .bP
202 If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
203 \fBpY, pX\fR must reference the coordinates of a location
204 inside the window \fBwin\fR.
205 They are converted to window-relative coordinates and returned
206 through the pointers.
207 If the conversion was successful, the function returns \fBTRUE\fR.
208 .bP
209 If one of the parameters was NULL or the location is
210 not inside the window, \fBFALSE\fR is returned.
211 .bP
212 If \fBto_screen\fR is
213 \fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
214 coordinates.
215 They are converted to stdscr-relative coordinates if the
216 window \fBwin\fR encloses this point.
217 In this case the function returns \fBTRUE\fR.
218 .bP
219 If one of the parameters is NULL or the point is not inside the
220 window, \fBFALSE\fR 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 .PP
226 The \fBmouse_trafo\fR function performs the same translation
227 as \fBwmouse_trafo\fR,
228 using stdscr for \fBwin\fR.
229 .SS mouseinterval
230 .PP
231 The \fBmouseinterval\fR function sets the maximum time (in thousands of a
232 second) that can elapse between press and release events for them to
233 be recognized as a click.
234 Use \fBmouseinterval(0)\fR to disable click resolution.
235 This function returns the previous interval value.
236 Use \fBmouseinterval(\-1)\fR to obtain the interval without altering it.
237 The default is one sixth of a second.
238 .SS has_mouse
239 .PP
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\fR that expects a linefeed for input-loop
246 termination.
247 .SH RETURN VALUE
248 \fBgetmouse\fR and \fBungetmouse\fR
249 return the integer \fBERR\fR upon failure or \fBOK\fR
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 also returns an error if no more events remain in the queue.
260 .TP 5
261 \fBungetmouse\fP
262 returns an error if the FIFO is full.
263 .RE
264 .PP
265 \fBmousemask\fR
266 returns the mask of reportable events.
267 .PP
268 \fBmouseinterval\fR
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 \fBwenclose\fR and \fBwmouse_trafo\fR
274 are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
275 on their test result.
276 .SH PORTABILITY
277 These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
278 curses, 4.4BSD curses, or any other previous version of curses.
279 .PP
280 SVr4 curses had support for the mouse in a variant of \fBxterm\fP.
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 ncurses) about the escape sequences
305 sent to and received from the terminal.
306 .IP
307 For instance
308 the SVr4 curses library used the \fBget_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 \fBreq_mouse_pos\fP capability.
313 .IP
314 Those features required a terminal which had been modified to work with curses.
315 They were not part of the X Consortium's xterm.
316 .PP
317 When developing the xterm mouse support for ncurses 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 \fBNCURSES_MOUSE_VERSION\fR 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 \fBNCURSES_MOUSE_VERSION\fR will be
329 incremented.
330 These values for \fBNCURSES_MOUSE_VERSION\fR may be
331 specified when configuring ncurses:
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 \fBMEVENT\fR structure members is not guaranteed.
345 Additional fields may be added to the structure in the future.
346 .PP
347 Under \fBncurses\fR(3X), 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 \fBncurses\fR(3X) (and the \fBmousemask\fR function will always
362 return \fB0\fR).
363 .PP
364 If the terminfo entry contains a \fBXM\fR 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\fR 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 \fBALL_MOUSE_EVENTS\fP class does not include \fBREPORT_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 \fBmousemask\fR.
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 \fBkmous\fR set to \*(``\\E[M\*(''
399 (the beginning of the response from xterm for mouse clicks).
400 Other values for \fBkmous\fR 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, \fBncurses\fR assumes that
406 if \fBkmous\fR 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 \fBkmous\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 \fBcurses\fR(3X),
415 \fBcurs_kernel\fR(3X),
416 \fBcurs_slk\fR(3X),
417 \fBcurs_variables\fR(3X).