Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | '\" t |
| 2 | .\"*************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 3 | .\" Copyright 2018-2023,2024 Thomas E. Dickey * |
| 4 | .\" Copyright 1998-2015,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 5 | .\" * |
| 6 | .\" Permission is hereby granted, free of charge, to any person obtaining a * |
| 7 | .\" copy of this software and associated documentation files (the * |
| 8 | .\" "Software"), to deal in the Software without restriction, including * |
| 9 | .\" without limitation the rights to use, copy, modify, merge, publish, * |
| 10 | .\" distribute, distribute with modifications, sublicense, and/or sell * |
| 11 | .\" copies of the Software, and to permit persons to whom the Software is * |
| 12 | .\" furnished to do so, subject to the following conditions: * |
| 13 | .\" * |
| 14 | .\" The above copyright notice and this permission notice shall be included * |
| 15 | .\" in all copies or substantial portions of the Software. * |
| 16 | .\" * |
| 17 | .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 18 | .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 19 | .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 20 | .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 21 | .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 22 | .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 23 | .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 24 | .\" * |
| 25 | .\" Except as contained in this notice, the name(s) of the above copyright * |
| 26 | .\" holders shall not be used in advertising or otherwise to promote the * |
| 27 | .\" sale, use or other dealings in this Software without prior written * |
| 28 | .\" authorization. * |
| 29 | .\"*************************************************************************** |
| 30 | .\" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 31 | .\" $Id: curs_mouse.3x,v 1.98 2024/04/20 19:02:07 tom Exp $ |
| 32 | .TH curs_mouse 3X 2024-04-20 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls" |
| 33 | .ie \n(.g \{\ |
| 34 | .ds `` \(lq |
| 35 | .ds '' \(rq |
| 36 | .\} |
| 37 | .el \{\ |
| 38 | .ie t .ds `` `` |
| 39 | .el .ds `` "" |
| 40 | .ie t .ds '' '' |
| 41 | .el .ds '' "" |
| 42 | .\} |
| 43 | . |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 44 | .de bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 45 | .ie n .IP \(bu 4 |
| 46 | .el .IP \(bu 2 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 47 | .. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 48 | .SH NAME |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 49 | \fB\%has_mouse\fP, |
| 50 | \fB\%getmouse\fP, |
| 51 | \fB\%ungetmouse\fP, |
| 52 | \fB\%mousemask\fP, |
| 53 | \fB\%wenclose\fP, |
| 54 | \fB\%mouse_trafo\fP, |
| 55 | \fB\%wmouse_trafo\fP, |
| 56 | \fB\%mouseinterval\fP \- |
| 57 | get mouse events in \fIcurses\fR |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 58 | .SH SYNOPSIS |
| 59 | .nf |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 60 | \fB#include <curses.h> |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 61 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 62 | \fBtypedef unsigned long mmask_t; |
| 63 | .PP |
| 64 | \fBtypedef struct { |
| 65 | \fB short id; \fI/* ID to distinguish multiple devices */ |
| 66 | \fB int x, y, z; \fI/* event coordinates */ |
| 67 | \fB mmask_t bstate; \fI/* button state bits */ |
| 68 | \fB} MEVENT; |
| 69 | .PP |
| 70 | \fBbool has_mouse(void); |
| 71 | .PP |
| 72 | \fBmmask_t mousemask(mmask_t \fInewmask\fP, mmask_t *\fIoldmask\fP); |
| 73 | .PP |
| 74 | \fBint getmouse(MEVENT *\fIevent\fP); |
| 75 | \fBint ungetmouse(MEVENT *\fIevent\fP); |
| 76 | .PP |
| 77 | \fBbool wenclose(const WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP); |
| 78 | .PP |
| 79 | \fBbool mouse_trafo(int* \fIpY\fP, int* \fIpX\fP, bool \fIto_screen\fP); |
| 80 | \fBbool wmouse_trafo(const WINDOW* \fIwin\fP, |
| 81 | .ti +18n \" "bool wmouse_trafo(" |
| 82 | \fBint* \fIpY\fB, int* \fIpX\fB, bool \fIto_screen\fB); |
| 83 | .PP |
| 84 | \fBint mouseinterval(int \fIerval\fB);\fR |
| 85 | .fi |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 86 | .SH DESCRIPTION |
| 87 | These functions provide an interface to mouse events from |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 88 | \fB\%ncurses\fP(3X). |
| 89 | Mouse events are represented by \fB\%KEY_MOUSE\fP |
| 90 | pseudo-key values in the \fB\%wgetch\fP(3X) input stream. |
| 91 | .SS has_mouse |
| 92 | The \fB\%has_mouse\fP function returns \fBTRUE\fP if the mouse driver |
| 93 | has been successfully initialized, |
| 94 | and \fBFALSE\fP otherwise. |
| 95 | .PP |
| 96 | Mouse events are ignored when input is in cooked mode, and |
| 97 | cause an error beep when cooked mode is being simulated in a window by a |
| 98 | function such as \fB\%getstr\fP that expects a linefeed for input-loop |
| 99 | termination. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 100 | .SS mousemask |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 101 | To make mouse events visible, use the \fB\%mousemask\fP function. |
| 102 | This sets the mouse events to be reported. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | By default, no mouse events are reported. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 104 | .bP |
| 105 | The function returns an updated copy of \fInewmask\fP |
| 106 | to indicate which of the specified mouse events can be reported. |
| 107 | .IP |
| 108 | If the screen has not been initialized, |
| 109 | or if the terminal does not support mouse-events, |
| 110 | this function returns 0. |
| 111 | .bP |
| 112 | If \fIoldmask\fP is non-\fBNULL\fP, |
| 113 | this function fills the indicated location with the previous value of the |
| 114 | current screen's mouse event mask. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 115 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 116 | As a side effect, setting a zero mouse mask may turn off the mouse pointer; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 117 | setting a nonzero mask may turn it on. |
| 118 | Whether this happens is device-dependent. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 119 | .SS "Mouse Events" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | Here are the mouse event type masks which may be defined: |
| 121 | .PP |
| 122 | .TS |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 123 | Lb Lb |
| 124 | Lb Lx. |
| 125 | Name Description |
| 126 | = |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 127 | BUTTON1_PRESSED mouse button 1 down |
| 128 | BUTTON1_RELEASED mouse button 1 up |
| 129 | BUTTON1_CLICKED mouse button 1 clicked |
| 130 | BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked |
| 131 | BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked |
| 132 | _ |
| 133 | BUTTON2_PRESSED mouse button 2 down |
| 134 | BUTTON2_RELEASED mouse button 2 up |
| 135 | BUTTON2_CLICKED mouse button 2 clicked |
| 136 | BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked |
| 137 | BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked |
| 138 | _ |
| 139 | BUTTON3_PRESSED mouse button 3 down |
| 140 | BUTTON3_RELEASED mouse button 3 up |
| 141 | BUTTON3_CLICKED mouse button 3 clicked |
| 142 | BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked |
| 143 | BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked |
| 144 | _ |
| 145 | BUTTON4_PRESSED mouse button 4 down |
| 146 | BUTTON4_RELEASED mouse button 4 up |
| 147 | BUTTON4_CLICKED mouse button 4 clicked |
| 148 | BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked |
| 149 | BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked |
| 150 | _ |
| 151 | BUTTON5_PRESSED mouse button 5 down |
| 152 | BUTTON5_RELEASED mouse button 5 up |
| 153 | BUTTON5_CLICKED mouse button 5 clicked |
| 154 | BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked |
| 155 | BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked |
| 156 | _ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 157 | BUTTON_SHIFT T{ |
| 158 | shift was down during button state change |
| 159 | T} |
| 160 | BUTTON_CTRL T{ |
| 161 | control was down during button state change |
| 162 | T} |
| 163 | BUTTON_ALT T{ |
| 164 | alt was down during button state change |
| 165 | T} |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 166 | ALL_MOUSE_EVENTS report all button state changes |
| 167 | REPORT_MOUSE_POSITION report mouse movement |
| 168 | _ |
| 169 | .TE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 170 | .SS getmouse |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 171 | Once a class of mouse events has been made visible in a window, |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 172 | calling the \fB\%wgetch\fP function on that window may return |
| 173 | \fB\%KEY_MOUSE\fP as an indicator that a mouse event has been queued. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 174 | To read the event data and pop the event off the queue, call |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 175 | \fB\%getmouse\fP. |
| 176 | This function will return \fBOK\fP if a mouse event |
| 177 | is actually visible in the given window, \fBERR\fP otherwise. |
| 178 | When \fB\%getmouse\fP returns \fBOK\fP, the data deposited as y and |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 179 | x in the event structure coordinates will be screen-relative character-cell |
| 180 | coordinates. |
| 181 | The returned state mask will have exactly one bit set to |
| 182 | indicate the event type. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 183 | The corresponding data in the queue is marked invalid. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 184 | A subsequent call to \fB\%getmouse\fP will retrieve the next older |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 185 | item from the queue. |
| 186 | .SS ungetmouse |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 187 | The \fB\%ungetmouse\fP function behaves analogously to \fB\%ungetch\fP. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 188 | It pushes |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 189 | a \fB\%KEY_MOUSE\fP event onto the input queue, and associates with that event |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 190 | the given state data and screen-relative character-cell coordinates. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 191 | .SS wenclose |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 192 | The \fB\%wenclose\fP function tests whether a given pair of screen-relative |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 193 | character-cell coordinates is enclosed by a given window, returning \fBTRUE\fP |
| 194 | if it is and \fBFALSE\fP otherwise. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 195 | It is useful for determining what subset of |
| 196 | the screen windows enclose the location of a mouse event. |
| 197 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 198 | If the parameter is a pad, |
| 199 | \fB\%wenclose\fP uses the most recent screen coordinates used for |
| 200 | this pad in |
| 201 | \fB\%prefresh\fP(3X) or |
| 202 | \fB\%pnoutrefresh\fP(3X). |
| 203 | .SS wmouse_trafo |
| 204 | The \fB\%wmouse_trafo\fP function transforms a given pair of coordinates |
| 205 | from \fB\%stdscr\fP-relative coordinates |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 206 | to coordinates relative to the given window or vice versa. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 207 | The resulting \fB\%stdscr\fP-relative coordinates are not always |
| 208 | identical to screen coordinates due to the mechanism to reserve |
| 209 | lines on top or bottom of the screen for other purposes |
| 210 | (see the \fB\%ripoffline\fP(3X) and \fB\%slk_init\fP(3X) calls, for example). |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 211 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 212 | If the parameter \fIto_screen\fP is \fBTRUE\fP, the pointers |
| 213 | \fIpY, pX\fP must reference the coordinates of a location |
| 214 | inside the window \fIwin\fP. |
| 215 | They are converted to \fB\%stdscr\fP-relative coordinates and returned |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 216 | through the pointers. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 217 | If the conversion was successful, the function returns \fBTRUE\fP. |
| 218 | .IP |
| 219 | If one of the parameters was \fBNULL\fP or the location is |
| 220 | not inside the window, \fBFALSE\fP is returned. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 221 | .bP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 222 | If \fIto_screen\fP is |
| 223 | \fBFALSE\fP, the pointers \fIpY, pX\fP must reference |
| 224 | \fB\%stdscr\fP-relative coordinates. |
| 225 | They are converted to window-relative coordinates if the |
| 226 | window \fIwin\fP encloses this point. |
| 227 | In this case the function returns \fBTRUE\fP. |
| 228 | .IP |
| 229 | If one of the parameters is \fBNULL\fP or the point is not inside the |
| 230 | window, \fBFALSE\fP is returned. |
| 231 | .PP |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 232 | The referenced coordinates |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 233 | are only replaced by the converted coordinates if the transformation was |
| 234 | successful. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 235 | .SS mouse_trafo |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 236 | The \fB\%mouse_trafo\fP function performs the same translation |
| 237 | as \fB\%wmouse_trafo\fP, |
| 238 | using \fB\%stdscr\fP for \fIwin\fP. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 239 | .SS mouseinterval |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 240 | The \fB\%mouseinterval\fP function sets the maximum time |
| 241 | (in thousands of a second) |
| 242 | that can elapse between press and release events for them to |
| 243 | be resolved as a |
| 244 | .IR click . |
| 245 | An application might interpret button press and release events separated |
| 246 | by more than the mouse interval as a \*(``long press\*('', |
| 247 | or, |
| 248 | with motion, |
| 249 | as a \*(``drag\*(''. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 250 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 251 | Calling \fB\%mouseinterval(0)\fP disables click resolution. |
| 252 | When |
| 253 | .I \%ncurses |
| 254 | detects a mouse event, |
| 255 | it awaits further input activity up to this interval, |
| 256 | and then checks for a subsequent mouse event which can be combined |
| 257 | with the first event. |
| 258 | If the timeout expires without input activity |
| 259 | (which would happen with a zero interval), |
| 260 | then no click resolution will occur. |
| 261 | .PP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 262 | This function returns the previous interval value. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 263 | Use \fB\%mouseinterval(\-1)\fP to obtain the interval without altering it. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 264 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 265 | The mouse interval is set to one sixth of a second |
| 266 | when the corresponding screen is initialized, |
| 267 | e.g., in \fBinitscr\fP(3X) or \fBsetupterm\fP(3X). |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 268 | .SH RETURN VALUE |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 269 | \fB\%has_mouse\fP, |
| 270 | \fB\%wenclose\fP, |
| 271 | \fB\%mouse_trafo\fP, |
| 272 | and |
| 273 | \fB\%wmouse_trafo\fP |
| 274 | return \fBTRUE\fP or \fBFALSE\fP as noted above. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 275 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 276 | \fB\%getmouse\fP and \fB\%ungetmouse\fP |
| 277 | return \fBERR\fP upon failure and \fBOK\fP upon success. |
| 278 | .PP |
| 279 | \fB\%getmouse\fP fails if: |
| 280 | .bP |
| 281 | no mouse driver was initialized, |
| 282 | .bP |
| 283 | the mask of reportable events is zero, |
| 284 | .bP |
| 285 | a mouse event was detected that does not match the mask, |
| 286 | .bP |
| 287 | or if no more events remain in the queue. |
| 288 | .PP |
| 289 | \fB\%ungetmouse\fP returns an error if the event queue is full. |
| 290 | .PP |
| 291 | \fB\%mousemask\fP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 292 | returns the mask of reportable events. |
| 293 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 294 | \fB\%mouseinterval\fP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 295 | returns the previous interval value, unless |
| 296 | the terminal was not initialized. |
| 297 | In that case, it returns the maximum interval value (166). |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 298 | .SH NOTES |
| 299 | The order of the \fB\%MEVENT\fP structure members is not guaranteed. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 300 | Additional fields may be added to the structure in the future. |
| 301 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 302 | Under |
| 303 | .IR \%ncurses , |
| 304 | these calls are implemented using either |
| 305 | .IR \%xterm 's |
| 306 | built-in mouse-tracking API or |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 307 | platform-specific drivers including |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 308 | .RS 3 |
| 309 | .bP |
| 310 | Alessandro Rubini's gpm server |
| 311 | .bP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 312 | FreeBSD sysmouse |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 313 | .bP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 314 | OS/2 EMX |
| 315 | .RE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 316 | .PP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 317 | If you are using an unsupported configuration, |
| 318 | mouse events will not be visible to |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 319 | \fI\%ncurses\fP (and the \fB\%mousemask\fP function will always |
| 320 | return \fB0\fP). |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 321 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 322 | If the |
| 323 | .I \%term\%info |
| 324 | entry contains a \fBXM\fP string, |
| 325 | this is used in the |
| 326 | .I \%xterm |
| 327 | mouse driver to control the |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 328 | way the terminal is initialized for mouse operation. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 329 | The default, if \fBXM\fP is not found, |
| 330 | corresponds to private mode 1000 of |
| 331 | .I \%xterm: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 332 | .PP |
| 333 | .RS 3 |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 334 | \eE[?1000%?%p1%{1}%=%th%el%; |
| 335 | .RE |
| 336 | .PP |
| 337 | The mouse driver also recognizes a newer |
| 338 | .I \%xterm |
| 339 | private mode 1006, |
| 340 | e.g., |
| 341 | .PP |
| 342 | .RS 3 |
| 343 | \eE[?1006;1000%?%p1%{1}%=%th%el%; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 344 | .RE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 345 | .PP |
| 346 | The \fIz\fP member in the event structure is not presently used. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 347 | It is intended |
| 348 | for use with touch screens (which may be pressure-sensitive) or with |
| 349 | 3D-mice/trackballs/power gloves. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 350 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 351 | The \fB\%ALL_MOUSE_EVENTS\fP class does not |
| 352 | include \fB\%REPORT_MOUSE_POSITION\fP. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 353 | They are distinct. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 354 | For example, |
| 355 | in |
| 356 | .IR \%xterm , |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 357 | wheel/scrolling mice send position reports as a sequence of |
| 358 | presses of buttons 4 or 5 without matching button-releases. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 359 | .SH EXTENSIONS |
| 360 | These functions were designed for |
| 361 | \fB\%ncurses\fP(3X), |
| 362 | and are not found in SVr4 |
| 363 | .IR curses , |
| 364 | 4.4BSD |
| 365 | .IR curses , |
| 366 | or any other previous curses implementation. |
| 367 | (SVr4 |
| 368 | .I curses |
| 369 | did have a |
| 370 | .I \%getmouse |
| 371 | function, |
| 372 | which took no argument and returned a different type.) |
| 373 | .SH PORTABILITY |
| 374 | Applications employing the |
| 375 | .I \%ncurses |
| 376 | mouse extension should condition its use on the visibility of the |
| 377 | .B \%NCURSES_MOUSE_VERSION |
| 378 | preprocessor macro. |
| 379 | When the interface changes, |
| 380 | the macro's value increments. |
| 381 | Multiple versions are available when |
| 382 | .I \%ncurses |
| 383 | is configured; |
| 384 | see section \*(``ALTERNATE CONFIGURATIONS\*('' of \fB\%ncurses\fP(3X). |
| 385 | The following values may be specified. |
| 386 | .RS 3 |
| 387 | .TP 3 |
| 388 | 1 |
| 389 | has definitions for reserved events. |
| 390 | The mask uses 28 bits. |
| 391 | .TP 3 |
| 392 | 2 |
| 393 | adds definitions for button 5, |
| 394 | removes the definitions for reserved events. |
| 395 | The mask uses 29 bits. |
| 396 | .RE |
| 397 | .PP |
| 398 | SVr4 |
| 399 | .I curses |
| 400 | had support for the mouse in a variant of \fI\%xterm\fP(1). |
| 401 | It is mentioned in a few places, |
| 402 | with little supporting documentation. |
| 403 | .bP |
| 404 | Its \*(``libcurses\*('' manual page lists functions for this feature |
| 405 | prototyped in \fI\%curses.h\fP. |
| 406 | .PP |
| 407 | .RS 8 |
| 408 | .EX |
| 409 | extern int mouse_set(long int); |
| 410 | extern int mouse_on(long int); |
| 411 | extern int mouse_off(long int); |
| 412 | extern int request_mouse_pos(void); |
| 413 | extern int map_button(unsigned long); |
| 414 | extern void wmouse_position(WINDOW *, int *, int *); |
| 415 | extern unsigned long getmouse(void), getbmap(void); |
| 416 | .EE |
| 417 | .RE |
| 418 | .bP |
| 419 | Its \*(``terminfo\*('' manual page lists capabilities for the feature. |
| 420 | .\" These don't appear in in the SVID 4th edition, Volume 3, |
| 421 | .\" terminfo(TI_ENV) man page. They can be found in, e.g., the "z/OS |
| 422 | .\" V1R1.0 C Curses" book, Chapter 17, pp. 179-186 (PDF 213-220). |
| 423 | .RS 8 |
| 424 | .TS |
| 425 | Lb Lb Lb Lx. |
| 426 | buttons btns BT T{ |
| 427 | Number of buttons on the mouse |
| 428 | T} |
| 429 | get_mouse getm Gm T{ |
| 430 | Curses should get button events |
| 431 | T} |
| 432 | key_mouse kmous Km T{ |
| 433 | 0631, Mouse event has occurred |
| 434 | T} |
| 435 | mouse_info minfo Mi T{ |
| 436 | Mouse status information |
| 437 | T} |
| 438 | req_mouse_pos reqmp RQ T{ |
| 439 | Request mouse position report |
| 440 | T} |
| 441 | .TE |
| 442 | .RE |
| 443 | .bP |
| 444 | The interface made assumptions |
| 445 | (as does |
| 446 | .IR \%ncurses ) |
| 447 | about the escape sequences sent to and received from the terminal. |
| 448 | .IP |
| 449 | For instance, |
| 450 | the SVr4 |
| 451 | .I curses |
| 452 | library used the \fB\%get_mouse\fP capability to tell the terminal which |
| 453 | mouse button events it should send, |
| 454 | passing the mouse-button bit mask to the terminal. |
| 455 | Also, it could ask the terminal |
| 456 | where the mouse was using the \fB\%req_mouse_pos\fP capability. |
| 457 | .IP |
| 458 | Those features required a terminal program that had been modified |
| 459 | to work with SVr4 |
| 460 | .IR curses . |
| 461 | They were not part of the X Consortium's |
| 462 | .IR \%xterm . |
| 463 | .PP |
| 464 | When developing the |
| 465 | .I \%xterm |
| 466 | mouse support for |
| 467 | .I \%ncurses |
| 468 | in September 1995, |
| 469 | Eric Raymond was uninterested in using the same interface due to its |
| 470 | lack of documentation. |
| 471 | Later, in 1998, Mark Hesseling provided support in |
| 472 | .I \%PDCurses |
| 473 | 2.3 using the SVr4 interface. |
| 474 | .IR \%PDCurses , |
| 475 | however, |
| 476 | does not use video terminals, |
| 477 | making it unnecessary to be concerned about compatibility with the |
| 478 | escape sequences. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 479 | .SH BUGS |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 480 | Mouse events from |
| 481 | .I \%xterm |
| 482 | are |
| 483 | .I not |
| 484 | ignored in cooked mode if they have been enabled by \fB\%mousemask\fP. |
| 485 | Instead, |
| 486 | the |
| 487 | .I \%xterm |
| 488 | mouse report sequence appears in the string read. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 489 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 490 | Mouse event reports from |
| 491 | .I \%xterm |
| 492 | are not detected correctly in a window with keypad application mode |
| 493 | disabled, |
| 494 | since they are interpreted as a variety of function key. |
| 495 | Set the terminal's |
| 496 | .I \%term\%info |
| 497 | capability \fB\%kmous\fP to \*(``\eE[M\*('' |
| 498 | (the beginning of the response from |
| 499 | .I \%xterm |
| 500 | for mouse clicks). |
| 501 | Other values of \fB\%kmous\fP are permitted under the same assumption, |
| 502 | that is, |
| 503 | the report begins with that sequence. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 504 | .PP |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 505 | Because there are no standard response sequences that serve to identify |
| 506 | terminals supporting the |
| 507 | .I \%xterm |
| 508 | mouse protocol, |
| 509 | .I \%ncurses |
| 510 | assumes that if \fB\%kmous\fP is defined in the terminal description, |
| 511 | or if the terminal type's primary name or aliases contain the string |
| 512 | \%\*(``xterm\*('', |
| 513 | then the terminal may send mouse events. |
| 514 | The \fB\%kmous\fP capability is checked first, |
| 515 | allowing use of newer |
| 516 | .I \%xterm |
| 517 | mouse protocols, |
| 518 | such as its private mode 1006. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 519 | .SH SEE ALSO |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 520 | \fB\%curses\fP(3X), |
| 521 | \fB\%curs_inopts\fP(3X), |
| 522 | \fB\%curs_kernel\fP(3X), |
| 523 | \fB\%curs_pad\fP(3X), |
| 524 | \fB\%curs_slk\fP(3X), |
| 525 | \fB\%curs_variables\fP(3X) |