3 ****************************************************************************
4 * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc. *
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: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
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. *
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 *
29 ****************************************************************************
30 * @Id: curs_mouse.3x,v 1.50 2018/12/29 23:40:47 tom Exp @
32 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
35 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
36 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
37 <TITLE>curs_mouse 3x</TITLE>
38 <link rel="author" href="mailto:bug-ncurses@gnu.org">
39 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
42 <H1 class="no-header">curs_mouse 3x</H1>
44 <STRONG><A HREF="curs_mouse.3x.html">curs_mouse(3x)</A></STRONG> <STRONG><A HREF="curs_mouse.3x.html">curs_mouse(3x)</A></STRONG>
49 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
50 <STRONG>has_mouse</STRONG>, <STRONG>getmouse</STRONG>, <STRONG>ungetmouse</STRONG>, <STRONG>mousemask</STRONG>, <STRONG>wenclose</STRONG>, <STRONG>mouse_trafo</STRONG>,
51 <STRONG>wmouse_trafo</STRONG>, <STRONG>mouseinterval</STRONG> - mouse interface through curses
54 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
55 <STRONG>#include</STRONG> <STRONG><curses.h></STRONG>
57 <STRONG>typedef</STRONG> <STRONG>unsigned</STRONG> <STRONG>long</STRONG> <STRONG>mmask_t;</STRONG>
59 <STRONG>typedef</STRONG> <STRONG>struct</STRONG> <STRONG>{</STRONG>
60 <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>
61 <STRONG>int</STRONG> <STRONG>x,</STRONG> <STRONG>y,</STRONG> <STRONG>z;</STRONG> <EM>/*</EM> <EM>event</EM> <EM>coordinates</EM> <EM>*/</EM>
62 <STRONG>mmask_t</STRONG> <STRONG>bstate;</STRONG> <EM>/*</EM> <EM>button</EM> <EM>state</EM> <EM>bits</EM> <EM>*/</EM>
63 <STRONG>}</STRONG> <STRONG>MEVENT;</STRONG>
65 <STRONG>bool</STRONG> <STRONG>has_mouse(void);</STRONG>
66 <STRONG>int</STRONG> <STRONG>getmouse(MEVENT</STRONG> <STRONG>*</STRONG><EM>event</EM><STRONG>);</STRONG>
67 <STRONG>int</STRONG> <STRONG>ungetmouse(MEVENT</STRONG> <STRONG>*</STRONG><EM>event</EM><STRONG>);</STRONG>
68 <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>
69 <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>
70 <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>
71 <STRONG>bool</STRONG> <STRONG>wmouse_trafo(const</STRONG> <STRONG>WINDOW*</STRONG> <EM>win</EM><STRONG>,</STRONG> <STRONG>int*</STRONG> <EM>pY</EM><STRONG>,</STRONG> <STRONG>int*</STRONG> <EM>pX</EM><STRONG>,</STRONG>
72 <STRONG>bool</STRONG> <EM>to</EM><STRONG>_</STRONG><EM>screen</EM><STRONG>);</STRONG>
73 <STRONG>int</STRONG> <STRONG>mouseinterval(int</STRONG> <EM>erval</EM><STRONG>);</STRONG>
76 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
77 These functions provide an interface to mouse events from <STRONG><A HREF="ncurses.3x.html">ncurses(3x)</A></STRONG>.
78 Mouse events are represented by <STRONG>KEY_MOUSE</STRONG> pseudo-key values in the
79 <STRONG><A HREF="curs_getch.3x.html">wgetch(3x)</A></STRONG> input stream.
82 </PRE><H3><a name="h3-mousemask">mousemask</a></H3><PRE>
83 To make mouse events visible, use the <STRONG>mousemask</STRONG> function. This will
84 set the mouse events to be reported. By default, no mouse events are
85 reported. The function will return a mask to indicate which of the
86 specified mouse events can be reported; on complete failure it returns
87 0. If oldmask is non-NULL, this function fills the indicated location
88 with the previous value of the given window's mouse event mask.
90 As a side effect, setting a zero mousemask may turn off the mouse
91 pointer; setting a nonzero mask may turn it on. Whether this happens
95 </PRE><H3><a name="h3-Mouse-events">Mouse events</a></H3><PRE>
96 Here are the mouse event type masks which may be defined:
98 <EM>Name</EM> <EM>Description</EM>
99 ---------------------------------------------------------------------
100 BUTTON1_PRESSED mouse button 1 down
101 BUTTON1_RELEASED mouse button 1 up
102 BUTTON1_CLICKED mouse button 1 clicked
103 BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
104 BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
105 ---------------------------------------------------------------------
106 BUTTON2_PRESSED mouse button 2 down
107 BUTTON2_RELEASED mouse button 2 up
108 BUTTON2_CLICKED mouse button 2 clicked
109 BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
110 BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
111 ---------------------------------------------------------------------
112 BUTTON3_PRESSED mouse button 3 down
113 BUTTON3_RELEASED mouse button 3 up
115 BUTTON3_CLICKED mouse button 3 clicked
116 BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
117 BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
118 ---------------------------------------------------------------------
119 BUTTON4_PRESSED mouse button 4 down
120 BUTTON4_RELEASED mouse button 4 up
121 BUTTON4_CLICKED mouse button 4 clicked
122 BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
123 BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
124 ---------------------------------------------------------------------
125 BUTTON5_PRESSED mouse button 5 down
126 BUTTON5_RELEASED mouse button 5 up
127 BUTTON5_CLICKED mouse button 5 clicked
128 BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked
129 BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked
130 ---------------------------------------------------------------------
131 BUTTON_SHIFT shift was down during button state change
132 BUTTON_CTRL control was down during button state change
133 BUTTON_ALT alt was down during button state change
134 ALL_MOUSE_EVENTS report all button state changes
135 REPORT_MOUSE_POSITION report mouse movement
136 ---------------------------------------------------------------------
139 </PRE><H3><a name="h3-getmouse">getmouse</a></H3><PRE>
140 Once a class of mouse events has been made visible in a window, calling
141 the <STRONG>wgetch</STRONG> function on that window may return <STRONG>KEY_MOUSE</STRONG> as an indicator
142 that a mouse event has been queued. To read the event data and pop the
143 event off the queue, call <STRONG>getmouse</STRONG>. This function will return <STRONG>OK</STRONG> if a
144 mouse event is actually visible in the given window, <STRONG>ERR</STRONG> otherwise.
145 When <STRONG>getmouse</STRONG> returns <STRONG>OK</STRONG>, the data deposited as y and x in the event
146 structure coordinates will be screen-relative character-cell coordi-
147 nates. The returned state mask will have exactly one bit set to indi-
148 cate the event type. The corresponding data in the queue is marked in-
149 valid. A subsequent call to <STRONG>getmouse</STRONG> will retrieve the next older item
153 </PRE><H3><a name="h3-ungetmouse">ungetmouse</a></H3><PRE>
154 The <STRONG>ungetmouse</STRONG> function behaves analogously to <STRONG>ungetch</STRONG>. It pushes a
155 <STRONG>KEY_MOUSE</STRONG> event onto the input queue, and associates with that event
156 the given state data and screen-relative character-cell coordinates.
159 </PRE><H3><a name="h3-wenclose">wenclose</a></H3><PRE>
160 The <STRONG>wenclose</STRONG> function tests whether a given pair of screen-relative
161 character-cell coordinates is enclosed by a given window, returning
162 <STRONG>TRUE</STRONG> if it is and <STRONG>FALSE</STRONG> otherwise. It is useful for determining what
163 subset of the screen windows enclose the location of a mouse event.
166 </PRE><H3><a name="h3-wmouse_trafo">wmouse_trafo</a></H3><PRE>
167 The <STRONG>wmouse_trafo</STRONG> function transforms a given pair of coordinates from
168 stdscr-relative coordinates to coordinates relative to the given window
169 or vice versa. The resulting stdscr-relative coordinates are not al-
170 ways identical to window-relative coordinates due to the mechanism to
171 reserve lines on top or bottom of the screen for other purposes (see
172 the <STRONG>ripoffline</STRONG> and <STRONG><A HREF="curs_slk.3x.html">slk_init(3x)</A></STRONG> calls, for example).
174 <STRONG>o</STRONG> If the parameter <STRONG>to_screen</STRONG> is <STRONG>TRUE</STRONG>, the pointers <STRONG>pY,</STRONG> <STRONG>pX</STRONG> must refer-
175 ence the coordinates of a location inside the window <STRONG>win</STRONG>. They are
176 converted to window-relative coordinates and returned through the
177 pointers. If the conversion was successful, the function returns
178 <STRONG>TRUE</STRONG>.
180 <STRONG>o</STRONG> If one of the parameters was NULL or the location is not inside the
181 window, <STRONG>FALSE</STRONG> is returned.
183 <STRONG>o</STRONG> If <STRONG>to_screen</STRONG> is <STRONG>FALSE</STRONG>, the pointers <STRONG>pY,</STRONG> <STRONG>pX</STRONG> must reference window-
184 relative coordinates. They are converted to stdscr-relative coor-
185 dinates if the window <STRONG>win</STRONG> encloses this point. In this case the
186 function returns <STRONG>TRUE</STRONG>.
188 <STRONG>o</STRONG> If one of the parameters is NULL or the point is not inside the
189 window, <STRONG>FALSE</STRONG> is returned. The referenced coordinates are only re-
190 placed by the converted coordinates if the transformation was suc-
194 </PRE><H3><a name="h3-mouse_trafo">mouse_trafo</a></H3><PRE>
195 The <STRONG>mouse_trafo</STRONG> function performs the same translation as <STRONG>wmouse_trafo</STRONG>,
196 using stdscr for <STRONG>win</STRONG>.
199 </PRE><H3><a name="h3-mouseinterval">mouseinterval</a></H3><PRE>
200 The <STRONG>mouseinterval</STRONG> function sets the maximum time (in thousands of a
201 second) that can elapse between press and release events for them to be
202 recognized as a click. Use <STRONG>mouseinterval(0)</STRONG> to disable click resolu-
203 tion. This function returns the previous interval value. Use <STRONG>mousein-</STRONG>
204 <STRONG>terval(-1)</STRONG> to obtain the interval without altering it. The default is
205 one sixth of a second.
208 </PRE><H3><a name="h3-has_mouse">has_mouse</a></H3><PRE>
209 The <STRONG>has_mouse</STRONG> function returns <STRONG>TRUE</STRONG> if the mouse driver has been suc-
210 cessfully initialized.
212 Note that mouse events will be ignored when input is in cooked mode,
213 and will cause an error beep when cooked mode is being simulated in a
214 window by a function such as <STRONG>getstr</STRONG> that expects a linefeed for input-
218 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
219 <STRONG>getmouse</STRONG> and <STRONG>ungetmouse</STRONG> return the integer <STRONG>ERR</STRONG> upon failure or <STRONG>OK</STRONG> upon
220 successful completion:
222 <STRONG>getmouse</STRONG>
225 <STRONG>o</STRONG> If no mouse driver was initialized, or if the mask parameter is
228 <STRONG>o</STRONG> It also returns an error if no more events remain in the queue.
230 <STRONG>ungetmouse</STRONG>
231 returns an error if the FIFO is full.
233 <STRONG>mousemask</STRONG> returns the mask of reportable events.
235 <STRONG>mouseinterval</STRONG> returns the previous interval value, unless the terminal
236 was not initialized. In that case, it returns the maximum interval
239 <STRONG>wenclose</STRONG> and <STRONG>wmouse_trafo</STRONG> are boolean functions returning <STRONG>TRUE</STRONG> or <STRONG>FALSE</STRONG>
240 depending on their test result.
243 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
244 These calls were designed for <STRONG><A HREF="ncurses.3x.html">ncurses(3x)</A></STRONG>, and are not found in SVr4
245 curses, 4.4BSD curses, or any other previous version of curses.
247 SVr4 curses had support for the mouse in a variant of <STRONG>xterm</STRONG>. It is
248 mentioned in a few places, but with no supporting documentation:
250 <STRONG>o</STRONG> the "libcurses" manual page lists functions for this feature which
251 are prototyped in <STRONG>curses.h</STRONG>:
253 extern int mouse_set(long int);
254 extern int mouse_on(long int);
255 extern int mouse_off(long int);
256 extern int request_mouse_pos(void);
257 extern int map_button(unsigned long);
258 extern void wmouse_position(WINDOW *, int *, int *);
259 extern unsigned long getmouse(void), getbmap(void);
261 <STRONG>o</STRONG> the "terminfo" manual page lists capabilities for the feature
263 buttons btns BT Number of buttons on the mouse
264 get_mouse getm Gm Curses should get button events
265 key_mouse kmous Km 0631, Mouse event has occurred
266 mouse_info minfo Mi Mouse status information
267 req_mouse_pos reqmp RQ Request mouse position report
269 <STRONG>o</STRONG> the interface made assumptions (as does ncurses) about the escape
270 sequences sent to and received from the terminal.
272 For instance the SVr4 curses library used the <STRONG>get_mouse</STRONG> capability
273 to tell the terminal which mouse button events it should send,
274 passing the mouse-button bit-mask to the terminal. Also, it could
275 ask the terminal where the mouse was using the <STRONG>req_mouse_pos</STRONG> capa-
278 Those features required a terminal which had been modified to work
279 with curses. They were not part of the X Consortium's xterm.
281 When developing the xterm mouse support for ncurses in September 1995,
282 Eric Raymond was uninterested in using the same interface due to its
283 lack of documentation. Later, in 1998, Mark Hesseling provided support
284 in PDCurses 2.3 using the SVr4 interface. PDCurses, however, does not
285 use video terminals, making it unnecessary to be concerned about com-
286 patibility with the escape sequences.
288 The feature macro <STRONG>NCURSES_MOUSE_VERSION</STRONG> is provided so the preprocessor
289 can be used to test whether these features are present. If the inter-
290 face is changed, the value of <STRONG>NCURSES_MOUSE_VERSION</STRONG> will be increment-
291 ed. These values for <STRONG>NCURSES_MOUSE_VERSION</STRONG> may be specified when con-
294 1 has definitions for reserved events. The mask uses 28 bits.
296 2 adds definitions for button 5, removes the definitions for re-
297 served events. The mask uses 29 bits.
299 The order of the <STRONG>MEVENT</STRONG> structure members is not guaranteed. Addition-
300 al fields may be added to the structure in the future.
302 Under <STRONG><A HREF="ncurses.3x.html">ncurses(3x)</A></STRONG>, these calls are implemented using either xterm's
303 built-in mouse-tracking API or platform-specific drivers including
305 <STRONG>o</STRONG> Alessandro Rubini's gpm server
307 <STRONG>o</STRONG> FreeBSD sysmouse
309 <STRONG>o</STRONG> OS/2 EMX
311 If you are using an unsupported configuration, mouse events will not be
312 visible to <STRONG><A HREF="ncurses.3x.html">ncurses(3x)</A></STRONG> (and the <STRONG>mousemask</STRONG> function will always return
315 If the terminfo entry contains a <STRONG>XM</STRONG> string, this is used in the xterm
316 mouse driver to control the way the terminal is initialized for mouse
317 operation. The default, if <STRONG>XM</STRONG> is not found, corresponds to private
320 \E[?1000%?%p1%{1}%=%th%el%;
322 The mouse driver also recognizes a newer xterm private mode 1006, e.g.,
324 \E[?1006;1000%?%p1%{1}%=%th%el%;
326 The <EM>z</EM> member in the event structure is not presently used. It is in-
327 tended for use with touch screens (which may be pressure-sensitive) or
328 with 3D-mice/trackballs/power gloves.
330 The <STRONG>ALL_MOUSE_EVENTS</STRONG> class does not include <STRONG>REPORT_MOUSE_POSITION</STRONG>.
331 They are distinct. For example, in xterm, wheel/scrolling mice send
332 position reports as a sequence of presses of buttons 4 or 5 without
333 matching button-releases.
336 </PRE><H2><a name="h2-BUGS">BUGS</a></H2><PRE>
337 Mouse events under xterm will not in fact be ignored during cooked
338 mode, if they have been enabled by <STRONG>mousemask</STRONG>. Instead, the xterm mouse
339 report sequence will appear in the string read.
341 Mouse events under xterm will not be detected correctly in a window
342 with its keypad bit off, since they are interpreted as a variety of
343 function key. Your terminfo description should have <STRONG>kmous</STRONG> set to
344 "\E[M" (the beginning of the response from xterm for mouse clicks).
345 Other values for <STRONG>kmous</STRONG> are permitted, but under the same assumption,
346 i.e., it is the beginning of the response.
348 Because there are no standard terminal responses that would serve to
349 identify terminals which support the xterm mouse protocol, <STRONG>ncurses</STRONG> as-
350 sumes that if your $TERM environment variable contains "xterm", or
351 <STRONG>kmous</STRONG> is defined in the terminal description, then the terminal may
352 send mouse events. The <STRONG>kmous</STRONG> capability is checked first, allowing the
353 use of newer xterm mouse protocols.
356 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
357 <STRONG><A HREF="ncurses.3x.html">curses(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>, <STRONG><A HREF="curs_variables.3x.html">curs_variables(3x)</A></STRONG>.
361 <STRONG><A HREF="curs_mouse.3x.html">curs_mouse(3x)</A></STRONG>
365 <li><a href="#h2-NAME">NAME</a></li>
366 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
367 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
369 <li><a href="#h3-mousemask">mousemask</a></li>
370 <li><a href="#h3-Mouse-events">Mouse events</a></li>
371 <li><a href="#h3-getmouse">getmouse</a></li>
372 <li><a href="#h3-ungetmouse">ungetmouse</a></li>
373 <li><a href="#h3-wenclose">wenclose</a></li>
374 <li><a href="#h3-wmouse_trafo">wmouse_trafo</a></li>
375 <li><a href="#h3-mouse_trafo">mouse_trafo</a></li>
376 <li><a href="#h3-mouseinterval">mouseinterval</a></li>
377 <li><a href="#h3-has_mouse">has_mouse</a></li>
380 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
381 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
382 <li><a href="#h2-BUGS">BUGS</a></li>
383 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>