3 ****************************************************************************
4 * Copyright 2018-2022,2023 Thomas E. Dickey *
5 * Copyright 1998-2015,2017 Free Software Foundation, Inc. *
7 * Permission is hereby granted, free of charge, to any person obtaining a *
8 * copy of this software and associated documentation files (the *
9 * "Software"), to deal in the Software without restriction, including *
10 * without limitation the rights to use, copy, modify, merge, publish, *
11 * distribute, distribute with modifications, sublicense, and/or sell *
12 * copies of the Software, and to permit persons to whom the Software is *
13 * furnished to do so, subject to the following conditions: *
15 * The above copyright notice and this permission notice shall be included *
16 * in all copies or substantial portions of the Software. *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
26 * Except as contained in this notice, the name(s) of the above copyright *
27 * holders shall not be used in advertising or otherwise to promote the *
28 * sale, use or other dealings in this Software without prior written *
30 ****************************************************************************
31 * @Id: curs_mouse.3x,v 1.79 2023/10/07 21:19:07 tom Exp @
33 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
36 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
37 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
38 <TITLE>curs_mouse 3x 2023-10-07 ncurses 6.4 Library calls</TITLE>
39 <link rel="author" href="mailto:bug-ncurses@gnu.org">
43 <H1 class="no-header">curs_mouse 3x 2023-10-07 ncurses 6.4 Library calls</H1>
45 <STRONG><A HREF="curs_mouse.3x.html">curs_mouse(3x)</A></STRONG> Library calls <STRONG><A HREF="curs_mouse.3x.html">curs_mouse(3x)</A></STRONG>
50 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
51 <STRONG>has_mouse</STRONG>, <STRONG>getmouse</STRONG>, <STRONG>ungetmouse</STRONG>, <STRONG>mousemask</STRONG>, <STRONG>wenclose</STRONG>, <STRONG>mouse_trafo</STRONG>,
52 <STRONG>wmouse_trafo</STRONG>, <STRONG>mouseinterval</STRONG> - get mouse events in <EM>curses</EM>
55 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
56 <STRONG>#include</STRONG> <STRONG><curses.h></STRONG>
58 <STRONG>typedef</STRONG> <STRONG>unsigned</STRONG> <STRONG>long</STRONG> <STRONG>mmask_t;</STRONG>
60 <STRONG>typedef</STRONG> <STRONG>struct</STRONG> <STRONG>{</STRONG>
61 <STRONG>short</STRONG> <STRONG>id;</STRONG> <EM>/*</EM> <EM>ID</EM> <EM>to</EM> <EM>distinguish</EM> <EM>multiple</EM> <EM>devices</EM> <EM>*/</EM>
62 <STRONG>int</STRONG> <STRONG>x,</STRONG> <STRONG>y,</STRONG> <STRONG>z;</STRONG> <EM>/*</EM> <EM>event</EM> <EM>coordinates</EM> <EM>*/</EM>
63 <STRONG>mmask_t</STRONG> <STRONG>bstate;</STRONG> <EM>/*</EM> <EM>button</EM> <EM>state</EM> <EM>bits</EM> <EM>*/</EM>
64 <STRONG>}</STRONG> <STRONG>MEVENT;</STRONG>
66 <STRONG>bool</STRONG> <STRONG>has_mouse(void);</STRONG>
68 <STRONG>int</STRONG> <STRONG>getmouse(MEVENT</STRONG> <STRONG>*</STRONG><EM>event</EM><STRONG>);</STRONG>
69 <STRONG>int</STRONG> <STRONG>ungetmouse(MEVENT</STRONG> <STRONG>*</STRONG><EM>event</EM><STRONG>);</STRONG>
71 <STRONG>mmask_t</STRONG> <STRONG>mousemask(mmask_t</STRONG> <EM>newmask</EM><STRONG>,</STRONG> <STRONG>mmask_t</STRONG> <STRONG>*</STRONG><EM>oldmask</EM><STRONG>);</STRONG>
73 <STRONG>bool</STRONG> <STRONG>wenclose(const</STRONG> <STRONG>WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>);</STRONG>
75 <STRONG>bool</STRONG> <STRONG>mouse_trafo(int*</STRONG> <EM>pY</EM><STRONG>,</STRONG> <STRONG>int*</STRONG> <EM>pX</EM><STRONG>,</STRONG> <STRONG>bool</STRONG> <EM>to</EM><STRONG>_</STRONG><EM>screen</EM><STRONG>);</STRONG>
76 <STRONG>bool</STRONG> <STRONG>wmouse_trafo(const</STRONG> <STRONG>WINDOW*</STRONG> <EM>win</EM><STRONG>,</STRONG>
77 <STRONG>int*</STRONG> <EM>pY</EM><STRONG>,</STRONG> <STRONG>int*</STRONG> <EM>pX</EM><STRONG>,</STRONG> <STRONG>bool</STRONG> <EM>to</EM><STRONG>_</STRONG><EM>screen</EM><STRONG>);</STRONG>
79 <STRONG>int</STRONG> <STRONG>mouseinterval(int</STRONG> <EM>erval</EM><STRONG>);</STRONG>
82 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
83 These functions provide an interface to mouse events from <STRONG><A HREF="ncurses.3x.html">ncurses(3x)</A></STRONG>.
84 Mouse events are represented by <STRONG>KEY_MOUSE</STRONG> pseudo-key values in the
85 <STRONG><A HREF="curs_getch.3x.html">wgetch(3x)</A></STRONG> input stream.
88 </PRE><H3><a name="h3-mousemask">mousemask</a></H3><PRE>
89 To make mouse events visible, use the <STRONG>mousemask</STRONG> function. This sets
90 the mouse events to be reported. By default, no mouse events are
93 <STRONG>o</STRONG> The function returns an updated copy of <EM>newmask</EM> to indicate which
94 of the specified mouse events can be reported.
96 If the screen has not been initialized, or if the terminal does not
97 support mouse-events, this function returns 0.
99 <STRONG>o</STRONG> If <EM>oldmask</EM> is non-<STRONG>NULL</STRONG>, this function fills the indicated location
100 with the previous value of the current screen's mouse event mask.
102 As a side effect, setting a zero mousemask may turn off the mouse
103 pointer; setting a nonzero mask may turn it on. Whether this happens
107 </PRE><H3><a name="h3-Mouse-events">Mouse events</a></H3><PRE>
108 Here are the mouse event type masks which may be defined:
110 <STRONG>Name</STRONG> <STRONG>Description</STRONG>
111 ---------------------------------------------------------------------
112 <STRONG>BUTTON1_PRESSED</STRONG> mouse button 1 down
113 <STRONG>BUTTON1_RELEASED</STRONG> mouse button 1 up
114 <STRONG>BUTTON1_CLICKED</STRONG> mouse button 1 clicked
116 <STRONG>BUTTON1_DOUBLE_CLICKED</STRONG> mouse button 1 double clicked
117 <STRONG>BUTTON1_TRIPLE_CLICKED</STRONG> mouse button 1 triple clicked
118 ---------------------------------------------------------------------
119 <STRONG>BUTTON2_PRESSED</STRONG> mouse button 2 down
120 <STRONG>BUTTON2_RELEASED</STRONG> mouse button 2 up
121 <STRONG>BUTTON2_CLICKED</STRONG> mouse button 2 clicked
122 <STRONG>BUTTON2_DOUBLE_CLICKED</STRONG> mouse button 2 double clicked
123 <STRONG>BUTTON2_TRIPLE_CLICKED</STRONG> mouse button 2 triple clicked
124 ---------------------------------------------------------------------
125 <STRONG>BUTTON3_PRESSED</STRONG> mouse button 3 down
126 <STRONG>BUTTON3_RELEASED</STRONG> mouse button 3 up
127 <STRONG>BUTTON3_CLICKED</STRONG> mouse button 3 clicked
128 <STRONG>BUTTON3_DOUBLE_CLICKED</STRONG> mouse button 3 double clicked
129 <STRONG>BUTTON3_TRIPLE_CLICKED</STRONG> mouse button 3 triple clicked
130 ---------------------------------------------------------------------
131 <STRONG>BUTTON4_PRESSED</STRONG> mouse button 4 down
132 <STRONG>BUTTON4_RELEASED</STRONG> mouse button 4 up
133 <STRONG>BUTTON4_CLICKED</STRONG> mouse button 4 clicked
134 <STRONG>BUTTON4_DOUBLE_CLICKED</STRONG> mouse button 4 double clicked
135 <STRONG>BUTTON4_TRIPLE_CLICKED</STRONG> mouse button 4 triple clicked
136 ---------------------------------------------------------------------
137 <STRONG>BUTTON5_PRESSED</STRONG> mouse button 5 down
138 <STRONG>BUTTON5_RELEASED</STRONG> mouse button 5 up
139 <STRONG>BUTTON5_CLICKED</STRONG> mouse button 5 clicked
140 <STRONG>BUTTON5_DOUBLE_CLICKED</STRONG> mouse button 5 double clicked
141 <STRONG>BUTTON5_TRIPLE_CLICKED</STRONG> mouse button 5 triple clicked
142 ---------------------------------------------------------------------
143 <STRONG>BUTTON_SHIFT</STRONG> shift was down during button state change
144 <STRONG>BUTTON_CTRL</STRONG> control was down during button state change
145 <STRONG>BUTTON_ALT</STRONG> alt was down during button state change
146 <STRONG>ALL_MOUSE_EVENTS</STRONG> report all button state changes
147 <STRONG>REPORT_MOUSE_POSITION</STRONG> report mouse movement
148 ---------------------------------------------------------------------
151 </PRE><H3><a name="h3-getmouse">getmouse</a></H3><PRE>
152 Once a class of mouse events has been made visible in a window, calling
153 the <STRONG>wgetch</STRONG> function on that window may return <STRONG>KEY_MOUSE</STRONG> as an indicator
154 that a mouse event has been queued. To read the event data and pop the
155 event off the queue, call <STRONG>getmouse</STRONG>. This function will return <STRONG>OK</STRONG> if a
156 mouse event is actually visible in the given window, <STRONG>ERR</STRONG> otherwise.
157 When <STRONG>getmouse</STRONG> returns <STRONG>OK</STRONG>, the data deposited as y and x in the event
158 structure coordinates will be screen-relative character-cell
159 coordinates. The returned state mask will have exactly one bit set to
160 indicate the event type. The corresponding data in the queue is marked
161 invalid. A subsequent call to <STRONG>getmouse</STRONG> will retrieve the next older
165 </PRE><H3><a name="h3-ungetmouse">ungetmouse</a></H3><PRE>
166 The <STRONG>ungetmouse</STRONG> function behaves analogously to <STRONG>ungetch</STRONG>. It pushes a
167 <STRONG>KEY_MOUSE</STRONG> event onto the input queue, and associates with that event
168 the given state data and screen-relative character-cell coordinates.
171 </PRE><H3><a name="h3-wenclose">wenclose</a></H3><PRE>
172 The <STRONG>wenclose</STRONG> function tests whether a given pair of screen-relative
173 character-cell coordinates is enclosed by a given window, returning
174 <STRONG>TRUE</STRONG> if it is and <STRONG>FALSE</STRONG> otherwise. It is useful for determining what
175 subset of the screen windows enclose the location of a mouse event.
178 </PRE><H3><a name="h3-wmouse_trafo">wmouse_trafo</a></H3><PRE>
179 The <STRONG>wmouse_trafo</STRONG> function transforms a given pair of coordinates from
180 stdscr-relative coordinates to coordinates relative to the given window
181 or vice versa. The resulting stdscr-relative coordinates are not
182 always identical to window-relative coordinates due to the mechanism to
183 reserve lines on top or bottom of the screen for other purposes (see
184 the <STRONG>ripoffline</STRONG> and <STRONG><A HREF="curs_slk.3x.html">slk_init(3x)</A></STRONG> calls, for example).
186 <STRONG>o</STRONG> If the parameter <EM>to</EM><STRONG>_</STRONG><EM>screen</EM> is <STRONG>TRUE</STRONG>, the pointers <EM>pY,</EM> <EM>pX</EM> must
187 reference the coordinates of a location inside the window <EM>win</EM>.
188 They are converted to window-relative coordinates and returned
189 through the pointers. If the conversion was successful, the
190 function returns <STRONG>TRUE</STRONG>.
192 <STRONG>o</STRONG> If one of the parameters was <STRONG>NULL</STRONG> or the location is not inside the
193 window, <STRONG>FALSE</STRONG> is returned.
195 <STRONG>o</STRONG> If <EM>to</EM><STRONG>_</STRONG><EM>screen</EM> is <STRONG>FALSE</STRONG>, the pointers <EM>pY,</EM> <EM>pX</EM> must reference window-
196 relative coordinates. They are converted to stdscr-relative
197 coordinates if the window <EM>win</EM> encloses this point. In this case
198 the function returns <STRONG>TRUE</STRONG>.
200 <STRONG>o</STRONG> If one of the parameters is <STRONG>NULL</STRONG> or the point is not inside the
201 window, <STRONG>FALSE</STRONG> is returned. The referenced coordinates are only
202 replaced by the converted coordinates if the transformation was
206 </PRE><H3><a name="h3-mouse_trafo">mouse_trafo</a></H3><PRE>
207 The <STRONG>mouse_trafo</STRONG> function performs the same translation as <STRONG>wmouse_trafo</STRONG>,
208 using stdscr for <EM>win</EM>.
211 </PRE><H3><a name="h3-mouseinterval">mouseinterval</a></H3><PRE>
212 The <STRONG>mouseinterval</STRONG> function sets the maximum time (in thousands of a
213 second) that can elapse between press and release events for them to be
214 recognized as a click. Use <STRONG>mouseinterval(0)</STRONG> to disable click
215 resolution. This function returns the previous interval value. Use
216 <STRONG>mouseinterval(-1)</STRONG> to obtain the interval without altering it. The
217 default is one sixth of a second.
220 </PRE><H3><a name="h3-has_mouse">has_mouse</a></H3><PRE>
221 The <STRONG>has_mouse</STRONG> function returns <STRONG>TRUE</STRONG> if the mouse driver has been
222 successfully initialized.
224 Note that mouse events will be ignored when input is in cooked mode,
225 and will cause an error beep when cooked mode is being simulated in a
226 window by a function such as <STRONG>getstr</STRONG> that expects a linefeed for input-
230 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
231 <STRONG>getmouse</STRONG> and <STRONG>ungetmouse</STRONG> return the integer <STRONG>ERR</STRONG> upon failure or <STRONG>OK</STRONG> upon
232 successful completion:
234 <STRONG>getmouse</STRONG>
237 <STRONG>o</STRONG> If no mouse driver was initialized, or if the mask parameter is
240 <STRONG>o</STRONG> It returns an error if a mouse event was detected which did not
241 match the current <EM>mousemask</EM>.
243 <STRONG>o</STRONG> It also returns an error if no more events remain in the queue.
245 <STRONG>ungetmouse</STRONG>
246 returns an error if the FIFO is full.
248 <STRONG>mousemask</STRONG> returns the mask of reportable events.
250 <STRONG>mouseinterval</STRONG> returns the previous interval value, unless the terminal
251 was not initialized. In that case, it returns the maximum interval
254 <STRONG>wenclose</STRONG> and <STRONG>wmouse_trafo</STRONG> are boolean functions returning <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>
255 depending on their test result.
258 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
259 These calls were designed for <EM>ncurses</EM>, and are not found in SVr4
260 <EM>curses</EM>, 4.4BSD <EM>curses</EM>, or any other previous version of <EM>curses</EM>.
262 SVr4 <EM>curses</EM> had support for the mouse in a variant of <STRONG>xterm(1)</STRONG>. It is
263 mentioned in a few places, but with no supporting documentation:
265 <STRONG>o</STRONG> the "libcurses" manual page lists functions for this feature which
266 are prototyped in <STRONG>curses.h</STRONG>:
268 extern int mouse_set(long int);
269 extern int mouse_on(long int);
270 extern int mouse_off(long int);
271 extern int request_mouse_pos(void);
272 extern int map_button(unsigned long);
273 extern void wmouse_position(WINDOW *, int *, int *);
274 extern unsigned long getmouse(void), getbmap(void);
276 <STRONG>o</STRONG> the "terminfo" manual page lists capabilities for the feature
278 buttons btns BT Number of buttons on the mouse
279 get_mouse getm Gm Curses should get button events
280 key_mouse kmous Km 0631, Mouse event has occurred
281 mouse_info minfo Mi Mouse status information
282 req_mouse_pos reqmp RQ Request mouse position report
284 <STRONG>o</STRONG> the interface made assumptions (as does <EM>ncurses</EM>) about the escape
285 sequences sent to and received from the terminal.
287 For instance the SVr4 <EM>curses</EM> library used the <STRONG>get_mouse</STRONG> capability
288 to tell the terminal which mouse button events it should send,
289 passing the mouse-button bit-mask to the terminal. Also, it could
290 ask the terminal where the mouse was using the <STRONG>req_mouse_pos</STRONG>
293 Those features required a terminal which had been modified to work
294 with <EM>curses</EM>. They were not part of the X Consortium's xterm.
296 When developing the xterm mouse support for <EM>ncurses</EM> in September 1995,
297 Eric Raymond was uninterested in using the same interface due to its
298 lack of documentation. Later, in 1998, Mark Hesseling provided support
299 in PDCurses 2.3 using the SVr4 interface. PDCurses, however, does not
300 use video terminals, making it unnecessary to be concerned about
301 compatibility with the escape sequences.
303 The feature macro <STRONG>NCURSES_MOUSE_VERSION</STRONG> is provided so the preprocessor
304 can be used to test whether these features are present. If the
305 interface is changed, the value of <STRONG>NCURSES_MOUSE_VERSION</STRONG> will be
306 incremented. These values for <STRONG>NCURSES_MOUSE_VERSION</STRONG> may be specified
307 when configuring <EM>ncurses</EM>:
309 1 has definitions for reserved events. The mask uses 28 bits.
311 2 adds definitions for button 5, removes the definitions for
312 reserved events. The mask uses 29 bits.
314 The order of the <STRONG>MEVENT</STRONG> structure members is not guaranteed.
315 Additional fields may be added to the structure in the future.
317 Under <EM>ncurses</EM>, these calls are implemented using either xterm's built-
318 in mouse-tracking API or platform-specific drivers including
320 <STRONG>o</STRONG> Alessandro Rubini's gpm server
322 <STRONG>o</STRONG> FreeBSD sysmouse
324 <STRONG>o</STRONG> OS/2 EMX
326 If you are using an unsupported configuration, mouse events will not be
327 visible to <EM>ncurses</EM> (and the <STRONG>mousemask</STRONG> function will always return <STRONG>0</STRONG>).
329 If the terminfo entry contains a <STRONG>XM</STRONG> string, this is used in the xterm
330 mouse driver to control the way the terminal is initialized for mouse
331 operation. The default, if <STRONG>XM</STRONG> is not found, corresponds to private
334 \E[?1000%?%p1%{1}%=%th%el%;
336 The mouse driver also recognizes a newer xterm private mode 1006, e.g.,
338 \E[?1006;1000%?%p1%{1}%=%th%el%;
340 The <EM>z</EM> member in the event structure is not presently used. It is
341 intended for use with touch screens (which may be pressure-sensitive)
342 or with 3D-mice/trackballs/power gloves.
344 The <STRONG>ALL_MOUSE_EVENTS</STRONG> class does not include <STRONG>REPORT_MOUSE_POSITION</STRONG>.
345 They are distinct. For example, in xterm, wheel/scrolling mice send
346 position reports as a sequence of presses of buttons 4 or 5 without
347 matching button-releases.
350 </PRE><H2><a name="h2-BUGS">BUGS</a></H2><PRE>
351 Mouse events under xterm will not in fact be ignored during cooked
352 mode, if they have been enabled by <STRONG>mousemask</STRONG>. Instead, the xterm mouse
353 report sequence will appear in the string read.
355 Mouse events under xterm will not be detected correctly in a window
356 with its keypad bit off, since they are interpreted as a variety of
357 function key. Your terminfo description should have <STRONG>kmous</STRONG> set to
358 "\E[M" (the beginning of the response from xterm for mouse clicks).
359 Other values for <STRONG>kmous</STRONG> are permitted, but under the same assumption,
360 i.e., it is the beginning of the response.
362 Because there are no standard terminal responses that would serve to
363 identify terminals which support the xterm mouse protocol, <EM>ncurses</EM>
364 assumes that if <STRONG>kmous</STRONG> is defined in the terminal description, or if the
365 terminal description's primary name or aliases contain the string
366 "xterm", then the terminal may send mouse events. The <STRONG>kmous</STRONG> capability
367 is checked first, allowing the use of newer xterm mouse protocols such
368 as xterm's private mode 1006.
371 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
372 <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_inopts.3x.html">curs_inopts(3x)</A></STRONG>, <STRONG><A HREF="curs_kernel.3x.html">curs_kernel(3x)</A></STRONG>, <STRONG><A HREF="curs_slk.3x.html">curs_slk(3x)</A></STRONG>,
373 <STRONG><A HREF="curs_variables.3x.html">curs_variables(3x)</A></STRONG>
377 ncurses 6.4 2023-10-07 <STRONG><A HREF="curs_mouse.3x.html">curs_mouse(3x)</A></STRONG>
381 <li><a href="#h2-NAME">NAME</a></li>
382 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
383 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
385 <li><a href="#h3-mousemask">mousemask</a></li>
386 <li><a href="#h3-Mouse-events">Mouse events</a></li>
387 <li><a href="#h3-getmouse">getmouse</a></li>
388 <li><a href="#h3-ungetmouse">ungetmouse</a></li>
389 <li><a href="#h3-wenclose">wenclose</a></li>
390 <li><a href="#h3-wmouse_trafo">wmouse_trafo</a></li>
391 <li><a href="#h3-mouse_trafo">mouse_trafo</a></li>
392 <li><a href="#h3-mouseinterval">mouseinterval</a></li>
393 <li><a href="#h3-has_mouse">has_mouse</a></li>
396 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
397 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
398 <li><a href="#h2-BUGS">BUGS</a></li>
399 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>