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