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