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