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