1curs_mouse(3X) curs_mouse(3X)
2
3
4
6 has_mouse, getmouse, ungetmouse, mousemask, wenclose, mouse_trafo,
7 wmouse_trafo, mouseinterval - mouse interface through curses
8
10 #include <curses.h>
11
12 typedef unsigned long mmask_t;
13
14 typedef struct {
15 short id; /* ID to distinguish multiple devices */
16 int x, y, z; /* event coordinates */
17 mmask_t bstate; /* button state bits */
18 } MEVENT;
19
20 bool has_mouse(void);
21 int getmouse(MEVENT *event);
22 int ungetmouse(MEVENT *event);
23 mmask_t mousemask(mmask_t newmask, mmask_t *oldmask);
24 bool wenclose(const WINDOW *win, int y, int x);
25 bool mouse_trafo(int* pY, int* pX, bool to_screen);
26 bool wmouse_trafo(const WINDOW* win, int* pY, int* pX,
27 bool to_screen);
28 int mouseinterval(int erval);
29
31 These functions provide an interface to mouse events from ncurses(3X).
32 Mouse events are represented by KEY_MOUSE pseudo-key values in the
33 wgetch(3X) input stream.
34
35 mousemask
36 To make mouse events visible, use the mousemask function. This will
37 set the mouse events to be reported. By default, no mouse events are
38 reported. The function will return a mask to indicate which of the
39 specified mouse events can be reported; on complete failure it returns
40 0. If oldmask is non-NULL, this function fills the indicated location
41 with the previous value of the given window's mouse event mask.
42
43 As a side effect, setting a zero mousemask may turn off the mouse
44 pointer; setting a nonzero mask may turn it on. Whether this happens
45 is device-dependent.
46
47 Mouse events
48 Here are the mouse event type masks which may be defined:
49
50 Name Description
51 ─────────────────────────────────────────────────────────────────────
52 BUTTON1_PRESSED mouse button 1 down
53 BUTTON1_RELEASED mouse button 1 up
54 BUTTON1_CLICKED mouse button 1 clicked
55 BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
56 BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
57 ─────────────────────────────────────────────────────────────────────
58 BUTTON2_PRESSED mouse button 2 down
59 BUTTON2_RELEASED mouse button 2 up
60 BUTTON2_CLICKED mouse button 2 clicked
61 BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
62 BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
63 ─────────────────────────────────────────────────────────────────────
64 BUTTON3_PRESSED mouse button 3 down
65 BUTTON3_RELEASED mouse button 3 up
66
67 BUTTON3_CLICKED mouse button 3 clicked
68 BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
69 BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
70 ─────────────────────────────────────────────────────────────────────
71 BUTTON4_PRESSED mouse button 4 down
72 BUTTON4_RELEASED mouse button 4 up
73 BUTTON4_CLICKED mouse button 4 clicked
74 BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
75 BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
76 ─────────────────────────────────────────────────────────────────────
77 BUTTON5_PRESSED mouse button 5 down
78 BUTTON5_RELEASED mouse button 5 up
79 BUTTON5_CLICKED mouse button 5 clicked
80 BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked
81 BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked
82 ─────────────────────────────────────────────────────────────────────
83 BUTTON_SHIFT shift was down during button state change
84 BUTTON_CTRL control was down during button state change
85 BUTTON_ALT alt was down during button state change
86 ALL_MOUSE_EVENTS report all button state changes
87 REPORT_MOUSE_POSITION report mouse movement
88 ─────────────────────────────────────────────────────────────────────
89
90 getmouse
91 Once a class of mouse events has been made visible in a window, calling
92 the wgetch function on that window may return KEY_MOUSE as an indicator
93 that a mouse event has been queued. To read the event data and pop the
94 event off the queue, call getmouse. This function will return OK if a
95 mouse event is actually visible in the given window, ERR otherwise.
96 When getmouse returns OK, the data deposited as y and x in the event
97 structure coordinates will be screen-relative character-cell coordi‐
98 nates. The returned state mask will have exactly one bit set to indi‐
99 cate the event type. The corresponding data in the queue is marked in‐
100 valid. A subsequent call to getmouse will retrieve the next older item
101 from the queue.
102
103 ungetmouse
104 The ungetmouse function behaves analogously to ungetch. It pushes a
105 KEY_MOUSE event onto the input queue, and associates with that event
106 the given state data and screen-relative character-cell coordinates.
107
108 wenclose
109 The wenclose function tests whether a given pair of screen-relative
110 character-cell coordinates is enclosed by a given window, returning
111 TRUE if it is and FALSE otherwise. It is useful for determining what
112 subset of the screen windows enclose the location of a mouse event.
113
114 wmouse_trafo
115 The wmouse_trafo function transforms a given pair of coordinates from
116 stdscr-relative coordinates to coordinates relative to the given window
117 or vice versa. The resulting stdscr-relative coordinates are not al‐
118 ways identical to window-relative coordinates due to the mechanism to
119 reserve lines on top or bottom of the screen for other purposes (see
120 the ripoffline and slk_init(3X) calls, for example).
121
122 · If the parameter to_screen is TRUE, the pointers pY, pX must refer‐
123 ence the coordinates of a location inside the window win. They are
124 converted to window-relative coordinates and returned through the
125 pointers. If the conversion was successful, the function returns
126 TRUE.
127
128 · If one of the parameters was NULL or the location is not inside the
129 window, FALSE is returned.
130
131 · If to_screen is FALSE, the pointers pY, pX must reference window-
132 relative coordinates. They are converted to stdscr-relative coor‐
133 dinates if the window win encloses this point. In this case the
134 function returns TRUE.
135
136 · If one of the parameters is NULL or the point is not inside the
137 window, FALSE is returned. The referenced coordinates are only re‐
138 placed by the converted coordinates if the transformation was suc‐
139 cessful.
140
141 mouse_trafo
142 The mouse_trafo function performs the same translation as wmouse_trafo,
143 using stdscr for win.
144
145 mouseinterval
146 The mouseinterval function sets the maximum time (in thousands of a
147 second) that can elapse between press and release events for them to be
148 recognized as a click. Use mouseinterval(0) to disable click resolu‐
149 tion. This function returns the previous interval value. Use mousein‐
150 terval(-1) to obtain the interval without altering it. The default is
151 one sixth of a second.
152
153 has_mouse
154 The has_mouse function returns TRUE if the mouse driver has been suc‐
155 cessfully initialized.
156
157 Note that mouse events will be ignored when input is in cooked mode,
158 and will cause an error beep when cooked mode is being simulated in a
159 window by a function such as getstr that expects a linefeed for input-
160 loop termination.
161
163 getmouse and ungetmouse return the integer ERR upon failure or OK upon
164 successful completion:
165
166 getmouse
167 returns an error.
168
169 · If no mouse driver was initialized, or if the mask parameter is
170 zero,
171
172 · It also returns an error if no more events remain in the queue.
173
174 ungetmouse
175 returns an error if the FIFO is full.
176
177 mousemask returns the mask of reportable events.
178
179 mouseinterval returns the previous interval value, unless the terminal
180 was not initialized. In that case, it returns the maximum interval
181 value (166).
182
183 wenclose and wmouse_trafo are boolean functions returning TRUE or FALSE
184 depending on their test result.
185
187 These calls were designed for ncurses(3X), and are not found in SVr4
188 curses, 4.4BSD curses, or any other previous version of curses.
189
190 SVr4 curses had support for the mouse in a variant of xterm. It is
191 mentioned in a few places, but with no supporting documentation:
192
193 · the “libcurses” manual page lists functions for this feature which
194 are prototyped in curses.h:
195
196 extern int mouse_set(long int);
197 extern int mouse_on(long int);
198 extern int mouse_off(long int);
199 extern int request_mouse_pos(void);
200 extern int map_button(unsigned long);
201 extern void wmouse_position(WINDOW *, int *, int *);
202 extern unsigned long getmouse(void), getbmap(void);
203
204 · the “terminfo” manual page lists capabilities for the feature
205
206 buttons btns BT Number of buttons on the mouse
207 get_mouse getm Gm Curses should get button events
208 key_mouse kmous Km 0631, Mouse event has occurred
209 mouse_info minfo Mi Mouse status information
210 req_mouse_pos reqmp RQ Request mouse position report
211
212 · the interface made assumptions (as does ncurses) about the escape
213 sequences sent to and received from the terminal.
214
215 For instance the SVr4 curses library used the get_mouse capability
216 to tell the terminal which mouse button events it should send,
217 passing the mouse-button bit-mask to the terminal. Also, it could
218 ask the terminal where the mouse was using the req_mouse_pos capa‐
219 bility.
220
221 Those features required a terminal which had been modified to work
222 with curses. They were not part of the X Consortium's xterm.
223
224 When developing the xterm mouse support for ncurses in September 1995,
225 Eric Raymond was uninterested in using the same interface due to its
226 lack of documentation. Later, in 1998, Mark Hesseling provided support
227 in PDCurses 2.3 using the SVr4 interface. PDCurses, however, does not
228 use video terminals, making it unnecessary to be concerned about com‐
229 patibility with the escape sequences.
230
231 The feature macro NCURSES_MOUSE_VERSION is provided so the preprocessor
232 can be used to test whether these features are present. If the inter‐
233 face is changed, the value of NCURSES_MOUSE_VERSION will be increment‐
234 ed. These values for NCURSES_MOUSE_VERSION may be specified when con‐
235 figuring ncurses:
236
237 1 has definitions for reserved events. The mask uses 28 bits.
238
239 2 adds definitions for button 5, removes the definitions for re‐
240 served events. The mask uses 29 bits.
241
242 The order of the MEVENT structure members is not guaranteed. Addition‐
243 al fields may be added to the structure in the future.
244
245 Under ncurses(3X), these calls are implemented using either xterm's
246 built-in mouse-tracking API or platform-specific drivers including
247
248 · Alessandro Rubini's gpm server
249
250 · FreeBSD sysmouse
251
252 · OS/2 EMX
253
254 If you are using an unsupported configuration, mouse events will not be
255 visible to ncurses(3X) (and the mousemask function will always return
256 0).
257
258 If the terminfo entry contains a XM string, this is used in the xterm
259 mouse driver to control the way the terminal is initialized for mouse
260 operation. The default, if XM is not found, corresponds to private
261 mode 1000 of xterm:
262
263 \E[?1000%?%p1%{1}%=%th%el%;
264
265 The mouse driver also recognizes a newer xterm private mode 1006, e.g.,
266
267 \E[?1006;1000%?%p1%{1}%=%th%el%;
268
269 The z member in the event structure is not presently used. It is in‐
270 tended for use with touch screens (which may be pressure-sensitive) or
271 with 3D-mice/trackballs/power gloves.
272
273 The ALL_MOUSE_EVENTS class does not include REPORT_MOUSE_POSITION.
274 They are distinct. For example, in xterm, wheel/scrolling mice send
275 position reports as a sequence of presses of buttons 4 or 5 without
276 matching button-releases.
277
279 Mouse events under xterm will not in fact be ignored during cooked
280 mode, if they have been enabled by mousemask. Instead, the xterm mouse
281 report sequence will appear in the string read.
282
283 Mouse events under xterm will not be detected correctly in a window
284 with its keypad bit off, since they are interpreted as a variety of
285 function key. Your terminfo description should have kmous set to
286 “\E[M” (the beginning of the response from xterm for mouse clicks).
287 Other values for kmous are permitted, but under the same assumption,
288 i.e., it is the beginning of the response.
289
290 Because there are no standard terminal responses that would serve to
291 identify terminals which support the xterm mouse protocol, ncurses as‐
292 sumes that if kmous is defined in the terminal description, or if the
293 terminal description's primary name or aliases contain the string
294 “xterm”, then the terminal may send mouse events. The kmous capability
295 is checked first, allowing the use of newer xterm mouse protocols such
296 as xterm's private mode 1006.
297
299 curses(3X), curs_kernel(3X), curs_slk(3X), curs_variables(3X).
300
301
302
303 curs_mouse(3X)