]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_mouse.3x
ncurses 6.0 - patch 20170916
[ncurses.git] / man / curs_mouse.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2015,2017 Free Software Foundation, Inc.              *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_mouse.3x,v 1.46 2017/05/20 14:42:41 Sven.Joachim Exp $
31 .ie \n(.g .ds `` \(lq
32 .el       .ds `` ``
33 .ie \n(.g .ds '' \(rq
34 .el       .ds '' ''
35 .de NS
36 .ie \n(.sp
37 .el    .sp .5
38 .ie \n(.in +4
39 .el    .in +2
40 .nf
41 .ft C                   \" Courier
42 ..
43 .de NE
44 .fi
45 .ft R
46 .in -4
47 ..
48 .de bP
49 .IP \(bu 4
50 ..
51 .TH curs_mouse 3X ""
52 .na
53 .hy 0
54 .SH NAME
55 \fBhas_mouse\fR,
56 \fBgetmouse\fR, \fBungetmouse\fR,
57 \fBmousemask\fR, \fBwenclose\fR,
58 \fBmouse_trafo\fR, \fBwmouse_trafo\fR,
59 \fBmouseinterval\fR \- mouse interface through curses
60 .ad
61 .hy
62 .SH SYNOPSIS
63 \fB#include <curses.h>\fR
64 .PP
65 \fBtypedef unsigned long mmask_t;\fR
66 .PP
67 .nf
68 \fBtypedef struct {\fR
69 \fB    short id;         \fR\fI/* ID to distinguish multiple devices */\fR
70 \fB    int x, y, z;      \fR\fI/* event coordinates */\fR
71 \fB    mmask_t bstate;   \fR\fI/* button state bits */\fR
72 \fB} MEVENT;\fR
73 .fi
74 .PP
75 \fBbool has_mouse(void);\fR
76 .br
77 \fBint getmouse(MEVENT *\fP\fIevent\fP\fB);\fR
78 .br
79 \fBint ungetmouse(MEVENT *\fP\fIevent\fP\fB);\fR
80 .br
81 \fBmmask_t mousemask(mmask_t \fP\fInewmask\fP\fB, mmask_t *\fP\fIoldmask\fP\fB);\fR
82 .br
83 \fBbool wenclose(const WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB);\fR
84 .br
85 \fBbool mouse_trafo(int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB, bool \fP\fIto_screen\fP\fB);\fR
86 .br
87 \fBbool wmouse_trafo(const WINDOW* \fP\fIwin\fP\fB, int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB,\fR
88 .br
89         \fBbool \fP\fIto_screen\fP\fB);\fR
90 .br
91 \fBint mouseinterval(int \fP\fIerval\fP\fB);\fR
92 .br
93 .SH DESCRIPTION
94 These functions provide an interface to mouse events from
95 \fBncurses\fR(3X).
96 Mouse events are represented by \fBKEY_MOUSE\fR
97 pseudo-key values in the \fBwgetch\fR(3X) input stream.
98 .SS mousemask
99 .PP
100 To make mouse events visible, use the \fBmousemask\fR function.
101 This will set
102 the mouse events to be reported.
103 By default, no mouse events are reported.
104 The function will return a mask to indicate which of the specified mouse events
105 can be reported; on complete failure it returns 0.
106 If oldmask is non-NULL,
107 this function fills the indicated location with the previous value of the given
108 window's mouse event mask.
109 .PP
110 As a side effect, setting a zero mousemask may turn off the mouse pointer;
111 setting a nonzero mask may turn it on.
112 Whether this happens is device-dependent.
113 .SS Mouse events
114 .PP
115 Here are the mouse event type masks which may be defined:
116 .PP
117 .TS
118 l l
119 _ _
120 l l.
121 \fIName\fR      \fIDescription\fR
122 BUTTON1_PRESSED mouse button 1 down
123 BUTTON1_RELEASED        mouse button 1 up
124 BUTTON1_CLICKED mouse button 1 clicked
125 BUTTON1_DOUBLE_CLICKED  mouse button 1 double clicked
126 BUTTON1_TRIPLE_CLICKED  mouse button 1 triple clicked
127 _
128 BUTTON2_PRESSED mouse button 2 down
129 BUTTON2_RELEASED        mouse button 2 up
130 BUTTON2_CLICKED mouse button 2 clicked
131 BUTTON2_DOUBLE_CLICKED  mouse button 2 double clicked
132 BUTTON2_TRIPLE_CLICKED  mouse button 2 triple clicked
133 _
134 BUTTON3_PRESSED mouse button 3 down
135 BUTTON3_RELEASED        mouse button 3 up
136 BUTTON3_CLICKED mouse button 3 clicked
137 BUTTON3_DOUBLE_CLICKED  mouse button 3 double clicked
138 BUTTON3_TRIPLE_CLICKED  mouse button 3 triple clicked
139 _
140 BUTTON4_PRESSED mouse button 4 down
141 BUTTON4_RELEASED        mouse button 4 up
142 BUTTON4_CLICKED mouse button 4 clicked
143 BUTTON4_DOUBLE_CLICKED  mouse button 4 double clicked
144 BUTTON4_TRIPLE_CLICKED  mouse button 4 triple clicked
145 _
146 BUTTON5_PRESSED mouse button 5 down
147 BUTTON5_RELEASED        mouse button 5 up
148 BUTTON5_CLICKED mouse button 5 clicked
149 BUTTON5_DOUBLE_CLICKED  mouse button 5 double clicked
150 BUTTON5_TRIPLE_CLICKED  mouse button 5 triple clicked
151 _
152 BUTTON_SHIFT    shift was down during button state change
153 BUTTON_CTRL     control was down during button state change
154 BUTTON_ALT      alt was down during button state change
155 ALL_MOUSE_EVENTS        report all button state changes
156 REPORT_MOUSE_POSITION   report mouse movement
157 _
158 .TE
159 .SS getmouse
160 .PP
161 Once a class of mouse events has been made visible in a window,
162 calling the \fBwgetch\fR function on that window may return
163 \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
164 To read the event data and pop the event off the queue, call
165 \fBgetmouse\fR.
166 This function will return \fBOK\fR if a mouse event
167 is actually visible in the given window, \fBERR\fR otherwise.
168 When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
169 x in the event structure coordinates will be screen-relative character-cell
170 coordinates.
171 The returned state mask will have exactly one bit set to
172 indicate the event type.
173 The corresponding data in the queue is marked invalid.
174 A subsequent call to \fBgetmouse\fP will retrieve the next older
175 item from the queue.
176 .SS ungetmouse
177 .PP
178 The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
179 It pushes
180 a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
181 the given state data and screen-relative character-cell coordinates.
182 .SS wenclose
183 .PP
184 The \fBwenclose\fR function tests whether a given pair of screen-relative
185 character-cell coordinates is enclosed by a given window, returning \fBTRUE\fP
186 if it is and \fBFALSE\fP otherwise.
187 It is useful for determining what subset of
188 the screen windows enclose the location of a mouse event.
189 .SS wmouse_trafo
190 .PP
191 The \fBwmouse_trafo\fR function transforms a given pair of coordinates
192 from stdscr-relative coordinates
193 to coordinates relative to the given window or vice versa.
194 The resulting stdscr-relative coordinates are not always identical
195 to window-relative coordinates due to the mechanism to reserve lines on top
196 or bottom of the screen for other purposes
197 (see the \fBripoffline\fP and \fBslk_init\fR(3X) calls, for example).
198 .bP
199 If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
200 \fBpY, pX\fR must reference the coordinates of a location
201 inside the window \fBwin\fR.
202 They are converted to window-relative coordinates and returned
203 through the pointers.
204 If the conversion was successful, the function returns \fBTRUE\fR.
205 .bP
206 If one of the parameters was NULL or the location is
207 not inside the window, \fBFALSE\fR is returned.
208 .bP
209 If \fBto_screen\fR is
210 \fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
211 coordinates.
212 They are converted to stdscr-relative coordinates if the
213 window \fBwin\fR encloses this point.
214 In this case the function returns \fBTRUE\fR.
215 .bP
216 If one of the parameters is NULL or the point is not inside the
217 window, \fBFALSE\fR is returned.
218 The referenced coordinates
219 are only replaced by the converted coordinates if the transformation was
220 successful.
221 .SS mouse_trafo
222 .PP
223 The \fBmouse_trafo\fR function performs the same translation
224 as \fBwmouse_trafo\fR,
225 using stdscr for \fBwin\fR.
226 .SS mouseinterval
227 .PP
228 The \fBmouseinterval\fR function sets the maximum time (in thousands of a
229 second) that can elapse between press and release events for them to
230 be recognized as a click.
231 Use \fBmouseinterval(0)\fR to disable click resolution.
232 This function returns the previous interval value.
233 Use \fBmouseinterval(\-1)\fR to obtain the interval without altering it.
234 The default is one sixth of a second.
235 .SS has_mouse
236 .PP
237 The \fBhas_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 \fBgetstr\fR that expects a linefeed for input-loop
243 termination.
244 .SH RETURN VALUE
245 \fBgetmouse\fR and \fBungetmouse\fR
246 return the integer \fBERR\fR upon failure or \fBOK\fR
247 upon successful completion:
248 .RS 3
249 .TP 5
250 \fBgetmouse\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 also returns an error if no more events remain in the queue.
257 .TP 5
258 \fBungetmouse\fP
259 returns an error if the FIFO is full.
260 .RE
261 .PP
262 \fBmousemask\fR
263 returns the mask of reportable events.
264 .PP
265 \fBmouseinterval\fR
266 returns the previous interval value, unless
267 the terminal was not initialized.
268 In that case, it returns the maximum interval value (166).
269 .PP
270 \fBwenclose\fR and \fBwmouse_trafo\fR
271 are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
272 on their test result.
273 .SH PORTABILITY
274 These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
275 curses, 4.4BSD curses, or any other previous version of curses.
276 .PP
277 SVr4 curses had support for the mouse in a variant of \fBxterm\fP.
278 It is mentioned in a few places, but with no supporting documentation:
279 .bP
280 the \*(``libcurses\*('' manual page lists functions for this feature
281 which are prototyped in \fBcurses.h\fP:
282 .NS
283 extern int mouse_set(long int);
284 extern int mouse_on(long int);
285 extern int mouse_off(long int);
286 extern int request_mouse_pos(void);
287 extern int map_button(unsigned long);
288 extern void wmouse_position(WINDOW *, int *, int *);
289 extern unsigned long getmouse(void), getbmap(void);
290 .NE
291 .bP
292 the \*(``terminfo\*('' manual page lists capabilities for the feature
293 .NS
294 buttons           btns    BT       Number of buttons on the mouse
295 get_mouse         getm    Gm       Curses should get button events
296 key_mouse         kmous   Km       0631, Mouse event has occurred
297 mouse_info        minfo   Mi       Mouse status information
298 req_mouse_pos     reqmp   RQ       Request mouse position report
299 .NE
300 .bP
301 the interface made assumptions (as does ncurses) about the escape sequences
302 sent to and received from the terminal.
303 .IP
304 For instance
305 the SVr4 curses library used the \fBget_mouse\fP capability to tell the
306 terminal which mouse button events it should send,
307 passing the mouse-button bit-mask to the terminal.
308 Also, it could ask the terminal where the mouse was using the \fBreq_mouse_pos\fP capability.
309 .IP
310 Those features required a terminal which had been modified to work with curses.
311 They were not part of the X Consortium's xterm.
312 .PP
313 When developing the xterm mouse support for ncurses in September 1995,
314 Eric Raymond was uninterested in using the same interface due to its
315 lack of documentation.
316 Later, in 1998, Mark Hesseling provided support in
317 PDCurses 2.3 using the SVr4 interface.
318 PDCurses, however, does not use video terminals,
319 making it unnecessary to be concerned about compatibility with the
320 escape sequences.
321 .PP
322 The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
323 can be used to test whether these features are present.
324 If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
325 incremented.
326 These values for \fBNCURSES_MOUSE_VERSION\fR may be
327 specified when configuring ncurses:
328 .RS 3
329 .TP 3
330 1
331 has definitions for reserved events.
332 The mask uses 28 bits.
333 .TP 3
334 2
335 adds definitions for button 5,
336 removes the definitions for reserved events.
337 The mask uses 29 bits.
338 .RE
339 .PP
340 The order of the \fBMEVENT\fR structure members is not guaranteed.
341 Additional fields may be added to the structure in the future.
342 .PP
343 Under \fBncurses\fR(3X), these calls are implemented using either
344 xterm's built-in mouse-tracking API or
345 platform-specific drivers including
346 .RS 3
347 .bP
348 Alessandro Rubini's gpm server
349 .bP
350 FreeBSD sysmouse
351 .bP
352 OS/2 EMX
353 .RE
354 .PP
355 If you are using an unsupported configuration,
356 mouse events will not be visible to
357 \fBncurses\fR(3X) (and the \fBmousemask\fR function will always
358 return \fB0\fR).
359 .PP
360 If the terminfo entry contains a \fBXM\fR string,
361 this is used in the xterm mouse driver to control the
362 way the terminal is initialized for mouse operation.
363 The default, if \fBXM\fR is not found,
364 corresponds to private mode 1000 of xterm:
365 .PP
366 .RS 3
367 \\E[?1000%?%p1%{1}%=%th%el%;
368 .RE
369 .PP
370 The \fIz\fP member in the event structure is not presently used.
371 It is intended
372 for use with touch screens (which may be pressure-sensitive) or with
373 3D-mice/trackballs/power gloves.
374 .PP
375 The \fBALL_MOUSE_EVENTS\fP class does not include \fBREPORT_MOUSE_POSITION\fP.
376 They are distinct.
377 For example, in xterm,
378 wheel/scrolling mice send position reports as a sequence of
379 presses of buttons 4 or 5 without matching button-releases.
380 .SH BUGS
381 Mouse events under xterm will not in fact be ignored during cooked mode,
382 if they have been enabled by \fBmousemask\fR.
383 Instead, the xterm mouse
384 report sequence will appear in the string read.
385 .PP
386 Mouse events under xterm will not be detected correctly in a window with
387 its keypad bit off, since they are interpreted as a variety of function key.
388 Your terminfo description should have \fBkmous\fR set to "\\E[M"
389 (the beginning of the response from xterm for mouse clicks).
390 Other values for \fBkmous\fR are permitted,
391 but under the same assumption,
392 i.e., it is the beginning of the response.
393 .PP
394 Because there are no standard terminal responses that would serve to identify
395 terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
396 if your $TERM environment variable contains "xterm",
397 or \fBkmous\fR is defined in
398 the terminal description, then the terminal may send mouse events.
399 .SH SEE ALSO
400 \fBcurses\fR(3X),
401 \fBcurs_kernel\fR(3X),
402 \fBcurs_slk\fR(3X),
403 \fBcurs_variables\fR(3X).