Debian Codegraph @

upstream/opensuse-leap-16-1/man3/mouse.3ncurses

raw
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2024,2025 Thomas E. Dickey *
4 .\" Copyright 1998-2015,2017 Free Software Foundation, Inc. *
5 .\" *
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: *
13 .\" *
14 .\" The above copyright notice and this permission notice shall be included *
15 .\" in all copies or substantial portions of the Software. *
16 .\" *
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. *
24 .\" *
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 *
28 .\" authorization. *
29 .\"***************************************************************************
30 .\"
31 .\" $Id: curs_mouse.3x,v 1.126 2025/04/05 22:08:22 tom Exp $
32 .TH mouse 3NCURSES 2025-04-05 "ncurses 6.5" "Library calls"
33 .ie \n(.g \{\
34 .ds `` \(lq
35 .ds '' \(rq
36 .\}
37 .el \{\
38 .ie t .ds `` ``
39 .el .ds `` ""
40 .ie t .ds '' ''
41 .el .ds '' ""
42 .\}
43 .
44 .de bP
45 .ie n .IP \(bu 4
46 .el .IP \(bu 2
47 ..
48 .SH NAME
49 \fB\%has_mouse\fP,
50 \fB\%getmouse\fP,
51 \fB\%ungetmouse\fP,
52 \fB\%mousemask\fP,
53 \fB\%wenclose\fP,
54 \fB\%mouse_trafo\fP,
55 \fB\%wmouse_trafo\fP,
56 \fB\%mouseinterval\fP,
57 \fB\%mmask_t\fP,
58 \fB\%MEVENT\fP \-
59 get mouse events in \fIncurses\fR
60 .SH SYNOPSIS
61 .nf
62 \fB#include <ncursesw/curses.h>
63 .PP
64 \fI/* data types */
65 \fBtypedef unsigned long mmask_t;
66 .PP
67 \fBtypedef struct {
68 \fB short id; \fI/* ID to distinguish multiple devices */
69 \fB int x, y, z; \fI/* event coordinates */
70 \fB mmask_t bstate; \fI/* button state bits */
71 \fB} MEVENT;
72 .PP
73 \fI/* functions */
74 \fBbool has_mouse(void);
75 .PP
76 \fBmmask_t mousemask(mmask_t \fInew-mask\fP, mmask_t * \fIold-mask\fP);
77 .PP
78 \fBint getmouse(MEVENT * \fIevent\fP);
79 \fBint ungetmouse(MEVENT * \fIevent\fP);
80 .PP
81 \fBbool wenclose(const WINDOW * \fIwin\fP, int \fIy\fP, int \fIx\fP);
82 .PP
83 \fBbool mouse_trafo(int * \fIpY\fP, int * \fIpX\fP, bool \fIto-screen\fP);
84 \fBbool wmouse_trafo(const WINDOW * \fIwin\fP,
85 \fBint * \fIpY\fB, int * \fIpX\fB, bool \fIto-screen\fB);
86 .PP
87 \fBint mouseinterval(int \fIerval\fB);\fR
88 .fi
89 .SH DESCRIPTION
90 .I \%ncurses
91 provides an interface to the mouse or other pointing device.
92 An application can register its interest in such events;
93 the library then exposes the availability of a mouse event via an
94 .IR "input character reading function" ":"
95 this is \fB\%wgetch\fP(3NCURSES) in the non-wide character
96 .I curses
97 API and \fB\%wget_wch\fP(3NCURSES) in the wide character API.
98 A queue distinct from that used for keyboard events
99 accumulates the details of mouse events.
100 The input character reading function
101 reports the
102 .B \%KEY_MOUSE
103 key code when a mouse event is available for collection.
104 A single mouse event queue serves all windows
105 associated with the screen.
106 .PP
107 The
108 .I \%MEVENT
109 structure describes a mouse event.
110 Its
111 .I y
112 and
113 .I x
114 coordinates are screen-,
115 not window-,
116 relative.
117 The
118 .I \%bstate
119 member has exactly one bit set indicating the event type.
120 .PP
121 .I \%ncurses
122 ignores mouse events when input is in canonical (\*(``cooked\*('') mode,
123 and produces an error beep when they occur
124 while the library simulates canonical mode in a window,
125 as with \fB\%getstr\fP(3NCURSES),
126 which expects a line feed to terminate its input loop.
127 .SS has_mouse
128 The terminal type or operating system interface
129 must support the encoding of mouse events.
130 .B \%has_mouse
131 returns
132 .B TRUE
133 if
134 .IR \%ncurses 's
135 mouse driver initialized successfully,
136 and
137 .B FALSE
138 otherwise.
139 .SS mousemask
140 Use
141 .B \%mousemask
142 to select the varieties of mouse event your application wishes to
143 receive.
144 By default,
145 .I \%ncurses
146 reports no mouse events.
147 .bP
148 The function returns an updated copy of
149 .I new-mask
150 indicating which of the specified mouse events can be reported.
151 .IP
152 If the screen is not initialized,
153 or the terminal interface does not report mouse events,
154 .B \%mousemask
155 returns 0.
156 .bP
157 If
158 .I old-mask
159 is not a null pointer,
160 .B \%mousemask
161 stores the previous value
162 of the screen's mouse event mask there.
163 .PP
164 As a side effect,
165 setting a zero mouse mask may turn off the mouse cursor;
166 setting a nonzero mask may turn it on.
167 Whether this happens is device-dependent.
168 .SS "Mouse Events"
169 Several mouse event types may be selected;
170 construct a mask by logically \*(``or\*(''-ing their values.
171 .PP
172 .TS
173 Lb Lb
174 Lb Lx.
175 Name Description
176 =
177 BUTTON1_PRESSED mouse button 1 down
178 BUTTON1_RELEASED mouse button 1 up
179 BUTTON1_CLICKED mouse button 1 clicked
180 BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
181 BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
182 _
183 BUTTON2_PRESSED mouse button 2 down
184 BUTTON2_RELEASED mouse button 2 up
185 BUTTON2_CLICKED mouse button 2 clicked
186 BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
187 BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
188 _
189 BUTTON3_PRESSED mouse button 3 down
190 BUTTON3_RELEASED mouse button 3 up
191 BUTTON3_CLICKED mouse button 3 clicked
192 BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
193 BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
194 _
195 BUTTON4_PRESSED mouse button 4 down
196 BUTTON4_RELEASED mouse button 4 up
197 BUTTON4_CLICKED mouse button 4 clicked
198 BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
199 BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
200 _
201 BUTTON5_PRESSED mouse button 5 down
202 BUTTON5_RELEASED mouse button 5 up
203 BUTTON5_CLICKED mouse button 5 clicked
204 BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked
205 BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked
206 _
207 BUTTON_SHIFT T{
208 a shift key was down during button state change
209 T}
210 BUTTON_CTRL T{
211 a control key was down during button state change
212 T}
213 BUTTON_ALT T{
214 an alt key was down during button state change
215 T}
216 ALL_MOUSE_EVENTS report all button state changes
217 REPORT_MOUSE_POSITION report mouse movement
218 _
219 .TE
220 .SS getmouse
221 Once a class of mouse events has been made visible in a window,
222 calling the input character reading function on that window may return
223 .B \%KEY_MOUSE
224 as an indicator that a mouse event is enqueued.
225 To read the event data and pop the event off the queue,
226 call
227 .BR \%getmouse ","
228 which returns
229 .B OK
230 if a mouse event is visible in the given window
231 and
232 .B ERR
233 otherwise.
234 When
235 .B \%getmouse
236 returns
237 .BR OK ","
238 it deposits data describing the mouse event in the
239 .I event
240 pointer you supply.
241 A subsequent
242 .B \%getmouse
243 call retrieves the next older event from the queue.
244 .SS ungetmouse
245 .B \%ungetmouse
246 behaves analogously to \fB\%ungetch\fP(3NCURSES).
247 It pushes a
248 .B \%KEY_MOUSE
249 event onto the screen's input queue,
250 and
251 .I event
252 onto the mouse event queue.
253 .SS wenclose
254 .B \%wenclose
255 returns
256 .B TRUE
257 if the pair of screen-relative coordinates
258 .RI ( y ,
259 .IR x ")"
260 is enclosed by the given window
261 .IR win ","
262 and
263 .B FALSE
264 otherwise.
265 If
266 .I win
267 is a pad,
268 .B \%wenclose
269 uses its most recent screen coordinates as specified in
270 a \fB\%prefresh\fP(3NCURSES) or \fB\%pnoutrefresh\fP(3NCURSES) call.
271 .PP
272 .B \%wenclose
273 is useful for determining what subset of the screen's windows
274 encloses the location of a mouse event;
275 it is otherwise independent of the
276 .I \%ncurses
277 mouse API.
278 .SS wmouse_trafo
279 .B \%wmouse_trafo
280 transforms the given pair of coordinate pointers
281 .RI ( pY ,
282 .IR pX ")"
283 from a
284 .IR win -relative
285 basis to a screen-relative one or
286 .IR "vice versa" ","
287 as
288 .I to-screen
289 is
290 .B TRUE
291 or
292 .BR FALSE ","
293 respectively.
294 .BR \%stdscr -relative
295 coordinates are not always identical to screen coordinates:
296 .I curses
297 supports reservation of screen lines at the top and/or bottom
298 for other purposes;
299 see \fB\%ripoffline\fP(3NCURSES) and \fB\%slk_init\fP(3NCURSES).
300 .PP
301 If
302 .I to-screen is
303 .B TRUE
304 and the pointers
305 .RI ( pY ,
306 .IR pX ")"
307 reference coordinates inside
308 .IR win ","
309 .I \%ncurses
310 updates their values to
311 .BR \%stdscr -relative
312 coordinates and returns
313 .BR TRUE "."
314 If either
315 .I pY
316 or
317 .I pX
318 is a null pointer,
319 or
320 .RI ( pY ,
321 .IR pX ")"
322 is not inside
323 .IR win ","
324 .B \%wmouse_trafo
325 returns
326 .BR FALSE "."
327 .PP
328 If
329 .I to-screen is
330 .B FALSE
331 and the pointers
332 .RI ( pY ,
333 .IR pX ")"
334 reference coordinates inside
335 .BR stdscr ","
336 .I \%ncurses
337 updates their values to
338 .IR win -relative
339 coordinates and returns
340 .BR TRUE "."
341 If either
342 .I pY
343 or
344 .I pX
345 is a null pointer,
346 or
347 .RI ( pY ,
348 .IR pX ")"
349 is not inside
350 .BR stdscr ","
351 .B \%wmouse_trafo
352 returns
353 .BR FALSE "."
354 .SS mouse_trafo
355 .B \%mouse_trafo
356 applies the
357 .B \%wmouse_trafo
358 translation to
359 .BR \%stdscr "."
360 If no screen lines are reserved by \fB\%ripoffline\fP(3NCURSES) or
361 \fB\%slk_init\fP(3NCURSES),
362 this is the identity transformation.
363 .SS mouseinterval
364 .B \%mouseinterval
365 sets the maximum time
366 (in thousandths of a second)
367 that can elapse between press and release events for them to
368 be resolved as a
369 .IR click .
370 An application might interpret button press and release events separated
371 by more than the mouse interval as a \*(``long press\*('',
372 or,
373 with motion,
374 as a \*(``drag\*(''.
375 .PP
376 When
377 .I \%ncurses
378 detects a mouse event,
379 it awaits further input activity up to this interval,
380 and then checks for a subsequent mouse event which can be combined
381 with the first event.
382 If the timeout expires without input activity,
383 then no click resolution occurs.
384 Calling
385 .B \%mouseinterval(0)
386 disables click resolution.
387 .PP
388 .B \%mouseinterval
389 returns the previous interval value.
390 Use
391 .B \%mouseinterval(\-1)
392 to obtain the interval without altering it.
393 .PP
394 The mouse interval is set to one sixth of a second
395 when the corresponding screen is initialized,
396 e.g., in \fBinitscr\fP(3NCURSES) or \fBsetupterm\fP(3NCURSES).
397 .SH RETURN VALUE
398 .BR \%has_mouse ","
399 .BR \%wenclose ","
400 .BR \%mouse_trafo ","
401 and
402 .B \%wmouse_trafo
403 return
404 .B TRUE
405 or
406 .B FALSE
407 as noted above.
408 .PP
409 .B \%getmouse
410 and
411 .B \%ungetmouse
412 return
413 .B ERR
414 upon failure and
415 .B OK
416 upon success.
417 .PP
418 .B \%getmouse
419 fails if:
420 .bP
421 no mouse driver was initialized,
422 .bP
423 the mask of reportable events is zero,
424 .bP
425 a mouse event was detected that does not match the mask,
426 or
427 .bP
428 no more events remain in the queue.
429 .PP
430 .B \%ungetmouse
431 returns
432 .B ERR
433 if the event queue is full.
434 .PP
435 .B \%mousemask
436 returns the mask of reportable events.
437 .PP
438 .B \%mouseinterval
439 returns the previous interval value, unless
440 the terminal was not initialized.
441 In that case, it returns the maximum interval value (166).
442 .SH NOTES
443 The order of the
444 .B \%MEVENT
445 structure members is not guaranteed.
446 Additional fields may be added to the structure in the future.
447 .PP
448 Under
449 .IR \%ncurses ,
450 these calls are implemented using either
451 .IR \%xterm 's
452 built-in mouse-tracking API or
453 platform-specific drivers including
454 .RS 3
455 .bP
456 Alessandro Rubini's gpm server
457 .bP
458 FreeBSD sysmouse
459 .bP
460 OS/2 EMX
461 .RE
462 .PP
463 If you are using an unsupported configuration,
464 mouse events are not visible to
465 .I \%ncurses
466 (and the
467 .B \%mousemask
468 function always returns
469 .BR 0 ")."
470 .PP
471 If the terminal type possesses the (nonstandard)
472 .I \%term\%info
473 string capability
474 .BR XM ","
475 .IR \%ncurses "'s"
476 .I \%xterm
477 mouse driver uses it when initializing the terminal for mouse operation.
478 The default,
479 if
480 .B XM
481 is not found,
482 corresponds to private mode 1000 of
483 .IR \%xterm "."
484 .PP
485 .RS 3
486 .EX
487 \eE[?1000%?%p1%{1}%=%th%el%;
488 .EE
489 .RE
490 .PP
491 .I \%ncurses
492 also recognizes
493 .IR \%xterm 's
494 newer private mode 1006.
495 .PP
496 .RS 3
497 .EX
498 \eE[?1006;1000%?%p1%{1}%=%th%el%;
499 .EE
500 .RE
501 .PP
502 The
503 .I id
504 member of the mouse event structure is not presently used;
505 no terminal type or operating system interface supports reporting events
506 from distinguishable pointing devices.
507 If you synthesize an
508 .IR \%MEVENT ","
509 use an
510 .I id
511 of 0.
512 .PP
513 The
514 .I z
515 member of the mouse event structure is not presently used.
516 It is intended
517 for use with touch screens (which may be pressure-sensitive) or with
518 3D-mice/trackballs/power gloves.
519 .PP
520 The
521 .B \%ALL_MOUSE_EVENTS
522 class does not include
523 .BR \%REPORT_MOUSE_POSITION "."
524 They are distinct.
525 For example,
526 in
527 .IR \%xterm ,
528 wheel/scrolling mice send position reports as a sequence of
529 presses of buttons 4 or 5 without matching button-releases.
530 .SH EXTENSIONS
531 These functions are
532 .I \%ncurses
533 extensions,
534 and are not found in SVr4
535 .IR curses ,
536 4.4BSD
537 .IR curses ,
538 or any other previous
539 .I curses
540 implementation.
541 (SVr4
542 .I curses
543 did have a
544 .I \%getmouse
545 function,
546 which took no argument and returned an
547 .IR "unsigned long" ".)"
548 .SH PORTABILITY
549 Applications employing the
550 .I \%ncurses
551 mouse extension should condition its use on the visibility of the
552 .B \%NCURSES_MOUSE_VERSION
553 preprocessor macro.
554 When the interface changes,
555 the macro's value increments.
556 Multiple versions are available when
557 .I \%ncurses
558 is configured;
559 see section \*(``ALTERNATE CONFIGURATIONS\*('' of \fB\%ncurses\fP(3NCURSES).
560 The following values may be specified.
561 .RS 3
562 .TP 3
563 .B 1
564 has definitions for reserved events.
565 The mask uses 28 bits.
566 .TP 3
567 .B 2
568 adds definitions for button 5,
569 removes the definitions for reserved events.
570 The mask uses 29 bits.
571 .RE
572 .SH HISTORY
573 SVr4 (1989) added mouse support to its variant of \fI\%xterm\fP(1).
574 It is mentioned in a few places,
575 with little supporting documentation.
576 .bP
577 Its \*(``libcurses\*('' manual page lists functions for this feature
578 prototyped in
579 .IR \%curses.h "."
580 .PP
581 .RS 8
582 .EX
583 .nf
584 extern int mouse_set(long int);
585 extern int mouse_on(long int);
586 extern int mouse_off(long int);
587 extern int request_mouse_pos(void);
588 extern int map_button(unsigned long);
589 extern void wmouse_position(WINDOW *, int *, int *);
590 extern unsigned long getmouse(void), getbmap(void);
591 .fi
592 .EE
593 .RE
594 .bP
595 Its \*(``terminfo\*('' manual page lists capabilities for the feature.
596 .PP
597 .\" These don't appear in the SVID 4th edition, Volume 3,
598 .\" terminfo(TI_ENV) man page. They can be found in, e.g., the "z/OS
599 .\" V1R1.0 C Curses" book, Chapter 17, pp. 179-186 (PDF 213-220).
600 .RS 8
601 .TS
602 Lb Lb Lb Lx.
603 buttons btns BT T{
604 Number of buttons on the mouse
605 T}
606 get_mouse getm Gm T{
607 Curses should get button events
608 T}
609 key_mouse kmous Km T{
610 0631, Mouse event has occurred
611 T}
612 mouse_info minfo Mi T{
613 Mouse status information
614 T}
615 req_mouse_pos reqmp RQ T{
616 Request mouse position report
617 T}
618 .TE
619 .RE
620 .bP
621 The interface made assumptions
622 (as does
623 .IR \%ncurses )
624 about the escape sequences sent to and received from the terminal.
625 .IP
626 For instance,
627 the SVr4
628 .I curses
629 library used the
630 .B \%get_mouse
631 .RB ( getm )
632 capability to tell the terminal which
633 mouse button events it should send,
634 passing the mouse-button bit mask to the terminal.
635 Also, it could ask the terminal
636 where the mouse was using the
637 .B \%req_mouse_pos
638 .RB ( reqmp )
639 capability.
640 .IP
641 Those features required a terminal program that had been modified
642 to work with SVr4
643 .IR curses .
644 They were not part of the X Consortium's
645 .IR \%xterm .
646 .PP
647 When developing the
648 .I \%xterm
649 mouse support for
650 .I \%ncurses
651 in September 1995,
652 Eric Raymond was uninterested in using the same interface due to its
653 lack of documentation.
654 Later, in 1998, Mark Hesseling provided support in
655 .I \%PDCurses
656 2.3 using the SVr4 interface.
657 .IR \%PDCurses ,
658 however,
659 does not use video terminals,
660 making it unnecessary to be concerned about compatibility with the
661 escape sequences.
662 .SH BUGS
663 Mouse events from
664 .I \%xterm
665 are
666 .I not
667 ignored in canonical (\*(``cooked\*('') mode
668 if they have been enabled by
669 .BR \%mousemask "."
670 Instead,
671 the
672 .I \%xterm
673 mouse report sequence appears in the string read.
674 .PP
675 An
676 .I \%ncurses
677 window must enable \fB\%keypad\fP(3NCURSES) to correctly receive mouse event
678 reports from
679 .I \%xterm
680 since they are encoded like function keys.
681 Set the terminal's
682 .I \%term\%info
683 capability
684 .B \%key_mouse
685 .RB ( \%kmous )
686 to \*(``\eE[M\*(''
687 (the beginning of the response from
688 .I \%xterm
689 for mouse clicks).
690 Other values of
691 .B \%key_mouse
692 are permitted under the same assumption \(em
693 that is,
694 a mouse report begins with the value of the
695 .B \%key_mouse
696 .RB ( \%kmous )
697 string capability.
698 .PP
699 Because there are no standard response sequences that serve to identify
700 terminals supporting the
701 .I \%xterm
702 mouse protocol,
703 .I \%ncurses
704 assumes that if
705 .B \%key_mouse
706 .RB ( \%kmous )
707 is defined in the terminal description,
708 or if the terminal type's primary name or aliases contain the string
709 \%\*(``xterm\*('',
710 then the terminal may send mouse events.
711 .I \%ncurses
712 checks the
713 .B \%kmous
714 cap-code first,
715 allowing use of newer
716 .I \%xterm
717 mouse protocols,
718 such as its private mode 1006.
719 .SH SEE ALSO
720 \fB\%ncurses\fP(3NCURSES),
721 \fB\%inopts\fP(3NCURSES),
722 \fB\%kernel\fP(3NCURSES),
723 \fB\%pad\fP(3NCURSES),
724 \fB\%slk\fP(3NCURSES),
725 \fB\%curses_variables\fP(3NCURSES)