2
3
4
5
6
7
12#include <notcurses/notcurses.h>
18
19
21
22
23
24
25static UiKey translate_nckey(uint32_t id,
const ncinput *ni) {
26 if (id == NCKEY_INVALID || id == (uint32_t)NCKEY_EOF)
30 if (nckey_mouse_p(id))
89 if (ni && ni->evtype == NCTYPE_UNKNOWN)
92 if (id >= 0x20 && id < NCKEY_INVALID)
99
100
103
104
106 int fd = notcurses_inputready_fd(
ui->nc);
107 tcflush(fd, TCIOFLUSH);
111
112
113
114
115
116
117int ui_get_event(UiSurface *s, ss_t w, UiChyron *chyron, UiEvent *ev,
int timeout_ms) {
120 memset(ev, 0,
sizeof(*ev));
122 memset(&ni, 0,
sizeof(ni));
127 if (timeout_ms > 1) {
134 memset(fds, 0,
sizeof(fds));
135 fds[0].fd = notcurses_inputready_fd(
ui->nc);
136 fds[0].events = POLLIN;
138 nfds_t ext_start_idx = nfds;
141 fds[nfds].events = POLLIN;
144 int poll_rc = poll(fds, nfds, timeout_ms);
154 bool ui_ready = (fds[0].revents & POLLIN);
156 for (nfds_t i = ext_start_idx; i < nfds; i++) {
157 if (fds[i].revents & (POLLIN | POLLHUP | POLLERR)) {
158 reg_idx = i - ext_start_idx;
167 memset(ev, 0,
sizeof(*ev));
169 if (timeout_ms < 0) {
171 notcurses_get_blocking(
ui->nc, &ni);
172 }
while (ni.evtype == NCTYPE_RELEASE ||
173 ni.id == NCKEY_INVALID || ni.id == NCKEY_MOTION || ni.id == NCKEY_SIGNAL);
175 struct timespec ts = {
176 .tv_sec = timeout_ms / 1000,
177 .tv_nsec = (
long)(timeout_ms % 1000) * 1000000L,
180 notcurses_get(
ui->nc, &ts, &ni);
181 }
while (ni.evtype == NCTYPE_RELEASE || ni.id == NCKEY_MOTION || ni.id == NCKEY_INVALID);
183 ev
->key = translate_nckey(ni.id, &ni);
184 ev
->alt = ncinput_alt_p(&ni);
185 ev
->ctrl = ncinput_ctrl_p(&ni);
186 ev
->shift = ncinput_shift_p(&ni);
190 if (ni.id == NCKEY_BUTTON4)
192 else if (ni.id == NCKEY_BUTTON5)
194 else if (ni.id == NCKEY_BUTTON1 && ni.evtype == NCTYPE_PRESS) {
196 struct ncplane *clicked = ui_ncplane_clicked(s, w, &ni);
199 ev
->in_win = ui_get_plane_idx(s, clicked);
201 if (ev
->in_win == chyron->w && ev
->y == chyron->y) {
220
221
227 notcurses_get(
ui->nc, NULL, &ni);
228 }
while (ni.evtype == NCTYPE_RELEASE ||
229 ni.id == NCKEY_INVALID ||
230 ni.id == NCKEY_MOTION ||
231 ni.id == NCKEY_SIGNAL);
235
236
237
238
244 memset(ev, 0,
sizeof(*ev));
246 notcurses_mice_disable(
ui->nc);
248 notcurses_get(
ui->nc, NULL, &ni);
249 }
while (ni.id == NCKEY_INVALID);
250 ev
->key = translate_nckey(ni.id, &ni);
251 ev
->alt = ncinput_alt_p(&ni);
252 ev
->ctrl = ncinput_ctrl_p(&ni);
253 ev
->shift = ncinput_shift_p(&ni);
259
260
261
262
265 if (s->mplane[w] == plane)
271
272
273
274
275
277 NcPlane *pile_member = s->mplane[w];
278 struct ncplane *cur = ncpile_top(pile_member);
279 while (cur != NULL) {
280 int y = ni->y, x = ni->x;
281 if (ncplane_translate_abs(cur, &y, &x)) {
286 cur = ncplane_below(cur);
294
295
296
301 notcurses_mice_enable(
ui->nc, mask);
303 notcurses_mice_enable(
ui->nc, NCMICE_BUTTON_EVENT);
307
308
309
312 notcurses_mice_enable(
ui->nc, mask);
314 notcurses_mice_enable(
ui->nc, NCMICE_BUTTON_EVENT);
void ui_render()
Render the UI by updating panels and refreshing the display.
int ui_mice_enable(int mask)
Enable or disable mouse support.
int ui_get_event_no_mouse(UiSurface *surface, ss_t w, UiEvent *ev)
Wait for an input event on target (or stdscr if NULL) without mouse support.
int ui_getch()
Wait for a single input character from the NotCurses context.
int ui_mousemask(int mask)
Enable or disable mouse support.
#define UIKEY_BUTTON1_PRESSED
#define UIKEY_BUTTON1_CLICKED
#define UIKEY_SCROLL_DOWN
void ui_flush_input()
Flush any pending input events from the NotCurses context. This function discards any input events th...
int ui_get_event(UiSurface *s, ss_t w, UiChyron *chyron, UiEvent *ev, int timeout_ms)
Read input events.
int ui_get_chyron_key(UiChyron *chyron, uint x)
Get keycode from chyron.
NcPlane * ui_ncplane_clicked(UiSurface *s, ss_t w, ncinput *ni)
Determine which ncplane was clicked based on the mouse event coordinates.
uint ui_get_plane_idx(UiSurface *s, struct ncplane *plane)
Get the index of a given ncplane in the UiSurface's plane array.
UiMouseAction mouse_action
ext_fd_reg_t ext_fds[MAX_EXT_FDS]