C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_notcurses_input.c File Reference

NotCurses UI backend — input handling. More...

#include "ui_backend.h"
#include "ui_notcurses_internal.h"
#include <notcurses/notcurses.h>
#include <string.h>
#include <termios.h>
Include dependency graph for ui_notcurses_input.c:

Go to the source code of this file.

Functions

uint get_plane_idx (UiSurface *s, struct ncplane *plane)
NcPlanencplane_clicked (UiSurface *s, uint w, ncinput *ni)
int ui_get_event (UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
 Wait for an input event from the NotCurses context.
int ui_get_event_multi (UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
int ui_get_event_multix (UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
int ui_get_event_no_mouse (UiSurface *target, uint w, UiEvent *ev)
int ui_getch ()

Detailed Description

NotCurses UI backend — input handling.

Translates NotCurses ncinput events into the portable UiEvent representation defined in ui_backend.h.

Definition in file ui_notcurses_input.c.

Function Documentation

◆ get_plane_idx()

uint get_plane_idx ( UiSurface * s,
struct ncplane * plane )

Definition at line 249 of file ui_notcurses_input.c.

249 {
250 if (!s)
251 return -1;
252 for (uint w = 0; w < SUB_SFC_MAX; ++w) {
253 if (s->mplane[w] == plane)
254 return w;
255 }
256 return -1;
257}
struct ncplane * mplane[SUB_SFC_MAX]

References SUB_SFC_MAX.

Referenced by ui_get_event_multi().

Here is the caller graph for this function:

◆ ncplane_clicked()

NcPlane * ncplane_clicked ( UiSurface * s,
uint w,
ncinput * ni )

Definition at line 259 of file ui_notcurses_input.c.

259 {
260 NcPlane *pile_member = s->mplane[w];
261 struct ncplane *cur = ncpile_top(pile_member);
262 while (cur != NULL) {
263 int y = ni->y, x = ni->x;
264 if (ncplane_translate_abs(cur, &y, &x)) {
265 ni->y = y;
266 ni->x = x;
267 return cur;
268 }
269 cur = ncplane_below(cur);
270 }
271 return NULL;
272}
struct ncplane NcPlane
Definition ui_backend.h:251

◆ ui_get_event()

int ui_get_event ( UiSurface * s,
uint w,
UiEvent * ev,
int timeout_ms )

Wait for an input event from the NotCurses context.

Wait for an input event on target (or stdscr if NULL).

Parameters
uiUI runtime context.
targetUnused for NotCurses (events are global to the context).
evOutput UiEvent structure.
timeout_msMilliseconds to wait; -1 = block indefinitely.
Returns
0 on success, -1 if ui or ev is NULL.

Definition at line 104 of file ui_notcurses_input.c.

104 {
105 if (!ui || !ev)
106 return -1;
107 memset(ev, 0, sizeof(*ev));
108
109 ncinput ni;
110 // ui_cursor_enable(s, w, true);
111 // tcflush(0, TCIFLUSH);
112 if (timeout_ms < 0) {
113 do {
114 // notcurses_get(ui->nc, NULL, &ni);
115 notcurses_get_blocking(ui->nc, &ni);
116 } while (ni.evtype == NCTYPE_RELEASE ||
117 ni.id == NCKEY_INVALID ||
118 ni.id == NCKEY_MOTION ||
119 ni.id == NCKEY_SIGNAL);
120 } else {
121 struct timespec ts = {
122 .tv_sec = timeout_ms / 1000,
123 .tv_nsec = (long)(timeout_ms % 1000) * 1000000L,
124 };
125 do {
126 notcurses_get(ui->nc, &ts, &ni);
127 } while (ni.evtype == NCTYPE_RELEASE || ni.id == NCKEY_INVALID);
128 }
129 // notcurses_cursor_disable(ui->nc);
130 ev->key = translate_nckey(ni.id, &ni);
131 ev->alt = ncinput_alt_p(&ni);
132 ev->ctrl = ncinput_ctrl_p(&ni);
133 ev->shift = ncinput_shift_p(&ni);
134 if (ev->key == UI_KEY_CHAR) {
135 ev->ch = ni.id; /* Unicode codepoint */
136 } else if (ev->key == UI_KEY_MOUSE) {
137 ev->y = ni.y;
138 ev->x = ni.x;
139 if (ni.id == NCKEY_BUTTON4)
141 else if (ni.id == NCKEY_BUTTON5)
143 else if (ni.evtype == NCTYPE_PRESS)
145 else if (ni.evtype == NCTYPE_RELEASE)
147 }
148 return ni.id;
149}
@ UI_KEY_CHAR
Definition ui_backend.h:44
@ UI_KEY_MOUSE
Definition ui_backend.h:61
UiRuntime * ui
@ UI_MOUSE_SCROLL_DOWN
Definition ui_backend.h:82
@ UI_MOUSE_PRESS
Definition ui_backend.h:78
@ UI_MOUSE_SCROLL_UP
Definition ui_backend.h:81
@ UI_MOUSE_RELEASE
Definition ui_backend.h:79
uint32_t ch
Definition ui_backend.h:102
UiMouseAction mouse_action
Definition ui_backend.h:112
bool shift
Definition ui_backend.h:105
bool ctrl
Definition ui_backend.h:104
UiKey key
Definition ui_backend.h:101
bool alt
Definition ui_backend.h:103

References UiEvent::alt, UiEvent::bstate, UiEvent::ch, UiEvent::ctrl, UiEvent::key, UiEvent::mouse_action, UiEvent::mouse_inside, UiRuntime::nc, UiEvent::shift, ui, UI_KEY_CHAR, UI_KEY_MOUSE, UI_MOUSE_PRESS, UI_MOUSE_RELEASE, UI_MOUSE_SCROLL_DOWN, UI_MOUSE_SCROLL_UP, UiEvent::x, and UiEvent::y.

Referenced by action_disposition(), answer_yn(), cf_accept(), display_error(), menu_cmd_processor(), notcurses_input(), and Perror().

Here is the caller graph for this function:

◆ ui_get_event_multi()

int ui_get_event_multi ( UiSurface * s,
uint w,
UiEvent * ev,
int timeout_ms )

Definition at line 181 of file ui_notcurses_input.c.

181 {
182 if (!ui || !ev)
183 return -1;
184 memset(ev, 0, sizeof(*ev));
185 ncinput ni;
186 if (timeout_ms < 0)
187 do {
188 notcurses_get(ui->nc, NULL, &ni);
189 } while (ni.evtype == NCTYPE_RELEASE ||
190 ni.id == NCKEY_INVALID ||
191 ni.id == NCKEY_MOTION ||
192 ni.id == NCKEY_SIGNAL);
193 else {
194 struct timespec ts = {
195 .tv_sec = timeout_ms / 1000,
196 .tv_nsec = (long)(timeout_ms % 1000) * 1000000L,
197 };
198 do {
199 notcurses_get(ui->nc, &ts, &ni);
200 } while (ni.evtype == NCTYPE_RELEASE || ni.id == NCKEY_INVALID);
201 }
202 // notcurses_cursor_disable(ui->nc);
203 ev->key = translate_nckey(ni.id, &ni);
204 ev->alt = ncinput_alt_p(&ni);
205 ev->ctrl = ncinput_ctrl_p(&ni);
206 ev->shift = ncinput_shift_p(&ni);
207 if (ev->key == UI_KEY_CHAR) {
208 ev->ch = ni.id; /* Unicode codepoint */
209 } else if (ev->key == UI_KEY_MOUSE) {
210 if (ni.id == NCKEY_BUTTON1) {
211 struct ncplane *nn = ncplane_clicked(s, w, &ni);
212 ev->in_win = get_plane_idx(s, nn);
213 ev->key = 0;
214 }
215 }
216 ev->y = ni.y;
217 ev->x = ni.x;
218 if (ni.id == NCKEY_BUTTON4)
220 else if (ni.id == NCKEY_BUTTON5)
222 else if (ni.evtype == NCTYPE_PRESS)
224 else if (ni.evtype == NCTYPE_RELEASE)
226 return ni.id;
227}
NcPlane * ncplane_clicked(UiSurface *s, uint w, ncinput *ni)
uint get_plane_idx(UiSurface *s, struct ncplane *plane)
uint in_win
Definition ui_backend.h:110

References UiEvent::alt, UiEvent::bstate, UiEvent::ch, UiEvent::chyron, UiEvent::ctrl, get_plane_idx(), UiEvent::in_win, UiEvent::key, UiEvent::mouse_action, UiRuntime::nc, ncplane_clicked(), UiEvent::shift, SUB_SFC_MAX, ui, UI_KEY_CHAR, UI_KEY_MOUSE, UI_MOUSE_NONE, UI_MOUSE_PRESS, UI_MOUSE_RELEASE, UI_MOUSE_SCROLL_DOWN, UI_MOUSE_SCROLL_UP, WIN, UiEvent::x, and UiEvent::y.

Referenced by field_editor(), form_post(), form_process(), and picker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_get_event_multix()

int ui_get_event_multix ( UiSurface * s,
uint w,
UiEvent * ev,
int timeout_ms )

Definition at line 164 of file ui_notcurses_input.c.

164 {
165 (void)timeout_ms;
166 (void)ev;
167 (void)w;
168 (void)s;
169 if (!ui)
170 return -1;
171 ncinput ni;
172 do {
173 // notcurses_get_blocking(ui->nc, &ni);
174 notcurses_get(ui->nc, NULL, &ni);
175 } while (ni.evtype == NCTYPE_RELEASE ||
176 ni.id == NCKEY_INVALID ||
177 ni.id == NCKEY_MOTION ||
178 ni.id == NCKEY_SIGNAL);
179 return ni.id;
180}

References UiRuntime::nc, and ui.

◆ ui_get_event_no_mouse()

int ui_get_event_no_mouse ( UiSurface * target,
uint w,
UiEvent * ev )

Definition at line 229 of file ui_notcurses_input.c.

229 {
230 (void)target;
231 (void)w;
232 if (!ui || !ev)
233 return -1;
234 memset(ev, 0, sizeof(*ev));
235 ncinput ni;
236 // notcurses_mice_disable(ui->nc);
237 do {
238 notcurses_get(ui->nc, NULL, &ni);
239 } while (ni.id == NCKEY_INVALID);
240 ev->key = translate_nckey(ni.id, &ni);
241 ev->alt = ncinput_alt_p(&ni);
242 ev->ctrl = ncinput_ctrl_p(&ni);
243 ev->shift = ncinput_shift_p(&ni);
244 if (ev->key == UI_KEY_CHAR)
245 ev->ch = ni.id;
246 return ni.id;
247}

References UiEvent::alt, UiEvent::ch, UiEvent::ctrl, UiEvent::key, UiRuntime::nc, UiEvent::shift, ui, and UI_KEY_CHAR.

Referenced by get_cmd_char().

Here is the caller graph for this function:

◆ ui_getch()

int ui_getch ( )

Definition at line 151 of file ui_notcurses_input.c.

151 {
152 if (!ui)
153 return -1;
154 ncinput ni;
155 do {
156 notcurses_get(ui->nc, NULL, &ni);
157 } while (ni.evtype == NCTYPE_RELEASE ||
158 ni.id == NCKEY_INVALID ||
159 ni.id == NCKEY_MOTION ||
160 ni.id == NCKEY_SIGNAL);
161 return ni.id;
162}

References nc, UiRuntime::nc, and ui.

Referenced by ui_notcurses_init().

Here is the caller graph for this function: