diff --git a/doc/man/man3/notcurses_input.3.md b/doc/man/man3/notcurses_input.3.md index 9a3186014..acf6e4c6b 100644 --- a/doc/man/man3/notcurses_input.3.md +++ b/doc/man/man3/notcurses_input.3.md @@ -14,24 +14,32 @@ notcurses_input - input via notcurses struct timespec; struct notcurses; +typedef enum { + NCTYPE_UNKNOWN, + NCTYPE_PRESS, + NCTYPE_REPEAT, + NCTYPE_RELEASE, +} ncintype_e; + +// 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. +// FIXME for abi4, combine the bools into |modifiers| 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 - unsigned modifiers; + uint32_t id; // Unicode codepoint or synthesized NCKEY event + int y, x; // y/x cell coordinate of event, -1 for undefined + char utf8[5]; // utf8 representation, if one exists + // DEPRECATED do not use! going away in 4.0 + bool alt; // was alt held? + bool shift; // was shift held? + bool ctrl; // was ctrl held? + // END DEPRECATION + ncintype_e evtype; + unsigned modifiers;// bitmask over NCKEY_MOD_* + 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 @@ -51,7 +59,7 @@ typedef struct ncinput { **uint32_t notcurses_get_blocking(struct notcurses* ***n***, ncinput* ***ni***);** -**int cnotcurses_mice_enable(struct notcurses* ***n***, unsigned ***eventmask***);** +**int notcurses_mice_enable(struct notcurses* ***n***, unsigned ***eventmask***);** **int notcurses_mice_disable(struct notcurses* ***n***);** @@ -71,6 +79,10 @@ typedef struct ncinput { **bool ncinput_meta_p(const struct ncinput* ***n***);** +**bool ncinput_super_p(const struct ncinput* ***n***);** + +**bool ncinput_hyper_p(const struct ncinput* ***n***);** + # DESCRIPTION notcurses supports input from keyboards and mice, and any device that looks @@ -102,7 +114,9 @@ be called without the possibility of blocking. **ncinput_equal_p** compares two **ncinput** structs for data equality (i.e. not considering padding), returning **true** if they represent the same -input (though not necessarily the same input event). +input (though not necessarily the same input event). Note that +**NCTYPE_UNKNOWN** and **NCTYPE_PRESS** are considered equivalent for the +purposes of **ncinput_equal_p**. **notcurses_linesigs_disable** disables conversion of inputs **INTR**, **QUIT**, **SUSP**, and **DSUSP** into **SIGINT**, **SIGQUIT**, and **SIGTSTP**. These diff --git a/include/ncpp/NCKey.hh b/include/ncpp/NCKey.hh index 0bfc1f70c..bf14f12d8 100644 --- a/include/ncpp/NCKey.hh +++ b/include/ncpp/NCKey.hh @@ -136,10 +136,10 @@ namespace ncpp struct EvType { - static constexpr unsigned Unknown = ncinput::NCTYPE_UNKNOWN; - static constexpr unsigned Press = ncinput::NCTYPE_PRESS; - static constexpr unsigned Repeat = ncinput::NCTYPE_REPEAT; - static constexpr unsigned Release = ncinput::NCTYPE_RELEASE; + static constexpr ncintype_e Unknown = NCTYPE_UNKNOWN; + static constexpr ncintype_e Press = NCTYPE_PRESS; + static constexpr ncintype_e Repeat = NCTYPE_REPEAT; + static constexpr ncintype_e Release = NCTYPE_RELEASE; }; } diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 02387d55c..ce9cc63aa 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1130,6 +1130,13 @@ nckey_mouse_p(uint32_t r){ return r >= NCKEY_MOTION && r <= NCKEY_BUTTON11; } +typedef enum { + NCTYPE_UNKNOWN, + NCTYPE_PRESS, + NCTYPE_REPEAT, + NCTYPE_RELEASE, +} ncintype_e; + // 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. @@ -1143,12 +1150,7 @@ typedef struct ncinput { bool shift; // was shift held? bool ctrl; // was ctrl held? // END DEPRECATION - enum { - NCTYPE_UNKNOWN, - NCTYPE_PRESS, - NCTYPE_REPEAT, - NCTYPE_RELEASE, - } evtype; + ncintype_e evtype; unsigned modifiers;// bitmask over NCKEY_MOD_* int ypx, xpx; // pixel offsets within cell, -1 for undefined } ncinput; @@ -1193,19 +1195,28 @@ ncinput_numlock_p(const ncinput* n){ return (n->modifiers & NCKEY_MOD_NUMLOCK); } -// compare two ncinput structs for data equality. +// compare two ncinput structs for data equality. NCTYPE_PRESS and +// NCTYPE_UNKNOWN are considered to be equivalent. static inline bool ncinput_equal_p(const ncinput* n1, const ncinput* n2){ + // don't need to check ->utf8; it's derived from id if(n1->id != n2->id){ return false; } if(n1->y != n2->y || n1->x != n2->x){ return false; } - if(n1->alt != n2->alt || n1->shift != n2->shift || n1->ctrl != n2->ctrl){ + // don't need to check deprecated alt, ctrl, shift + if(n1->modifiers != n2->modifiers){ return false; } if(n1->evtype != n2->evtype){ + if((n1->evtype != NCTYPE_UNKNOWN && n1->evtype != NCTYPE_PRESS) || + (n2->evtype != NCTYPE_UNKNOWN && n2->evtype != NCTYPE_PRESS)){ + return false; + } + } + if(n1->ypx != n2->ypx || n1->xpx != n2->xpx){ return false; } return true; diff --git a/src/lib/menu.c b/src/lib/menu.c index 92ab3f4c9..ae82bb1bc 100644 --- a/src/lib/menu.c +++ b/src/lib/menu.c @@ -92,10 +92,10 @@ dup_menu_item(ncmenu_int_item* dst, const struct ncmenu_item* src){ return 0; } size_t bytes = 1; // NUL terminator - if(src->shortcut.alt){ + if(ncinput_alt_p(&src->shortcut)){ bytes += strlen(ALTMOD); } - if(src->shortcut.ctrl){ + if(ncinput_ctrl_p(&src->shortcut)){ bytes += strlen(CTLMOD); } mbstate_t ps; @@ -107,8 +107,8 @@ dup_menu_item(ncmenu_int_item* dst, const struct ncmenu_item* src){ } bytes += shortsize + 1; char* sdup = malloc(bytes); - int n = snprintf(sdup, bytes, "%s%s", src->shortcut.alt ? ALTMOD : "", - src->shortcut.ctrl ? CTLMOD : ""); + int n = snprintf(sdup, bytes, "%s%s", ncinput_alt_p(&src->shortcut) ? ALTMOD : "", + ncinput_ctrl_p(&src->shortcut) ? CTLMOD : ""); if(n < 0 || (size_t)n >= bytes){ free(sdup); free(dst->desc); diff --git a/src/tests/plane.cpp b/src/tests/plane.cpp index 910c044a2..826c5ddd2 100644 --- a/src/tests/plane.cpp +++ b/src/tests/plane.cpp @@ -883,7 +883,7 @@ TEST_CASE("Plane") { REQUIRE(n); ncinput ni{}; ni.id = NCKEY_BUTTON1; - ni.evtype = ncinput::NCTYPE_RELEASE; + ni.evtype = ncpp::EvType::Release; int total = 0; for(ni.y = 0 ; ni.y < 5 ; ++ni.y){ for(ni.x = 0 ; ni.x < 5 ; ++ni.x){