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