.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "notcurses_input" "3" "v3.0.0" "" "" .hy .SH NAME .PP notcurses_input - input via notcurses .SH SYNOPSIS .PP \f[B]#include \f[R] .IP .nf \f[C] struct timespec; struct notcurses; typedef struct ncinput { uint32_t id; // Unicode codepoint int y; // Y cell coordinate of event, -1 for undefined int x; // X cell coordinate of event, -1 for undefined char utf8[5]; // utf8 representation, when one exists bool alt; // Was Alt held during the event? bool shift; // Was Shift held during the event? bool ctrl; // Was Ctrl held during the event? enum { EVTYPE_UNKNOWN, EVTYPE_PRESS, EVTYPE_REPEAT, EVTYPE_RELEASE, } evtype; int ypx, xpx; // pixel offsets within cell, -1 for undefined } ncinput; #define NCMICE_NO_EVENTS 0 #define NCMICE_MOVE_EVENT 0x1 #define NCMICE_BUTTON_EVENT 0x2 #define NCMICE_DRAG_EVENT 0x4 #define NCMICE_ALL_EVENTS 0x7 \f[R] .fi .PP \f[B]bool nckey_mouse_p(uint32_t \f[R]\f[I]r\f[R]\f[B]);\f[R] .PP \f[B]bool ncinput_nomod_p(const ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]uint32_t notcurses_get(struct notcurses* \f[R]\f[I]n\f[R]\f[B], const struct timespec* \f[R]\f[I]ts\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_getvec(struct notcurses* \f[R]\f[I]n\f[R]\f[B], const struct timespec* \f[R]\f[I]ts\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B], int vcount);\f[R] .PP \f[B]uint32_t notcurses_get_nblock(struct notcurses* \f[R]\f[I]n\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]uint32_t notcurses_get_blocking(struct notcurses* \f[R]\f[I]n\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]int cnotcurses_mice_enable(struct notcurses* \f[R]\f[I]n\f[R]\f[B], unsigned \f[R]\f[I]eventmask\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_mice_disable(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_inputready_fd(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .PP \f[B]static inline bool ncinput_equal_p(const ncinput* \f[R]\f[I]n1\f[R]\f[B], const ncinput* \f[R]\f[I]n2\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_linesigs_disable(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_linesigs_enable(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .SH DESCRIPTION .PP notcurses supports input from keyboards and mice, and any device that looks like them. Mouse support requires a broker such as GPM, Wayland, or Xorg, and must be explicitly enabled via \f[B]notcurses_mice_enable\f[R]. The full 32-bit range of Unicode is supported (see \f[B]unicode(7)\f[R]), with synthesized events mapped above the 1,114,112 codepoints of Unicode 14.0\[aq]s seventeen Planes. Unicode characters are returned directly as UCS-32, one codepoint at a time. When the input has a UTF8 representation, it is written to \f[B]utf8\f[R]; this field is always NUL-terminated. .PP notcurses takes its keyboard input from \f[B]stdin\f[R], which will be placed into non-blocking mode for the duration of operation. The terminal is put into non-canonical mode (see \f[B]termios(3)\f[R]), and thus keys are received without line-buffering. notcurses maintains its own buffer of input characters, which it will attempt to fill whenever it reads. .PP \f[B]notcurses_get\f[R] allows a \f[B]struct timespec\f[R] to be specified as a timeout. If \f[B]\f[BI]ts\f[B]\f[R] is \f[B]NULL\f[R], \f[B]notcurses_get\f[R] will block until it reads input, or is interrupted by a signal. If its values are zeroes, there will be no blocking. Otherwise, \f[B]\f[BI]ts\f[B]\f[R] specifies an absolute deadline (taken against \f[B]CLOCK_MONOTONIC\f[R]; see \f[B]clock_gettime(2)\f[R]). On timeout, 0 is returned. Event details will be reported in \f[B]\f[BI]ni\f[B]\f[R], unless \f[B]\f[BI]ni\f[B]\f[R] is NULL. .PP \f[B]notcurses_inputready_fd\f[R] provides a file descriptor suitable for use with I/O multiplexors such as \f[B]poll(2)\f[R]. This file descriptor might or might not be the actual input file descriptor. If it readable, \f[B]notcurses_get\f[R] can be called without the possibility of blocking. .PP \f[B]ncinput_equal_p\f[R] compares two \f[B]ncinput\f[R] structs for data equality (i.e. not considering padding), returning \f[B]true\f[R] if they represent the same input (though not necessarily the same input event). .PP \f[B]notcurses_linesigs_disable\f[R] disables conversion of inputs \f[B]INTR\f[R], \f[B]QUIT\f[R], \f[B]SUSP\f[R], and \f[B]DSUSP\f[R] into \f[B]SIGINT\f[R], \f[B]SIGQUIT\f[R], and \f[B]SIGTSTP\f[R]. These conversions are enabled by default. \f[B]notcurses_linesigs_enable\f[R] undoes this action, but signals in the interim are permanently lost. .SS Mice .PP For mouse events, the additional fields \f[B]\f[BI]y\f[B]\f[R], \f[B]\f[BI]x\f[B]\f[R], \f[B]\f[BI]ypx\f[B]\f[R], and \f[B]\f[BI]xpx\f[B]\f[R] are set. These fields are not meaningful for keypress events. Mouse events can be distinguished using the \f[B]nckey_mouse_p\f[R] predicate. \f[B]NCMICE_MOVE_EVENT\f[R] requests events whenever the mouse moves when no buttons are held down. \f[B]NCMICE_DRAG_EVENT\f[R] requests events when the mouse is moving with buttons held down. \f[B]NCMICE_BUTTON_EVENT\f[R] requests events then the button state changes. \f[B]NCMICE_ALL_EVENTS\f[R] is provided for convenience and future-proofing against API (though not ABI) changes. .SS Synthesized keypresses .PP Many keys do not have a Unicode representation, let alone ASCII. Examples include the modifier keys (Alt, Meta, etc.), the \[dq]function\[dq] keys, and the arrow keys on the numeric keypad. The special keys available to the terminal are defined in the \f[B]terminfo(5)\f[R] entry, which notcurses loads on startup. Upon receiving an escape code matching a terminfo input capability, notcurses synthesizes a special value. An escape sequence must arrive in its entirety to notcurses; running out of input in the middle of an escape sequence will see it rejected. Likewise, any error while handling an escape sequence will see the lex aborted, and the sequence thus far played back as independent literal keystrokes. .PP The full list of synthesized keys (there are well over one hundred) can be found in \f[B]\f[R]. For more details, consult \f[B]terminfo(5)\f[R]. .SS \f[B]NCKEY_RESIZE\f[R] .PP Unless the \f[B]SIGWINCH\f[R] handler has been inhibited (see \f[B]notcurses_init\f[R]), Notcurses will automatically catch screen resizes, and synthesize an \f[B]NCKEY_RESIZE\f[R] event. Upon receiving this event, the user may call \f[B]notcurses_refresh\f[R] to force an immediate reflow, or just wait until the next call to \f[B]notcurses_render\f[R], when notcurses will pick up the resize itself. If the \f[B]SIGWINCH\f[R] handler is inhibited, \f[B]NCKEY_RESIZE\f[R] is never generated. .SS \f[B]NCKEY_SIGNAL\f[R] .PP Unless the \f[B]SIGWINCH\f[R] handler has been inhibited (see \f[B]notcurses_init\f[R]), Notcurses will catch \f[B]SIGCONT\f[R], and synthesize an \f[B]NCKEY_SIGNAL\f[R] event. This typically indicates that the program has been restarted after being paused or placed in the background. The next rasterization will be a full rebuild of the screen, as if \f[B]notcurses_refresh\f[R] had been called; the user might wish to immediately call \f[B]notcurses_refresh\f[R] themselves. .SS \f[B]NCKEY_EOF\f[R] .PP Upon reaching the end of input, \f[B]NCKEY_EOF\f[R] will be returned. At this point, any further calls will immediately return \f[B]NCKEY_EOF\f[R]. Note that this does not necessarily result from pressing e.g. Ctrl+D. .SH RETURN VALUES .PP On error, the \f[B]get\f[R] family of functions return \f[B](uint32_t)-1\f[R]. The cause of the error may be determined using \f[B]errno(3)\f[R]. Unless the error was a temporary one (especially e.g. \f[B]EINTR\f[R]), \f[B]notcurses_get\f[R] probably cannot be usefully called forthwith. On a timeout, 0 is returned. Otherwise, the UCS-32 value of a Unicode codepoint, or a synthesized event, is returned. .PP If an error is encountered before \f[B]notcurses_getvec\f[R] has read any input, it will return -1. If it times out before reading any input, it will return 0. Otherwise, it returns the number of \f[B]ncinput\f[R] objects written back. .PP \f[B]notcurses_mice_enable\f[R] returns 0 on success, and non-zero on failure, as does \f[B]notcurses_mice_disable\f[R]. Success does not necessarily mean that a mouse is available nor that all requested events will be generated. .PP \f[B]ncinput_equal_p\f[R] returns \f[B]true\f[R] if the two \f[B]ncinput\f[R] structs represent the same input (though not necessarily the same input event), and \f[B]false\f[R] otherwise. .SH NOTES .PP Like any other notcurses function, it is an error to call \f[B]notcurses_get\f[R] during or after a call to \f[B]notcurses_stop\f[R]. If a thread is always sitting on blocking input, it can be tricky to guarantee that this doesn\[aq]t happen. .PP Only one thread may call into the input stack at once, but unlike almost every other function in notcurses, \f[B]notcurses_get\f[R] and friends can be called concurrently with \f[B]notcurses_render\f[R]. .PP Do not simply \f[B]poll\f[R] the file descriptor associated with \f[B]stdin\f[R] to test for input readiness. Instead, use the file descriptor returned by \f[B]notcurses_inputready_fd\f[R] to ensure compatibility with future versions of Notcurses (it is possible that future versions will process input in their own contexts). .PP When support is detected, the Kitty keyboard disambiguation protocol will be requested. This eliminates most of the \f[B]BUGS\f[R] mentioned below. .PP The full list of synthesized events is available in \f[B]\f[R]. .SH BUGS .PP The Shift key is not indicated in conjunction with typical Unicode text. If e.g. Shift is used to generate a capital letter \[aq]A\[aq], \f[B]\f[BI]id\f[B]\f[R] will equal \[aq]A\[aq], and \f[B]\f[BI]shift\f[B]\f[R] will be \f[B]false\f[R]. Similarly, when Ctrl is pressed along with a letter, the letter will currently always be reported in its uppercase form. E.g., if Shift, Ctrl, and \[aq]a\[aq] are all pressed, this is indistinguishable from Ctrl and \[aq]A\[aq]. .PP Ctrl pressed along with \[aq]J\[aq] or \[aq]M\[aq], whether Shift is pressed or not, currently registers as \f[B]NCKEY_ENTER\f[R]. This will likely change in the future. .PP When the Kitty keyboard disambiguation protocol is used, most of these issues are resolved. You can determine whether the protocol is in use by examining the output of \f[B]notcurses-info(1)\f[R]. If the \f[B]kbd\f[R] property is indicated, you\[aq]re using the Kitty protocol. .PP Mouse events in the left margins will never be delivered to the application (as is intended), but mouse events in the bottom and right margins sometimes can be if the event occurs prior to a window resize. .PP The \f[B]\f[BI]ypx\f[B]\f[R] and \f[B]\f[BI]xpx\f[B]\f[R] fields are never currently valid (i.e. they are always -1). This ought be fixed in the future using the SGR PixelMode mouse protocol. .PP On some operating systems, \f[B]CLOCK_REALTIME\f[R] is used as the basis for timeouts instead of \f[B]CLOCK_MONOTONIC\f[R]. This ought be fixed. .SH SEE ALSO .PP \f[B]notcurses-info(1)\f[R], \f[B]clock_gettime(2)\f[R], \f[B]poll(2)\f[R], \f[B]notcurses(3)\f[R], \f[B]notcurses_refresh(3)\f[R], \f[B]notcurses_render(3)\f[R], \f[B]termios(3)\f[R], \f[B]terminfo(5)\f[R], \f[B]ascii(7)\f[R], \f[B]signal(7)\f[R], \f[B]unicode(7)\f[R] .SH AUTHORS nick black .