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