mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
[input] add evtype to ncinput, for press/repeat/release #2182
This commit is contained in:
parent
1f4b32def7
commit
99007e128c
7
NEWS.md
7
NEWS.md
@ -12,6 +12,13 @@ rearrangements of Notcurses.
|
||||
retrieve terminal messages (if buffers are full, Notcurses cannot
|
||||
continue reading). Likewise added `NCDIRECT_OPTION_DRAIN_INPUT`.
|
||||
* Removed a bunch of deprecated `static inline` functions from the headers.
|
||||
* A new field, `evtype`, has been added to `ncinput`. It takes a value
|
||||
from among `EVTYPE_{UNKNOWN, PRESS, REPEAT, RELEASE}.`. Where possible,
|
||||
Notcurses will distinguish between a press, repeat, and release. This
|
||||
cannot be done in all environments, nor with all inputs. The
|
||||
`NCKEY_RELEASE` definition is no longer returned; instead, the
|
||||
appropriate `NCKEY_BUTTONx` synthesized key is returned, with
|
||||
`EVTYPE_RELEASE` set.
|
||||
|
||||
* 2.4.1 (2021-09-12)
|
||||
* `notcurses_check_pixel_support()` still returns 0 if there is no support
|
||||
|
7
USAGE.md
7
USAGE.md
@ -684,7 +684,12 @@ typedef struct ncinput {
|
||||
bool alt; // was alt held?
|
||||
bool shift; // was shift held?
|
||||
bool ctrl; // was ctrl held?
|
||||
uint64_t seqnum; // input event number
|
||||
enum {
|
||||
EVTYPE_UNKNOWN,
|
||||
EVTYPE_PRESS,
|
||||
EVTYPE_REPEAT,
|
||||
EVTYPE_RELEASE,
|
||||
} evtype;
|
||||
} ncinput;
|
||||
|
||||
// Read a UTF-32-encoded Unicode codepoint from input. This might only be part
|
||||
|
@ -21,7 +21,12 @@ typedef struct ncinput {
|
||||
bool alt; // Was Alt held during the event?
|
||||
bool shift; // Was Shift held during the event?
|
||||
bool ctrl; // Was Ctrl held during the event?
|
||||
uint64_t seqnum; // Monotonically increasing input event counter
|
||||
enum {
|
||||
EVTYPE_UNKNOWN,
|
||||
EVTYPE_PRESS,
|
||||
EVTYPE_REPEAT,
|
||||
EVTYPE_RELEASE,
|
||||
} evtype;
|
||||
} ncinput;
|
||||
```
|
||||
|
||||
@ -77,8 +82,8 @@ be the actual input file descriptor. If it readable, **notcurses_get** can
|
||||
be called without the possibility of blocking.
|
||||
|
||||
**ncinput_equal_p** compares two **ncinput** structs for data equality (i.e.
|
||||
not considering padding or the **seqnum** field), returning **true** if they
|
||||
represent the same input (though not necessarily the same input event).
|
||||
not considering padding), returning **true** if they represent the same
|
||||
input (though not necessarily the same input event).
|
||||
|
||||
**notcurses_linesigs_disable** disables conversion of inputs **INTR**, **QUIT**,
|
||||
**SUSP**, and **DSUSP** into **SIGINT**, **SIGQUIT**, and **SIGTSTP**. These
|
||||
|
@ -1037,19 +1037,25 @@ nckey_mouse_p(uint32_t r){
|
||||
return r >= NCKEY_BUTTON1 && r <= NCKEY_RELEASE;
|
||||
}
|
||||
|
||||
// An input event. Cell coordinates are currently defined only for mouse events.
|
||||
// An input event. Cell coordinates are currently defined only for mouse
|
||||
// events. It is not guaranteed that we can set the modifiers for a given
|
||||
// ncinput. We encompass single Unicode codepoints, not complete EGCs.
|
||||
typedef struct ncinput {
|
||||
uint32_t id; // identifier. Unicode codepoint or synthesized NCKEY event
|
||||
int y; // y cell coordinate of event, -1 for undefined
|
||||
int x; // x cell coordinate of event, -1 for undefined
|
||||
bool alt; // was alt held?
|
||||
bool shift; // was shift held?
|
||||
bool ctrl; // was ctrl held?
|
||||
uint64_t seqnum; // input event number
|
||||
uint32_t id; // Unicode codepoint or synthesized NCKEY event
|
||||
int y; // y cell coordinate of event, -1 for undefined
|
||||
int x; // x cell coordinate of event, -1 for undefined
|
||||
bool alt; // was alt held?
|
||||
bool shift; // was shift held?
|
||||
bool ctrl; // was ctrl held?
|
||||
enum {
|
||||
EVTYPE_UNKNOWN,
|
||||
EVTYPE_PRESS,
|
||||
EVTYPE_REPEAT,
|
||||
EVTYPE_RELEASE,
|
||||
} evtype;
|
||||
} ncinput;
|
||||
|
||||
// compare two ncinput structs for data equality. we can't just use memcmp()
|
||||
// due to potential padding in the struct (especially wrt bools) and seqnum.
|
||||
// compare two ncinput structs for data equality.
|
||||
static inline bool
|
||||
ncinput_equal_p(const ncinput* n1, const ncinput* n2){
|
||||
if(n1->id != n2->id){
|
||||
@ -1061,7 +1067,9 @@ ncinput_equal_p(const ncinput* n1, const ncinput* n2){
|
||||
if(n1->alt != n2->alt || n1->shift != n2->shift || n1->ctrl != n2->ctrl){
|
||||
return false;
|
||||
}
|
||||
// do not check seqnum!
|
||||
if(n1->keytype != n2->keytype){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,6 @@ while True:
|
||||
std_plane.putstr(f"Is alt: {p.is_alt}", y_pos=3, x_pos=0)
|
||||
std_plane.putstr(f"Is shift: {p.is_shift}", y_pos=4, x_pos=0)
|
||||
std_plane.putstr(f"Is ctrl: {p.is_ctrl}", y_pos=5, x_pos=0)
|
||||
std_plane.putstr(f"Seqnum: {p.seqnum}", y_pos=6, x_pos=0)
|
||||
std_plane.putstr("Press CTRL+C to exit.", y_pos=7, x_pos=0)
|
||||
|
||||
std_plane.context.render()
|
||||
|
@ -125,7 +125,6 @@ typedef struct inputctx {
|
||||
HANDLE stdinhandle; // handle to input terminal for MSFT Terminal
|
||||
#endif
|
||||
|
||||
uint64_t seqnum; // process-scope sequence number
|
||||
int lmargin, tmargin; // margins in use at left and top
|
||||
|
||||
struct esctrie* inputescapes;
|
||||
@ -473,7 +472,6 @@ create_inputctx(tinfo* ti, FILE* infp, int lmargin, int tmargin,
|
||||
i->runstring[i->stridx] = '\0';
|
||||
i->lmargin = lmargin;
|
||||
i->tmargin = tmargin;
|
||||
i->seqnum = 0;
|
||||
i->drain = drain;
|
||||
logdebug("input descriptors: %d/%d\n", i->stdinfd, i->termfd);
|
||||
return i;
|
||||
@ -2013,7 +2011,6 @@ internal_get(inputctx* ictx, const struct timespec* ts, ncinput* ni){
|
||||
id = ictx->inputs[ictx->iread].id;
|
||||
if(ni){
|
||||
memcpy(ni, &ictx->inputs[ictx->iread], sizeof(*ni));
|
||||
ni->seqnum = ++ictx->seqnum;
|
||||
}
|
||||
if(++ictx->iread == ictx->isize){
|
||||
ictx->iread = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user