add ncinput_equal_p() predicate #1059

This commit is contained in:
nick black 2020-10-15 03:14:19 -04:00
parent 6623fc92a0
commit 3229fa53b3
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 27 additions and 0 deletions

View File

@ -3,6 +3,7 @@ rearrangements of Notcurses.
* 2.1.0 (not yet released)
* Add `ncmenu_item_set_status()` for disabling or enabling menu items.
* Add `ncinput_equal_p()` for comparison of `ncinput` structure data.
* 2.0.0 (2020-10-12) "Stankonia"
* **API STABILITY!** The API expressed in 2.0.0 will be maintained throughout

View File

@ -39,6 +39,8 @@ typedef struct ncinput {
**int notcurses_inputready_fd(struct notcurses* n);**
**static inline int ncinput_equal_p(const struct ncinput* n1, const struct ncinput* n2);**
# DESCRIPTION
notcurses supports input from keyboards and mice, and any device that looks
@ -67,6 +69,10 @@ I/O multiplexors such as **poll(2)**. This file descriptor might or might not
be the actual input file descriptor. If it readable, **notcurses_getc** 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 1 if they
represent the same input (though not necessarily the same input event).
## Mice
For mouse events, the additional fields **y** and **x** are set. These fields
@ -114,6 +120,9 @@ a synthesized event, is returned.
**notcurses_mouse_enable** returns 0 on success, and non-zero on failure, as
does **notcurses_mouse_disable**.
**ncinput_equal_p** returns 1 if the two **ncinput** structs represent the
same input (though not necessarily the same input event), and 0 otherwise.
# NOTES
Like any other notcurses function, it is an error to call **notcurses_getc**

View File

@ -904,6 +904,23 @@ typedef struct ncinput {
uint64_t seqnum; // input event number
} 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.
static inline int
ncinput_equal_p(const struct ncinput* n1, const struct ncinput* n2){
if(n1->id != n2->id){
return 0;
}
if(n1->y != n2->y || n1->x != n2->x){
return 0;
}
if(n1->alt != n2->alt || n1->shift != n2->shift || n1->ctrl != n2->ctrl){
return 0;
}
// do not check seqnum!
return 1;
}
// See ppoll(2) for more detail. Provide a NULL 'ts' to block at length, a 'ts'
// of 0 for non-blocking operation, and otherwise a timespec to bound blocking.
// Signals in sigmask (less several we handle internally) will be atomically