1curs_mouse(3X)                                                  curs_mouse(3X)
2
3
4

NAME

6       has_mouse, getmouse, ungetmouse, mousemask, wenclose, mouse_trafo,
7       wmouse_trafo, mouseinterval - mouse interface through curses
8

SYNOPSIS

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
22       int getmouse(MEVENT *event);
23       int ungetmouse(MEVENT *event);
24
25       mmask_t mousemask(mmask_t newmask, mmask_t *oldmask);
26
27       bool wenclose(const WINDOW *win, int y, int x);
28
29       bool mouse_trafo(int* pY, int* pX, bool to_screen);
30       bool wmouse_trafo(const WINDOW* win,
31                         int* pY, int* pX, bool to_screen);
32
33       int mouseinterval(int erval);
34

DESCRIPTION

36       These functions provide an interface to mouse events from  ncurses(3X).
37       Mouse  events  are  represented  by  KEY_MOUSE pseudo-key values in the
38       wgetch(3X) input stream.
39
40   mousemask
41       To make mouse events visible, use the mousemask  function.   This  will
42       set  the  mouse events to be reported.  By default, no mouse events are
43       reported.  The function will return a mask to  indicate  which  of  the
44       specified  mouse events can be reported; on complete failure it returns
45       0.  If oldmask is non-NULL, this function fills the indicated  location
46       with the previous value of the given window's mouse event mask.
47
48       As  a  side  effect,  setting  a  zero mousemask may turn off the mouse
49       pointer; setting a nonzero mask may turn it on.  Whether  this  happens
50       is device-dependent.
51
52   Mouse events
53       Here are the mouse event type masks which may be defined:
54
55       Name                     Description
56       ─────────────────────────────────────────────────────────────────────
57       BUTTON1_PRESSED          mouse button 1 down
58       BUTTON1_RELEASED         mouse button 1 up
59       BUTTON1_CLICKED          mouse button 1 clicked
60       BUTTON1_DOUBLE_CLICKED   mouse button 1 double clicked
61       BUTTON1_TRIPLE_CLICKED   mouse button 1 triple clicked
62       ─────────────────────────────────────────────────────────────────────
63       BUTTON2_PRESSED          mouse button 2 down
64       BUTTON2_RELEASED         mouse button 2 up
65       BUTTON2_CLICKED          mouse button 2 clicked
66
67       BUTTON2_DOUBLE_CLICKED   mouse button 2 double clicked
68       BUTTON2_TRIPLE_CLICKED   mouse button 2 triple clicked
69       ─────────────────────────────────────────────────────────────────────
70       BUTTON3_PRESSED          mouse button 3 down
71       BUTTON3_RELEASED         mouse button 3 up
72       BUTTON3_CLICKED          mouse button 3 clicked
73       BUTTON3_DOUBLE_CLICKED   mouse button 3 double clicked
74       BUTTON3_TRIPLE_CLICKED   mouse button 3 triple clicked
75       ─────────────────────────────────────────────────────────────────────
76       BUTTON4_PRESSED          mouse button 4 down
77       BUTTON4_RELEASED         mouse button 4 up
78       BUTTON4_CLICKED          mouse button 4 clicked
79       BUTTON4_DOUBLE_CLICKED   mouse button 4 double clicked
80       BUTTON4_TRIPLE_CLICKED   mouse button 4 triple clicked
81       ─────────────────────────────────────────────────────────────────────
82       BUTTON5_PRESSED          mouse button 5 down
83       BUTTON5_RELEASED         mouse button 5 up
84       BUTTON5_CLICKED          mouse button 5 clicked
85       BUTTON5_DOUBLE_CLICKED   mouse button 5 double clicked
86       BUTTON5_TRIPLE_CLICKED   mouse button 5 triple clicked
87       ─────────────────────────────────────────────────────────────────────
88       BUTTON_SHIFT             shift was down during button state change
89       BUTTON_CTRL              control was down during button state change
90       BUTTON_ALT               alt was down during button state change
91       ALL_MOUSE_EVENTS         report all button state changes
92       REPORT_MOUSE_POSITION    report mouse movement
93       ─────────────────────────────────────────────────────────────────────
94
95   getmouse
96       Once a class of mouse events has been made visible in a window, calling
97       the wgetch function on that window may return KEY_MOUSE as an indicator
98       that a mouse event has been queued.  To read the event data and pop the
99       event off the queue, call getmouse.  This function will return OK if  a
100       mouse  event  is  actually  visible in the given window, ERR otherwise.
101       When getmouse returns OK, the data deposited as y and x  in  the  event
102       structure  coordinates  will  be screen-relative character-cell coordi‐
103       nates.  The returned state mask will have exactly one bit set to  indi‐
104       cate the event type.  The corresponding data in the queue is marked in‐
105       valid.  A subsequent call to getmouse will retrieve the next older item
106       from the queue.
107
108   ungetmouse
109       The  ungetmouse  function  behaves analogously to ungetch.  It pushes a
110       KEY_MOUSE event onto the input queue, and associates  with  that  event
111       the given state data and screen-relative character-cell coordinates.
112
113   wenclose
114       The  wenclose  function  tests  whether a given pair of screen-relative
115       character-cell coordinates is enclosed by  a  given  window,  returning
116       TRUE  if  it is and FALSE otherwise.  It is useful for determining what
117       subset of the screen windows enclose the location of a mouse event.
118
119   wmouse_trafo
120       The wmouse_trafo function transforms a given pair of  coordinates  from
121       stdscr-relative coordinates to coordinates relative to the given window
122       or vice versa.  The resulting stdscr-relative coordinates are  not  al‐
123       ways  identical  to window-relative coordinates due to the mechanism to
124       reserve lines on top or bottom of the screen for  other  purposes  (see
125       the ripoffline and slk_init(3X) calls, for example).
126
127       •   If the parameter to_screen is TRUE, the pointers pY, pX must refer‐
128           ence the coordinates of a location inside the window win.  They are
129           converted  to  window-relative coordinates and returned through the
130           pointers.  If the conversion was successful, the  function  returns
131           TRUE.
132
133       •   If one of the parameters was NULL or the location is not inside the
134           window, FALSE is returned.
135
136       •   If to_screen is FALSE, the pointers pY, pX must  reference  window-
137           relative  coordinates.  They are converted to stdscr-relative coor‐
138           dinates if the window win encloses this point.  In  this  case  the
139           function returns TRUE.
140
141       •   If  one  of  the  parameters is NULL or the point is not inside the
142           window, FALSE is returned.  The referenced coordinates are only re‐
143           placed  by the converted coordinates if the transformation was suc‐
144           cessful.
145
146   mouse_trafo
147       The mouse_trafo function performs the same translation as wmouse_trafo,
148       using stdscr for win.
149
150   mouseinterval
151       The  mouseinterval  function  sets  the maximum time (in thousands of a
152       second) that can elapse between press and release events for them to be
153       recognized  as  a click.  Use mouseinterval(0) to disable click resolu‐
154       tion.  This function returns the previous interval value.  Use mousein‐
155       terval(-1)  to obtain the interval without altering it.  The default is
156       one sixth of a second.
157
158   has_mouse
159       The has_mouse function returns TRUE if the mouse driver has  been  suc‐
160       cessfully initialized.
161
162       Note  that  mouse  events will be ignored when input is in cooked mode,
163       and will cause an error beep when cooked mode is being simulated  in  a
164       window  by a function such as getstr that expects a linefeed for input-
165       loop termination.
166

RETURN VALUE

168       getmouse and ungetmouse return the integer ERR upon failure or OK  upon
169       successful completion:
170
171          getmouse
172               returns an error.
173
174          •   If  no mouse driver was initialized, or if the mask parameter is
175              zero,
176
177          •   It also returns an error if no more events remain in the queue.
178
179          ungetmouse
180               returns an error if the FIFO is full.
181
182       mousemask returns the mask of reportable events.
183
184       mouseinterval returns the previous interval value, unless the  terminal
185       was  not  initialized.   In  that case, it returns the maximum interval
186       value (166).
187
188       wenclose and wmouse_trafo are boolean functions returning TRUE or FALSE
189       depending on their test result.
190

PORTABILITY

192       These  calls  were  designed for ncurses(3X), and are not found in SVr4
193       curses, 4.4BSD curses, or any other previous version of curses.
194
195       SVr4 curses had support for the mouse in a variant  of  xterm.   It  is
196       mentioned in a few places, but with no supporting documentation:
197
198       •   the  “libcurses” manual page lists functions for this feature which
199           are prototyped in curses.h:
200
201               extern int mouse_set(long int);
202               extern int mouse_on(long int);
203               extern int mouse_off(long int);
204               extern int request_mouse_pos(void);
205               extern int map_button(unsigned long);
206               extern void wmouse_position(WINDOW *, int *, int *);
207               extern unsigned long getmouse(void), getbmap(void);
208
209       •   the “terminfo” manual page lists capabilities for the feature
210
211               buttons           btns    BT       Number of buttons on the mouse
212               get_mouse         getm    Gm       Curses should get button events
213               key_mouse         kmous   Km       0631, Mouse event has occurred
214               mouse_info        minfo   Mi       Mouse status information
215               req_mouse_pos     reqmp   RQ       Request mouse position report
216
217       •   the interface made assumptions (as does ncurses) about  the  escape
218           sequences sent to and received from the terminal.
219
220           For  instance the SVr4 curses library used the get_mouse capability
221           to tell the terminal which mouse  button  events  it  should  send,
222           passing  the mouse-button bit-mask to the terminal.  Also, it could
223           ask the terminal where the mouse was using the req_mouse_pos  capa‐
224           bility.
225
226           Those  features required a terminal which had been modified to work
227           with curses.  They were not part of the X Consortium's xterm.
228
229       When developing the xterm mouse support for ncurses in September  1995,
230       Eric  Raymond  was  uninterested in using the same interface due to its
231       lack of documentation.  Later, in 1998, Mark Hesseling provided support
232       in  PDCurses 2.3 using the SVr4 interface.  PDCurses, however, does not
233       use video terminals, making it unnecessary to be concerned  about  com‐
234       patibility with the escape sequences.
235
236       The feature macro NCURSES_MOUSE_VERSION is provided so the preprocessor
237       can be used to test whether these features are present.  If the  inter‐
238       face  is changed, the value of NCURSES_MOUSE_VERSION will be increment‐
239       ed.  These values for NCURSES_MOUSE_VERSION may be specified when  con‐
240       figuring ncurses:
241
242          1  has definitions for reserved events.  The mask uses 28 bits.
243
244          2  adds  definitions  for  button 5, removes the definitions for re‐
245             served events.  The mask uses 29 bits.
246
247       The order of the MEVENT structure members is not guaranteed.  Addition‐
248       al fields may be added to the structure in the future.
249
250       Under  ncurses(3X),  these  calls  are implemented using either xterm's
251       built-in mouse-tracking API or platform-specific drivers including
252
253          •   Alessandro Rubini's gpm server
254
255          •   FreeBSD sysmouse
256
257          •   OS/2 EMX
258
259       If you are using an unsupported configuration, mouse events will not be
260       visible  to  ncurses(3X) (and the mousemask function will always return
261       0).
262
263       If the terminfo entry contains a XM string, this is used in  the  xterm
264       mouse  driver  to control the way the terminal is initialized for mouse
265       operation.  The default, if XM is not  found,  corresponds  to  private
266       mode 1000 of xterm:
267
268          \E[?1000%?%p1%{1}%=%th%el%;
269
270       The mouse driver also recognizes a newer xterm private mode 1006, e.g.,
271
272          \E[?1006;1000%?%p1%{1}%=%th%el%;
273
274       The  z  member in the event structure is not presently used.  It is in‐
275       tended for use with touch screens (which may be pressure-sensitive)  or
276       with 3D-mice/trackballs/power gloves.
277
278       The  ALL_MOUSE_EVENTS  class  does  not  include REPORT_MOUSE_POSITION.
279       They are distinct.  For example, in xterm,  wheel/scrolling  mice  send
280       position  reports  as  a  sequence of presses of buttons 4 or 5 without
281       matching button-releases.
282

BUGS

284       Mouse events under xterm will not in  fact  be  ignored  during  cooked
285       mode, if they have been enabled by mousemask.  Instead, the xterm mouse
286       report sequence will appear in the string read.
287
288       Mouse events under xterm will not be detected  correctly  in  a  window
289       with  its  keypad  bit  off, since they are interpreted as a variety of
290       function key.  Your terminfo  description  should  have  kmous  set  to
291       “\E[M”  (the  beginning  of  the response from xterm for mouse clicks).
292       Other values for kmous are permitted, but under  the  same  assumption,
293       i.e., it is the beginning of the response.
294
295       Because  there  are  no standard terminal responses that would serve to
296       identify terminals which support the xterm mouse protocol, ncurses  as‐
297       sumes  that  if kmous is defined in the terminal description, or if the
298       terminal description's primary  name  or  aliases  contain  the  string
299       “xterm”, then the terminal may send mouse events.  The kmous capability
300       is checked first, allowing the use of newer xterm mouse protocols  such
301       as xterm's private mode 1006.
302

SEE ALSO

304       curses(3X), curs_kernel(3X), curs_slk(3X), curs_variables(3X).
305
306
307
308                                                                curs_mouse(3X)
Impressum