]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_mouse.3x
316598a5594c9c8ced7ce5112853f12c387bfaad
[ncurses.git] / man / curs_mouse.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998,1999,2000 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.15 2000/07/08 12:50:08 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>\fR
40
41 \fBtypedef unsigned long mmask_t;
42
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(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).  Mouse events are represented by \fBKEY_MOUSE\fR
71 pseudo-key values in the \fBwgetch\fR input stream.
72
73 To make mouse events visible, use the \fBmousemask\fR function.  This will set
74 the mouse events to be reported.  By default, no mouse events are reported.
75 The function will return a mask to indicate which of the specified mouse events
76 can be reported; on complete failure it returns 0.  If oldmask is non-NULL,
77 this function fills the indicated location with the previous value of the given
78 window's mouse event mask.
79
80 As a side effect, setting a zero mousemask may turn off the mouse pointer;
81 setting a nonzero mask may turn it on.  Whether this happens is
82 device-dependent.
83
84 Here are the mouse event type masks:
85
86 .TS
87 l l
88 _ _
89 l l.
90 \fIName\fR      \fIDescription\fR
91 BUTTON1_PRESSED mouse button 1 down
92 BUTTON1_RELEASED        mouse button 1 up
93 BUTTON1_CLICKED mouse button 1 clicked
94 BUTTON1_DOUBLE_CLICKED  mouse button 1 double clicked
95 BUTTON1_TRIPLE_CLICKED  mouse button 1 triple clicked
96 BUTTON2_PRESSED mouse button 2 down
97 BUTTON2_RELEASED        mouse button 2 up
98 BUTTON2_CLICKED mouse button 2 clicked
99 BUTTON2_DOUBLE_CLICKED  mouse button 2 double clicked
100 BUTTON2_TRIPLE_CLICKED  mouse button 2 triple clicked
101 BUTTON3_PRESSED mouse button 3 down
102 BUTTON3_RELEASED        mouse button 3 up
103 BUTTON3_CLICKED mouse button 3 clicked
104 BUTTON3_DOUBLE_CLICKED  mouse button 3 double clicked
105 BUTTON3_TRIPLE_CLICKED  mouse button 3 triple clicked
106 BUTTON4_PRESSED mouse button 4 down
107 BUTTON4_RELEASED        mouse button 4 up
108 BUTTON4_CLICKED mouse button 4 clicked
109 BUTTON4_DOUBLE_CLICKED  mouse button 4 double clicked
110 BUTTON4_TRIPLE_CLICKED  mouse button 4 triple clicked
111 BUTTON_SHIFT    shift was down during button state change
112 BUTTON_CTRL     control was down during button state change
113 BUTTON_ALT      alt was down during button state change
114 ALL_MOUSE_EVENTS        report all button state changes
115 REPORT_MOUSE_POSITION   report mouse movement
116 .TE
117
118 Once a class of mouse events have been made visible in a window,
119 calling the \fBwgetch\fR function on that window may return
120 \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
121 To read the event data and pop the event off the queue, call
122 \fBgetmouse\fR.  This function will return \fBOK\fR if a mouse event
123 is actually visible in the given window, \fBERR\fR otherwise.
124 When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
125 x in the event structure coordinates will be screen-relative character-cell
126 coordinates.  The returned state mask will have exactly one bit set to
127 indicate the event type.
128
129 The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.  It pushes
130 a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
131 the given state data and screen-relative character-cell coordinates.
132
133 The \fBwenclose\fR function tests whether a given pair of screen-relative
134 character-cell coordinates is enclosed by a given window, returning TRUE
135 if it is and FALSE otherwise.  It is useful for determining what subset of
136 the screen windows enclose the location of a mouse event.
137
138 The \fBwmouse_trafo\fR function transforms a given pair of coordinates from
139 stdscr-relative coordinates to screen-relative coordinates or vice versa.
140 Please remember, that stdscr-relative coordinates are not always identical
141 to screen-relative coordinates due to the mechanism to reserve lines on top
142 or bottom of the screen for other purposes (ripoff() call, see also slk_...
143 functions). If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers 
144 \fBpY, pX\fR must reference the coordinates of a location inside the window 
145 \fBwin\fR. They are converted to screen-relative coordinates and returned
146 through the pointers. If the conversion was successful, the function
147 returns \fBTRUE\fR. If one of the parameters was NULL or the location is
148 not inside the window, \fBFALSE\fR is returned. If \fBto_screen\fR is
149 \fBFALSE\fR, the pointers \fBpY, pX\fR must reference screen-relative
150 coordinates. They are converted to stdscr-relative coordinates if the
151 window \fBwin\fR encloses this point. In this case the function returns
152 \fBTRUE\fR. If one of the parameters is NULL or the point is not inside the
153 window, \fBFALSE\fR is returned. Please notice, that the referenced coordinates
154 are only replaced by the converted coordinates if the transformation was
155 successful.
156  
157 The \fBmouseinterval\fR function sets the maximum time (in thousands of a
158 second) that can elapse between press and release events in order for them to
159 be recognized as a click.  This function returns the previous interval value.
160 The default is one fifth of a second.
161
162 Note that mouse events will be ignored when input is in cooked mode, and will
163 cause an error beep when cooked mode is being simulated in a window by a
164 function such as \fBgetstr\fR that expects a linefeed for input-loop
165 termination.
166
167 .SH RETURN VALUE
168 \fBgetmouse\fR, \fBungetmouse\fR and \fBmouseinterval\fR
169 return the integer \fBERR\fR upon failure or \fBOK\fR
170 upon successful completion. \fBmousemask\fR returns the
171 mask of reportable events. \fBwenclose\fR and \fBwmouse_trafo\fR
172 are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
173 on their test result.
174 .SH PORTABILITY
175 These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
176 curses, 4.4BSD curses, or any other previous version of curses.
177
178 The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
179 can be used to test whether these features are present (its value is 1).
180 If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
181 incremented.
182
183 The order of the \fBMEVENT\fR structure members is not guaranteed.
184 Additional fields may be added to the structure in the future.
185
186 Under \fBncurses\fR(3X), these calls are implemented using either
187 xterm's built-in mouse-tracking API or Alessandro Rubini's gpm server.
188 If you are using something other than xterm and there is no gpm daemon
189 running on your machine, mouse events will not be visible to
190 \fBncurses\fR(3X) (and the \fBwmousemask\fR function will always
191 return \fB0\fR).
192
193 The z member in the event structure is not presently used.  It is intended
194 for use with touch screens (which may be pressure-sensitive) or with
195 3D-mice/trackballs/power gloves.
196 .SH BUGS
197 Mouse events under xterm will not in fact be ignored during cooked mode,
198 if they have been enabled by \fBwmousemask\fR.  Instead, the xterm mouse
199 report sequence will appear in the string read.
200
201 Mouse events under xterm will not be detected correctly in a window with
202 its keypad bit off, since they are interpreted as a variety of function key.
203 Your terminfo description must have \fBkmous\fR set to "\\E[M" (the beginning
204 of the response from xterm for mouse clicks).
205
206 Because there are no standard terminal responses that would serve to identify
207 terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
208 if your $DISPLAY environment variable is set, and \fBkmous\fR is defined in
209 the terminal description, then the terminal may send mouse events.
210 .SH SEE ALSO
211 \fBcurses\fR(3X).
212 .\"#
213 .\"# The following sets edit modes for GNU EMACS
214 .\"# Local Variables:
215 .\"# mode:nroff
216 .\"# fill-column:79
217 .\"# End: