blob: b7cf4c6ca2399fae8b21bec9785c5948d0fab2b7 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301'\" t
2.\"***************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01003.\" Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304.\" *
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.\"
Steve Kondikae271bc2015-11-15 02:50:53 +010030.\" $Id: curs_mouse.3x,v 1.42 2015/07/21 09:27:39 tom Exp $
31.de bP
32.IP \(bu 4
33..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053034.TH curs_mouse 3X ""
35.na
36.hy 0
37.SH NAME
Steve Kondikae271bc2015-11-15 02:50:53 +010038\fBhas_mouse\fR,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053039\fBgetmouse\fR, \fBungetmouse\fR,
40\fBmousemask\fR, \fBwenclose\fR,
41\fBmouse_trafo\fR, \fBwmouse_trafo\fR,
Steve Kondikae271bc2015-11-15 02:50:53 +010042\fBmouseinterval\fR \- mouse interface through curses
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053043.ad
44.hy
45.SH SYNOPSIS
Steve Kondikae271bc2015-11-15 02:50:53 +010046\fB#include <curses.h>\fR
47.PP
48\fBtypedef unsigned long mmask_t;\fR
49.PP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053050.nf
Steve Kondikae271bc2015-11-15 02:50:53 +010051\fBtypedef struct {\fR
52\fB short id; \fR\fI/* ID to distinguish multiple devices */\fR
53\fB int x, y, z; \fR\fI/* event coordinates */\fR
54\fB mmask_t bstate; \fR\fI/* button state bits */\fR
55\fB} MEVENT;\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056.fi
Steve Kondikae271bc2015-11-15 02:50:53 +010057.PP
58\fBbool has_mouse(void);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053059.br
Steve Kondikae271bc2015-11-15 02:50:53 +010060\fBint getmouse(MEVENT *\fP\fIevent\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053061.br
Steve Kondikae271bc2015-11-15 02:50:53 +010062\fBint ungetmouse(MEVENT *\fP\fIevent\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053063.br
Steve Kondikae271bc2015-11-15 02:50:53 +010064\fBmmask_t mousemask(mmask_t \fP\fInewmask\fP\fB, mmask_t *\fP\fIoldmask\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053065.br
Steve Kondikae271bc2015-11-15 02:50:53 +010066\fBbool wenclose(const WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053067.br
Steve Kondikae271bc2015-11-15 02:50:53 +010068\fBbool mouse_trafo(int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB, bool \fP\fIto_screen\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053069.br
Steve Kondikae271bc2015-11-15 02:50:53 +010070\fBbool wmouse_trafo(const WINDOW* \fP\fIwin\fP\fB, int* \fP\fIpY\fP\fB, int* \fP\fIpX\fP\fB,\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053071.br
Steve Kondikae271bc2015-11-15 02:50:53 +010072 \fBbool \fP\fIto_screen\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053073.br
Steve Kondikae271bc2015-11-15 02:50:53 +010074\fBint mouseinterval(int \fP\fIerval\fP\fB);\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053075.br
76.SH DESCRIPTION
77These functions provide an interface to mouse events from
78\fBncurses\fR(3X).
79Mouse events are represented by \fBKEY_MOUSE\fR
80pseudo-key values in the \fBwgetch\fR input stream.
Steve Kondikae271bc2015-11-15 02:50:53 +010081.SS mousemask
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053082.PP
83To make mouse events visible, use the \fBmousemask\fR function.
84This will set
85the mouse events to be reported.
86By default, no mouse events are reported.
87The function will return a mask to indicate which of the specified mouse events
88can be reported; on complete failure it returns 0.
89If oldmask is non-NULL,
90this function fills the indicated location with the previous value of the given
91window's mouse event mask.
92.PP
93As a side effect, setting a zero mousemask may turn off the mouse pointer;
94setting a nonzero mask may turn it on.
95Whether this happens is device-dependent.
Steve Kondikae271bc2015-11-15 02:50:53 +010096.SS Mouse events
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097.PP
98Here are the mouse event type masks which may be defined:
99.PP
100.TS
101l l
102_ _
103l l.
104\fIName\fR \fIDescription\fR
105BUTTON1_PRESSED mouse button 1 down
106BUTTON1_RELEASED mouse button 1 up
107BUTTON1_CLICKED mouse button 1 clicked
108BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
109BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
110_
111BUTTON2_PRESSED mouse button 2 down
112BUTTON2_RELEASED mouse button 2 up
113BUTTON2_CLICKED mouse button 2 clicked
114BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
115BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
116_
117BUTTON3_PRESSED mouse button 3 down
118BUTTON3_RELEASED mouse button 3 up
119BUTTON3_CLICKED mouse button 3 clicked
120BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
121BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
122_
123BUTTON4_PRESSED mouse button 4 down
124BUTTON4_RELEASED mouse button 4 up
125BUTTON4_CLICKED mouse button 4 clicked
126BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
127BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
128_
129BUTTON5_PRESSED mouse button 5 down
130BUTTON5_RELEASED mouse button 5 up
131BUTTON5_CLICKED mouse button 5 clicked
132BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked
133BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked
134_
135BUTTON_SHIFT shift was down during button state change
136BUTTON_CTRL control was down during button state change
137BUTTON_ALT alt was down during button state change
138ALL_MOUSE_EVENTS report all button state changes
139REPORT_MOUSE_POSITION report mouse movement
140_
141.TE
Steve Kondikae271bc2015-11-15 02:50:53 +0100142.SS getmouse
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530143.PP
Steve Kondikae271bc2015-11-15 02:50:53 +0100144Once a class of mouse events has been made visible in a window,
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530145calling the \fBwgetch\fR function on that window may return
146\fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
147To read the event data and pop the event off the queue, call
148\fBgetmouse\fR.
149This function will return \fBOK\fR if a mouse event
150is actually visible in the given window, \fBERR\fR otherwise.
151When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
152x in the event structure coordinates will be screen-relative character-cell
153coordinates.
154The returned state mask will have exactly one bit set to
155indicate the event type.
Steve Kondikae271bc2015-11-15 02:50:53 +0100156The corresponding data in the queue is marked invalid.
157A subsequent call to \fBgetmouse\fP will retrieve the next older
158item from the queue.
159.SS ungetmouse
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530160.PP
161The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
162It pushes
163a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
164the given state data and screen-relative character-cell coordinates.
Steve Kondikae271bc2015-11-15 02:50:53 +0100165.SS wenclose
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530166.PP
167The \fBwenclose\fR function tests whether a given pair of screen-relative
Steve Kondikae271bc2015-11-15 02:50:53 +0100168character-cell coordinates is enclosed by a given window, returning \fBTRUE\fP
169if it is and \fBFALSE\fP otherwise.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530170It is useful for determining what subset of
171the screen windows enclose the location of a mouse event.
Steve Kondikae271bc2015-11-15 02:50:53 +0100172.SS wmouse_trafo
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530173.PP
174The \fBwmouse_trafo\fR function transforms a given pair of coordinates
175from stdscr-relative coordinates
176to coordinates relative to the given window or vice versa.
Steve Kondikae271bc2015-11-15 02:50:53 +0100177The resulting stdscr-relative coordinates are not always identical
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530178to window-relative coordinates due to the mechanism to reserve lines on top
179or bottom of the screen for other purposes
Steve Kondikae271bc2015-11-15 02:50:53 +0100180(see the \fBripoffline\fP and \fBslk_init\fR calls, for example).
181.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530182If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
183\fBpY, pX\fR must reference the coordinates of a location
184inside the window \fBwin\fR.
185They are converted to window-relative coordinates and returned
186through the pointers.
187If the conversion was successful, the function returns \fBTRUE\fR.
Steve Kondikae271bc2015-11-15 02:50:53 +0100188.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530189If one of the parameters was NULL or the location is
190not inside the window, \fBFALSE\fR is returned.
Steve Kondikae271bc2015-11-15 02:50:53 +0100191.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530192If \fBto_screen\fR is
193\fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
194coordinates.
195They are converted to stdscr-relative coordinates if the
196window \fBwin\fR encloses this point.
197In this case the function returns \fBTRUE\fR.
Steve Kondikae271bc2015-11-15 02:50:53 +0100198.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530199If one of the parameters is NULL or the point is not inside the
200window, \fBFALSE\fR is returned.
Steve Kondikae271bc2015-11-15 02:50:53 +0100201The referenced coordinates
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530202are only replaced by the converted coordinates if the transformation was
203successful.
Steve Kondikae271bc2015-11-15 02:50:53 +0100204.SS mouse_trafo
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530205.PP
206The \fBmouse_trafo\fR function performs the same translation
207as \fBwmouse_trafo\fR,
208using stdscr for \fBwin\fR.
Steve Kondikae271bc2015-11-15 02:50:53 +0100209.SS mouseinterval
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530210.PP
211The \fBmouseinterval\fR function sets the maximum time (in thousands of a
212second) that can elapse between press and release events for them to
213be recognized as a click.
214Use \fBmouseinterval(0)\fR to disable click resolution.
215This function returns the previous interval value.
Steve Kondikae271bc2015-11-15 02:50:53 +0100216Use \fBmouseinterval(\-1)\fR to obtain the interval without altering it.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530217The default is one sixth of a second.
Steve Kondikae271bc2015-11-15 02:50:53 +0100218.SS has_mouse
219.PP
220The \fBhas_mouse\fP function returns \fBTRUE\fP if the mouse driver has been
221successfully initialized.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530222.PP
223Note that mouse events will be ignored when input is in cooked mode, and will
224cause an error beep when cooked mode is being simulated in a window by a
225function such as \fBgetstr\fR that expects a linefeed for input-loop
226termination.
227.SH RETURN VALUE
228\fBgetmouse\fR and \fBungetmouse\fR
229return the integer \fBERR\fR upon failure or \fBOK\fR
Steve Kondikae271bc2015-11-15 02:50:53 +0100230upon successful completion:
231.RS 3
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530232.TP 5
233\fBgetmouse\fP
234returns an error.
Steve Kondikae271bc2015-11-15 02:50:53 +0100235.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530236If no mouse driver was initialized, or
237if the mask parameter is zero,
Steve Kondikae271bc2015-11-15 02:50:53 +0100238.bP
239It also returns an error if no more events remain in the queue.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530240.TP 5
241\fBungetmouse\fP
242returns an error if the FIFO is full.
243.RE
244.PP
245\fBmousemask\fR
246returns the mask of reportable events.
247.PP
248\fBmouseinterval\fR
249returns the previous interval value, unless
250the terminal was not initialized.
251In that case, it returns the maximum interval value (166).
252.PP
253\fBwenclose\fR and \fBwmouse_trafo\fR
254are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
255on their test result.
256.SH PORTABILITY
257These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
258curses, 4.4BSD curses, or any other previous version of curses.
259.PP
260The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
261can be used to test whether these features are present.
262If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
263incremented.
264These values for \fBNCURSES_MOUSE_VERSION\fR may be
265specified when configuring ncurses:
Steve Kondikae271bc2015-11-15 02:50:53 +0100266.RS 3
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530267.TP 3
2681
269has definitions for reserved events.
270The mask uses 28 bits.
271.TP 3
2722
273adds definitions for button 5,
274removes the definitions for reserved events.
275The mask uses 29 bits.
276.RE
277.PP
278The order of the \fBMEVENT\fR structure members is not guaranteed.
279Additional fields may be added to the structure in the future.
280.PP
281Under \fBncurses\fR(3X), these calls are implemented using either
282xterm's built-in mouse-tracking API or
283platform-specific drivers including
Steve Kondikae271bc2015-11-15 02:50:53 +0100284.RS 3
285.bP
286Alessandro Rubini's gpm server
287.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530288FreeBSD sysmouse
Steve Kondikae271bc2015-11-15 02:50:53 +0100289.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530290OS/2 EMX
291.RE
Steve Kondikae271bc2015-11-15 02:50:53 +0100292.PP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530293If you are using an unsupported configuration,
294mouse events will not be visible to
295\fBncurses\fR(3X) (and the \fBmousemask\fR function will always
296return \fB0\fR).
297.PP
298If the terminfo entry contains a \fBXM\fR string,
299this is used in the xterm mouse driver to control the
300way the terminal is initialized for mouse operation.
301The default, if \fBXM\fR is not found,
302corresponds to private mode 1000 of xterm:
Steve Kondikae271bc2015-11-15 02:50:53 +0100303.PP
304.RS 3
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530305\\E[?1000%?%p1%{1}%=%th%el%;
306.RE
Steve Kondikae271bc2015-11-15 02:50:53 +0100307.PP
308The \fIz\fP member in the event structure is not presently used.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530309It is intended
310for use with touch screens (which may be pressure-sensitive) or with
3113D-mice/trackballs/power gloves.
Steve Kondikae271bc2015-11-15 02:50:53 +0100312.PP
313The \fBALL_MOUSE_EVENTS\fP class does not include \fBREPORT_MOUSE_POSITION\fP.
314They are distinct.
315For example, in xterm,
316wheel/scrolling mice send position reports as a sequence of
317presses of buttons 4 or 5 without matching button-releases.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530318.SH BUGS
319Mouse events under xterm will not in fact be ignored during cooked mode,
320if they have been enabled by \fBmousemask\fR.
321Instead, the xterm mouse
322report sequence will appear in the string read.
323.PP
324Mouse events under xterm will not be detected correctly in a window with
325its keypad bit off, since they are interpreted as a variety of function key.
326Your terminfo description should have \fBkmous\fR set to "\\E[M"
327(the beginning of the response from xterm for mouse clicks).
328Other values for \fBkmous\fR are permitted,
329but under the same assumption,
330i.e., it is the beginning of the response.
331.PP
332Because there are no standard terminal responses that would serve to identify
333terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
334if your $TERM environment variable contains "xterm",
335or \fBkmous\fR is defined in
336the terminal description, then the terminal may send mouse events.
337.SH SEE ALSO
338\fBcurses\fR(3X),
339\fBcurs_kernel\fR(3X),
Steve Kondikae271bc2015-11-15 02:50:53 +0100340\fBcurs_slk\fR(3X),
341\fBcurs_variables\fR(3X).