| Main index | Section 3 | Options |
#include <curses.h>typedef unsigned long mmask_t;
typedef struct { short id; /* ID to distinguish multiple devices */ int x, y, z; /* event coordinates */ mmask_t bstate; /* button state bits */ } MEVENT;
bool has_mouse(void);
mmask_t mousemask(mmask_t newmask, mmask_t *oldmask);
int getmouse(MEVENT *event); int ungetmouse(MEVENT *event);
bool wenclose(const WINDOW *win, int y, int x);
bool mouse_trafo(int* pY, int* pX, bool to_screen); bool wmouse_trafo(const WINDOW* win,
int* pY, int* pX, bool to_screen);int mouseinterval(int erval);
Mouse events are ignored when input is in cooked mode, and cause an error beep when cooked mode is being simulated in a window by a function such as getstr that expects a linefeed for input-loop termination.
| &#187; | The function returns an updated copy of newmask to indicate which of the specified mouse events can be reported. |
| If the screen has not been initialized, or if the terminal does not support mouse-events, this function returns 0. | |
| &#187; | If oldmask is non-NULL, this function fills the indicated location with the previous value of the current screen's mouse event mask. |
If the parameter is a pad, wenclose uses the most recent screen coordinates used for this pad in prefresh(3X) or pnoutrefresh(3X).
| &#187; | If the parameter to_screen is TRUE, the pointers pY, pX must reference the coordinates of a location inside the window win. They are converted to stdscr-relative coordinates and returned through the pointers. If the conversion was successful, the function returns TRUE. |
| If one of the parameters was NULL or the location is not inside the window, FALSE is returned. | |
| &#187; | If to_screen is FALSE, the pointers pY, pX must reference stdscr-relative coordinates. They are converted to window-relative coordinates if the window win encloses this point. In this case the function returns TRUE. |
| If one of the parameters is NULL or the point is not inside the window, FALSE is returned. | |
Calling mouseinterval(0) disables click resolution. When ncurses detects a mouse event, it awaits further input activity up to this interval, and then checks for a subsequent mouse event which can be combined with the first event. If the timeout expires without input activity (which would happen with a zero interval), then no click resolution will occur.
This function returns the previous interval value. Use mouseinterval(-1) to obtain the interval without altering it.
The mouse interval is set to one sixth of a second when the corresponding screen is initialized, e.g., in initscr(3X) or setupterm(3X).
getmouse and ungetmouse return ERR upon failure and OK upon success.
getmouse fails if:
| &#187; | no mouse driver was initialized, |
| &#187; | the mask of reportable events is zero, |
| &#187; | a mouse event was detected that does not match the mask, |
| &#187; | or if no more events remain in the queue. |
mousemask returns the mask of reportable events.
mouseinterval returns the previous interval value, unless the terminal was not initialized. In that case, it returns the maximum interval value (166).
Under ncurses, these calls are implemented using either xterm's built-in mouse-tracking API or platform-specific drivers including
&#187; Alessandro Rubini's gpm server &#187; FreeBSD sysmouse &#187; OS/2 EMX
If you are using an unsupported configuration, mouse events will not be visible to ncurses (and the mousemask function will always return 0).
If the term info entry contains a XM string, this is used in the xterm mouse driver to control the way the terminal is initialized for mouse operation. The default, if XM is not found, corresponds to private mode 1000 of xterm:
\E[?1000%?%p1%{1}%=%th%el%;
The mouse driver also recognizes a newer xterm private mode 1006, e.g.,
\E[?1006;1000%?%p1%{1}%=%th%el%;
The z member in the event structure is not presently used. It is intended for use with touch screens (which may be pressure-sensitive) or with 3D-mice/trackballs/power gloves.
The ALL_MOUSE_EVENTS class does not include REPORT_MOUSE_POSITION. They are distinct. For example, in xterm, wheel/scrolling mice send position reports as a sequence of presses of buttons 4 or 5 without matching button-releases.
1 has definitions for reserved events. The mask uses 28 bits. 2 adds definitions for button 5, removes the definitions for reserved events. The mask uses 29 bits.
SVr4 curses had support for the mouse in a variant of xterm(1). It is mentioned in a few places, with little supporting documentation.
| &#187; |
Its libcurses manual page lists functions for this feature
prototyped in curses.h.
| ||
| &#187; |
Its terminfo manual page lists capabilities for the feature.
| ||
| &#187; | The interface made assumptions (as does ncurses) about the escape sequences sent to and received from the terminal. | ||
| For instance, the SVr4 curses library used the get_mouse capability to tell the terminal which mouse button events it should send, passing the mouse-button bit mask to the terminal. Also, it could ask the terminal where the mouse was using the req_mouse_pos capability. | |||
| Those features required a terminal program that had been modified to work with SVr4 curses. They were not part of the X Consortium's xterm. | |||
Mouse event reports from xterm are not detected correctly in a window with keypad application mode disabled, since they are interpreted as a variety of function key. Set the terminal's term info capability kmous to \E[M (the beginning of the response from xterm for mouse clicks). Other values of kmous are permitted under the same assumption, that is, the report begins with that sequence.
Because there are no standard response sequences that serve to identify terminals supporting the xterm mouse protocol, ncurses assumes that if kmous is defined in the terminal description, or if the terminal type's primary name or aliases contain the string xterm, then the terminal may send mouse events. The kmous capability is checked first, allowing use of newer xterm mouse protocols, such as its private mode 1006.
| 2024-04-20 | curs_mouse (3X) | ncurses 6.5 |
| Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Modern Unix impedes progress in computer science, wastes billions of dollars, and destroys the common sense of many who seriously use it. | ” |
| — The Unix Haters' handbook | ||