]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_mouse.3x
ncurses 5.9 - patch 20131221
[ncurses.git] / man / curs_mouse.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2010,2013 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.39 2013/06/22 18:09:42 tom Exp $
31 .TH curs_mouse 3X ""
32 .na
33 .hy 0
34 .SH NAME
35 \fBhas_mouse\fR,
36 \fBgetmouse\fR, \fBungetmouse\fR,
37 \fBmousemask\fR, \fBwenclose\fR,
38 \fBmouse_trafo\fR, \fBwmouse_trafo\fR,
39 \fBmouseinterval\fR \- mouse interface through curses
40 .ad
41 .hy
42 .SH SYNOPSIS
43 \fB#include <curses.h>\fR
44 .PP
45 \fBtypedef unsigned long mmask_t;\fR
46 .PP
47 .nf
48 \fBtypedef struct {\fR
49 \fB    short id;         \fR\fI/* ID to distinguish multiple devices */\fR
50 \fB    int x, y, z;      \fR\fI/* event coordinates */\fR
51 \fB    mmask_t bstate;   \fR\fI/* button state bits */\fR
52 \fB} MEVENT;\fR
53 .fi
54 .PP
55 \fBbool has_mouse(void);\fR
56 .br
57 \fBint getmouse(MEVENT *event);\fR
58 .br
59 \fBint ungetmouse(MEVENT *event);\fR
60 .br
61 \fBmmask_t mousemask(mmask_t newmask, mmask_t *oldmask);\fR
62 .br
63 \fBbool wenclose(const WINDOW *win, int y, int x);\fR
64 .br
65 \fBbool mouse_trafo(int* pY, int* pX, bool to_screen);\fR
66 .br
67 \fBbool wmouse_trafo(const WINDOW* win, int* pY, int* pX,\fR
68 .br
69         \fBbool to_screen);\fR
70 .br
71 \fBint mouseinterval(int erval);\fR
72 .br
73 .SH DESCRIPTION
74 These functions provide an interface to mouse events from
75 \fBncurses\fR(3X).
76 Mouse events are represented by \fBKEY_MOUSE\fR
77 pseudo-key values in the \fBwgetch\fR input stream.
78 .PP
79 To make mouse events visible, use the \fBmousemask\fR function.
80 This will set
81 the mouse events to be reported.
82 By default, no mouse events are reported.
83 The function will return a mask to indicate which of the specified mouse events
84 can be reported; on complete failure it returns 0.
85 If oldmask is non-NULL,
86 this function fills the indicated location with the previous value of the given
87 window's mouse event mask.
88 .PP
89 As a side effect, setting a zero mousemask may turn off the mouse pointer;
90 setting a nonzero mask may turn it on.
91 Whether this happens is device-dependent.
92 .PP
93 Here are the mouse event type masks which may be defined:
94 .PP
95 .TS
96 l l
97 _ _
98 l l.
99 \fIName\fR      \fIDescription\fR
100 BUTTON1_PRESSED mouse button 1 down
101 BUTTON1_RELEASED        mouse button 1 up
102 BUTTON1_CLICKED mouse button 1 clicked
103 BUTTON1_DOUBLE_CLICKED  mouse button 1 double clicked
104 BUTTON1_TRIPLE_CLICKED  mouse button 1 triple clicked
105 _
106 BUTTON2_PRESSED mouse button 2 down
107 BUTTON2_RELEASED        mouse button 2 up
108 BUTTON2_CLICKED mouse button 2 clicked
109 BUTTON2_DOUBLE_CLICKED  mouse button 2 double clicked
110 BUTTON2_TRIPLE_CLICKED  mouse button 2 triple clicked
111 _
112 BUTTON3_PRESSED mouse button 3 down
113 BUTTON3_RELEASED        mouse button 3 up
114 BUTTON3_CLICKED mouse button 3 clicked
115 BUTTON3_DOUBLE_CLICKED  mouse button 3 double clicked
116 BUTTON3_TRIPLE_CLICKED  mouse button 3 triple clicked
117 _
118 BUTTON4_PRESSED mouse button 4 down
119 BUTTON4_RELEASED        mouse button 4 up
120 BUTTON4_CLICKED mouse button 4 clicked
121 BUTTON4_DOUBLE_CLICKED  mouse button 4 double clicked
122 BUTTON4_TRIPLE_CLICKED  mouse button 4 triple clicked
123 _
124 BUTTON5_PRESSED mouse button 5 down
125 BUTTON5_RELEASED        mouse button 5 up
126 BUTTON5_CLICKED mouse button 5 clicked
127 BUTTON5_DOUBLE_CLICKED  mouse button 5 double clicked
128 BUTTON5_TRIPLE_CLICKED  mouse button 5 triple clicked
129 _
130 BUTTON_SHIFT    shift was down during button state change
131 BUTTON_CTRL     control was down during button state change
132 BUTTON_ALT      alt was down during button state change
133 ALL_MOUSE_EVENTS        report all button state changes
134 REPORT_MOUSE_POSITION   report mouse movement
135 _
136 .TE
137 .PP
138 Once a class of mouse events have been made visible in a window,
139 calling the \fBwgetch\fR function on that window may return
140 \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
141 To read the event data and pop the event off the queue, call
142 \fBgetmouse\fR.
143 This function will return \fBOK\fR if a mouse event
144 is actually visible in the given window, \fBERR\fR otherwise.
145 When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
146 x in the event structure coordinates will be screen-relative character-cell
147 coordinates.
148 The returned state mask will have exactly one bit set to
149 indicate the event type.
150 The corresponding data in the queue is marked invalid.
151 A subsequent call to \fBgetmouse\fP will retrieve the next older
152 item from the queue.
153 .PP
154 The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
155 It pushes
156 a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
157 the given state data and screen-relative character-cell coordinates.
158 .PP
159 The \fBwenclose\fR function tests whether a given pair of screen-relative
160 character-cell coordinates is enclosed by a given window, returning TRUE
161 if it is and FALSE otherwise.
162 It is useful for determining what subset of
163 the screen windows enclose the location of a mouse event.
164 .PP
165 The \fBwmouse_trafo\fR function transforms a given pair of coordinates
166 from stdscr-relative coordinates
167 to coordinates relative to the given window or vice versa.
168 Please remember, that stdscr-relative coordinates are not always identical
169 to window-relative coordinates due to the mechanism to reserve lines on top
170 or bottom of the screen for other purposes
171 (see the \fBripoffline()\fP and \fBslk_init\fR calls, for example).
172 If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
173 \fBpY, pX\fR must reference the coordinates of a location
174 inside the window \fBwin\fR.
175 They are converted to window-relative coordinates and returned
176 through the pointers.
177 If the conversion was successful, the function returns \fBTRUE\fR.
178 If one of the parameters was NULL or the location is
179 not inside the window, \fBFALSE\fR is returned.
180 If \fBto_screen\fR is
181 \fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
182 coordinates.
183 They are converted to stdscr-relative coordinates if the
184 window \fBwin\fR encloses this point.
185 In this case the function returns \fBTRUE\fR.
186 If one of the parameters is NULL or the point is not inside the
187 window, \fBFALSE\fR is returned.
188 Please notice, that the referenced coordinates
189 are only replaced by the converted coordinates if the transformation was
190 successful.
191 .PP
192 The \fBmouse_trafo\fR function performs the same translation
193 as \fBwmouse_trafo\fR,
194 using stdscr for \fBwin\fR.
195 .PP
196 The \fBmouseinterval\fR function sets the maximum time (in thousands of a
197 second) that can elapse between press and release events for them to
198 be recognized as a click.
199 Use \fBmouseinterval(0)\fR to disable click resolution.
200 This function returns the previous interval value.
201 Use \fBmouseinterval(\-1)\fR to obtain the interval without altering it.
202 The default is one sixth of a second.
203 .PP
204 The \fBhas_mouse\fP function returns TRUE if the mouse driver has been
205 successfully initialized.
206 .PP
207 Note that mouse events will be ignored when input is in cooked mode, and will
208 cause an error beep when cooked mode is being simulated in a window by a
209 function such as \fBgetstr\fR that expects a linefeed for input-loop
210 termination.
211 .SH RETURN VALUE
212 \fBgetmouse\fR and \fBungetmouse\fR
213 return the integer \fBERR\fR upon failure or \fBOK\fR
214 upon successful completion.
215 .RS
216 .TP 5
217 \fBgetmouse\fP
218 returns an error.
219 If no mouse driver was initialized, or
220 if the mask parameter is zero,
221 it also returns an error if no more events remain in the queue.
222 .TP 5
223 \fBungetmouse\fP
224 returns an error if the FIFO is full.
225 .RE
226 .PP
227 \fBmousemask\fR
228 returns the mask of reportable events.
229 .PP
230 \fBmouseinterval\fR
231 returns the previous interval value, unless
232 the terminal was not initialized.
233 In that case, it returns the maximum interval value (166).
234 .PP
235 \fBwenclose\fR and \fBwmouse_trafo\fR
236 are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
237 on their test result.
238 .SH PORTABILITY
239 These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
240 curses, 4.4BSD curses, or any other previous version of curses.
241 .PP
242 The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
243 can be used to test whether these features are present.
244 If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
245 incremented.
246 These values for \fBNCURSES_MOUSE_VERSION\fR may be
247 specified when configuring ncurses:
248 .RS
249 .TP 3
250 1
251 has definitions for reserved events.
252 The mask uses 28 bits.
253 .TP 3
254 2
255 adds definitions for button 5,
256 removes the definitions for reserved events.
257 The mask uses 29 bits.
258 .RE
259 .PP
260 The order of the \fBMEVENT\fR structure members is not guaranteed.
261 Additional fields may be added to the structure in the future.
262 .PP
263 Under \fBncurses\fR(3X), these calls are implemented using either
264 xterm's built-in mouse-tracking API or
265 platform-specific drivers including
266 .RS
267 Alessandro Rubini's gpm server
268 .br
269 FreeBSD sysmouse
270 .br
271 OS/2 EMX
272 .RE
273 If you are using an unsupported configuration,
274 mouse events will not be visible to
275 \fBncurses\fR(3X) (and the \fBmousemask\fR function will always
276 return \fB0\fR).
277 .PP
278 If the terminfo entry contains a \fBXM\fR string,
279 this is used in the xterm mouse driver to control the
280 way the terminal is initialized for mouse operation.
281 The default, if \fBXM\fR is not found,
282 corresponds to private mode 1000 of xterm:
283 .RS
284 \\E[?1000%?%p1%{1}%=%th%el%;
285 .RE
286 The z member in the event structure is not presently used.
287 It is intended
288 for use with touch screens (which may be pressure-sensitive) or with
289 3D-mice/trackballs/power gloves.
290 .SH BUGS
291 Mouse events under xterm will not in fact be ignored during cooked mode,
292 if they have been enabled by \fBmousemask\fR.
293 Instead, the xterm mouse
294 report sequence will appear in the string read.
295 .PP
296 Mouse events under xterm will not be detected correctly in a window with
297 its keypad bit off, since they are interpreted as a variety of function key.
298 Your terminfo description should have \fBkmous\fR set to "\\E[M"
299 (the beginning of the response from xterm for mouse clicks).
300 Other values for \fBkmous\fR are permitted,
301 but under the same assumption,
302 i.e., it is the beginning of the response.
303 .PP
304 Because there are no standard terminal responses that would serve to identify
305 terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
306 if your $TERM environment variable contains "xterm",
307 or \fBkmous\fR is defined in
308 the terminal description, then the terminal may send mouse events.
309 .SH SEE ALSO
310 \fBcurses\fR(3X),
311 \fBcurs_kernel\fR(3X),
312 \fBcurs_slk\fR(3X),
313 \fBcurs_variables\fR(3X).