curs_mouse.3x 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. '\" t
  2. .\"***************************************************************************
  3. .\" Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
  4. .\" *
  5. .\" Permission is hereby granted, free of charge, to any person obtaining a *
  6. .\" copy of this software and associated documentation files (the *
  7. .\" "Software"), to deal in the Software without restriction, including *
  8. .\" without limitation the rights to use, copy, modify, merge, publish, *
  9. .\" distribute, distribute with modifications, sublicense, and/or sell *
  10. .\" copies of the Software, and to permit persons to whom the Software is *
  11. .\" furnished to do so, subject to the following conditions: *
  12. .\" *
  13. .\" The above copyright notice and this permission notice shall be included *
  14. .\" in all copies or substantial portions of the Software. *
  15. .\" *
  16. .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  17. .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  18. .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  19. .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  20. .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  21. .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  22. .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  23. .\" *
  24. .\" Except as contained in this notice, the name(s) of the above copyright *
  25. .\" holders shall not be used in advertising or otherwise to promote the *
  26. .\" sale, use or other dealings in this Software without prior written *
  27. .\" authorization. *
  28. .\"***************************************************************************
  29. .\"
  30. .\" $Id: curs_mouse.3x,v 1.31 2008/11/23 00:09:53 tom Exp $
  31. .TH curs_mouse 3X ""
  32. .na
  33. .hy 0
  34. .SH NAME
  35. \fBhas_mouse\fR,
  36. \fBgetmouse\fR, \fBungetmouse\fR,
  37. \fBmousemask\fR, \fBwenclose\fR,
  38. \fBmouse_trafo\fR, \fBwmouse_trafo\fR,
  39. \fBmouseinterval\fR - mouse interface through curses
  40. .ad
  41. .hy
  42. .SH SYNOPSIS
  43. .nf
  44. \fB#include <curses.h>
  45. .PP
  46. \fBtypedef unsigned long mmask_t;
  47. .PP
  48. typedef struct
  49. {
  50. short id; \fI/* ID to distinguish multiple devices */\fB
  51. int x, y, z; \fI/* event coordinates */\fB
  52. mmask_t bstate; \fI/* button state bits */\fB
  53. }
  54. MEVENT;\fR
  55. .fi
  56. .br
  57. \fBbool has_mouse(void);\fR
  58. .br
  59. -\fBint getmouse(MEVENT *event);\fR
  60. .br
  61. \fBint ungetmouse(MEVENT *event);\fR
  62. .br
  63. \fBmmask_t mousemask(mmask_t newmask, mmask_t *oldmask);\fR
  64. .br
  65. \fBbool wenclose(const WINDOW *win, int y, int x);\fR
  66. .br
  67. \fBbool mouse_trafo(int* pY, int* pX, bool to_screen);\fR
  68. .br
  69. \fBbool wmouse_trafo(const WINDOW* win, int* pY, int* pX,\fR
  70. .br
  71. \fBbool to_screen);\fR
  72. .br
  73. \fBint mouseinterval(int erval);\fR
  74. .br
  75. .SH DESCRIPTION
  76. These functions provide an interface to mouse events from
  77. \fBncurses\fR(3X).
  78. Mouse events are represented by \fBKEY_MOUSE\fR
  79. pseudo-key values in the \fBwgetch\fR input stream.
  80. .PP
  81. To make mouse events visible, use the \fBmousemask\fR function.
  82. This will set
  83. the mouse events to be reported.
  84. By default, no mouse events are reported.
  85. The function will return a mask to indicate which of the specified mouse events
  86. can be reported; on complete failure it returns 0.
  87. If oldmask is non-NULL,
  88. this function fills the indicated location with the previous value of the given
  89. window's mouse event mask.
  90. .PP
  91. As a side effect, setting a zero mousemask may turn off the mouse pointer;
  92. setting a nonzero mask may turn it on.
  93. Whether this happens is device-dependent.
  94. .PP
  95. Here are the mouse event type masks which may be defined:
  96. .PP
  97. .TS
  98. l l
  99. _ _
  100. l l.
  101. \fIName\fR \fIDescription\fR
  102. BUTTON1_PRESSED mouse button 1 down
  103. BUTTON1_RELEASED mouse button 1 up
  104. BUTTON1_CLICKED mouse button 1 clicked
  105. BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
  106. BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
  107. _
  108. BUTTON2_PRESSED mouse button 2 down
  109. BUTTON2_RELEASED mouse button 2 up
  110. BUTTON2_CLICKED mouse button 2 clicked
  111. BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
  112. BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
  113. _
  114. BUTTON3_PRESSED mouse button 3 down
  115. BUTTON3_RELEASED mouse button 3 up
  116. BUTTON3_CLICKED mouse button 3 clicked
  117. BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
  118. BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
  119. _
  120. BUTTON4_PRESSED mouse button 4 down
  121. BUTTON4_RELEASED mouse button 4 up
  122. BUTTON4_CLICKED mouse button 4 clicked
  123. BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
  124. BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
  125. _
  126. BUTTON5_PRESSED mouse button 5 down
  127. BUTTON5_RELEASED mouse button 5 up
  128. BUTTON5_CLICKED mouse button 5 clicked
  129. BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked
  130. BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked
  131. _
  132. BUTTON_SHIFT shift was down during button state change
  133. BUTTON_CTRL control was down during button state change
  134. BUTTON_ALT alt was down during button state change
  135. ALL_MOUSE_EVENTS report all button state changes
  136. REPORT_MOUSE_POSITION report mouse movement
  137. _
  138. .TE
  139. .PP
  140. Once a class of mouse events have been made visible in a window,
  141. calling the \fBwgetch\fR function on that window may return
  142. \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued.
  143. To read the event data and pop the event off the queue, call
  144. \fBgetmouse\fR.
  145. This function will return \fBOK\fR if a mouse event
  146. is actually visible in the given window, \fBERR\fR otherwise.
  147. When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and
  148. x in the event structure coordinates will be screen-relative character-cell
  149. coordinates.
  150. The returned state mask will have exactly one bit set to
  151. indicate the event type.
  152. .PP
  153. The \fBungetmouse\fR function behaves analogously to \fBungetch\fR.
  154. It pushes
  155. a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event
  156. the given state data and screen-relative character-cell coordinates.
  157. .PP
  158. The \fBwenclose\fR function tests whether a given pair of screen-relative
  159. character-cell coordinates is enclosed by a given window, returning TRUE
  160. if it is and FALSE otherwise.
  161. It is useful for determining what subset of
  162. the screen windows enclose the location of a mouse event.
  163. .PP
  164. The \fBwmouse_trafo\fR function transforms a given pair of coordinates
  165. from stdscr-relative coordinates
  166. to coordinates relative to the given window or vice versa.
  167. Please remember, that stdscr-relative coordinates are not always identical
  168. to window-relative coordinates due to the mechanism to reserve lines on top
  169. or bottom of the screen for other purposes
  170. (see the \fBripoffline()\fP and \fBslk_init\fR calls, for example).
  171. If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers
  172. \fBpY, pX\fR must reference the coordinates of a location
  173. inside the window \fBwin\fR.
  174. They are converted to window-relative coordinates and returned
  175. through the pointers.
  176. If the conversion was successful, the function returns \fBTRUE\fR.
  177. If one of the parameters was NULL or the location is
  178. not inside the window, \fBFALSE\fR is returned.
  179. If \fBto_screen\fR is
  180. \fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative
  181. coordinates.
  182. They are converted to stdscr-relative coordinates if the
  183. window \fBwin\fR encloses this point.
  184. In this case the function returns \fBTRUE\fR.
  185. If one of the parameters is NULL or the point is not inside the
  186. window, \fBFALSE\fR is returned.
  187. Please notice, that the referenced coordinates
  188. are only replaced by the converted coordinates if the transformation was
  189. successful.
  190. .PP
  191. The \fBmouse_trafo\fR function performs the same translation
  192. as \fBwmouse_trafo\fR,
  193. using stdscr for \fBwin\fR.
  194. .PP
  195. The \fBmouseinterval\fR function sets the maximum time (in thousands of a
  196. second) that can elapse between press and release events for them to
  197. be recognized as a click.
  198. Use \fBmouseinterval(0)\fR to disable click resolution.
  199. This function returns the previous interval value.
  200. Use \fBmouseinterval(-1)\fR to obtain the interval without altering it.
  201. The default is one sixth of a second.
  202. .PP
  203. The \fBhas_mouse\fP function returns TRUE if the mouse driver has been
  204. successfully initialized.
  205. .PP
  206. Note that mouse events will be ignored when input is in cooked mode, and will
  207. cause an error beep when cooked mode is being simulated in a window by a
  208. function such as \fBgetstr\fR that expects a linefeed for input-loop
  209. termination.
  210. .SH RETURN VALUE
  211. \fBgetmouse\fR and \fBungetmouse\fR
  212. return the integer \fBERR\fR upon failure or \fBOK\fR
  213. upon successful completion.
  214. .RS
  215. .TP 5
  216. \fBgetmouse\fP
  217. returns an error.
  218. If no mouse driver was initialized, or
  219. if the mask parameter is zero,
  220. .TP 5
  221. \fBungetmouse\fP
  222. returns an error if the FIFO is full.
  223. .RE
  224. .PP
  225. \fBmousemask\fR
  226. returns the mask of reportable events.
  227. .PP
  228. \fBmouseinterval\fR
  229. returns the previous interval value, unless
  230. the terminal was not initialized.
  231. In that case, it returns the maximum interval value (166).
  232. .PP
  233. \fBwenclose\fR and \fBwmouse_trafo\fR
  234. are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending
  235. on their test result.
  236. .SH PORTABILITY
  237. These calls were designed for \fBncurses\fR(3X), and are not found in SVr4
  238. curses, 4.4BSD curses, or any other previous version of curses.
  239. .PP
  240. The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor
  241. can be used to test whether these features are present.
  242. If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be
  243. incremented.
  244. These values for \fBNCURSES_MOUSE_VERSION\fR may be
  245. specified when configuring ncurses:
  246. .RS
  247. .TP 3
  248. 1
  249. has definitions for reserved events.
  250. The mask uses 28 bits.
  251. .TP 3
  252. 2
  253. adds definitions for button 5,
  254. removes the definitions for reserved events.
  255. The mask uses 29 bits.
  256. .RE
  257. .PP
  258. The order of the \fBMEVENT\fR structure members is not guaranteed.
  259. Additional fields may be added to the structure in the future.
  260. .PP
  261. Under \fBncurses\fR(3X), these calls are implemented using either
  262. xterm's built-in mouse-tracking API or
  263. platform-specific drivers including
  264. .RS
  265. Alessandro Rubini's gpm server.
  266. .br
  267. FreeBSD sysmouse
  268. .br
  269. OS/2 EMX
  270. .RE
  271. If you are using an unsupported configuration,
  272. mouse events will not be visible to
  273. \fBncurses\fR(3X) (and the \fBmousemask\fR function will always
  274. return \fB0\fR).
  275. .PP
  276. If the terminfo entry contains a \fBXM\fR string,
  277. this is used in the xterm mouse driver to control the
  278. way the terminal is initialized for mouse operation.
  279. The default, if \fBXM\fR is not found,
  280. corresponds to private mode 1000 of xterm:
  281. .RS
  282. \\E[?1000%?%p1%{1}%=%th%el%;
  283. .RE
  284. The z member in the event structure is not presently used.
  285. It is intended
  286. for use with touch screens (which may be pressure-sensitive) or with
  287. 3D-mice/trackballs/power gloves.
  288. .SH BUGS
  289. Mouse events under xterm will not in fact be ignored during cooked mode,
  290. if they have been enabled by \fBmousemask\fR.
  291. Instead, the xterm mouse
  292. report sequence will appear in the string read.
  293. .PP
  294. Mouse events under xterm will not be detected correctly in a window with
  295. its keypad bit off, since they are interpreted as a variety of function key.
  296. Your terminfo description should have \fBkmous\fR set to "\\E[M"
  297. (the beginning of the response from xterm for mouse clicks).
  298. Other values for \fBkmous\fR are permitted,
  299. but under the same assumption,
  300. i.e., it is the beginning of the response.
  301. .PP
  302. Because there are no standard terminal responses that would serve to identify
  303. terminals which support the xterm mouse protocol, \fBncurses\fR assumes that
  304. if your $TERM environment variable contains "xterm",
  305. or \fBkmous\fR is defined in
  306. the terminal description, then the terminal may send mouse events.
  307. .SH SEE ALSO
  308. \fBcurses\fR(3X),
  309. \fBcurs_kernel\fR(3X),
  310. \fBcurs_slk\fR(3X).
  311. .\"#
  312. .\"# The following sets edit modes for GNU EMACS
  313. .\"# Local Variables:
  314. .\"# mode:nroff
  315. .\"# fill-column:79
  316. .\"# End: