From de02ceed917f37eb13e2b240c28ef04c668ef2b2 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 7 Jan 2022 22:10:53 -0500 Subject: [PATCH] [load_ncinput] always capitalize ASCII when Ctrl is used --- doc/man/man3/notcurses_input.3.md | 18 +++++++++--------- src/lib/in.c | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/doc/man/man3/notcurses_input.3.md b/doc/man/man3/notcurses_input.3.md index adec1743e..7c2955f60 100644 --- a/doc/man/man3/notcurses_input.3.md +++ b/doc/man/man3/notcurses_input.3.md @@ -207,17 +207,17 @@ In API4, the various **bool** modifier fields will go away, and these statuses will be merged into the ***modifiers*** bitmask. You are encouraged to use **ncinput_shift_p** and friends to future-proof your code. -When support is detected, the Kitty keyboard disambiguation protocol will be -requested. This eliminates most of the **BUGS** mentioned below. - # BUGS -The Shift key is not indicated in conjunction with typical Unicode text. -If e.g. Shift is used to generate a capital letter 'A', ***id*** will equal 'A', -and ***shift*** will be **false**. Similarly, when Ctrl is pressed along with a -letter, the letter will currently always be reported in its uppercase form. -E.g., if Shift, Ctrl, and 'a' are all pressed, this is indistinguishable from -Ctrl and 'A'. +Notcurses attempts to use the XTMODKEYS and Kitty keyboard disambiguation +protocols. When supported, they eliminate most of these issues. + +The Shift key is traditionally not indicated in conjunction with typical +Unicode text. If e.g. Shift is used to generate a capital letter 'A', ***id*** +will equal 'A', and ***shift*** will be **false**. Similarly, when Ctrl is +pressed along with a letter, the letter will currently always be reported in +its uppercase form. E.g., if Shift, Ctrl, and 'a' are all pressed, this is +indistinguishable from Ctrl and 'A'. Ctrl pressed along with 'J' or 'M', whether Shift is pressed or not, currently registers as **NCKEY_ENTER**. This will likely change in the diff --git a/src/lib/in.c b/src/lib/in.c index 41481e50e..2e2a9d187 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -476,16 +476,27 @@ mark_pipe_ready(ipipe pipes[static 2]){ } } -// shove the assembled input |tni| into the input queue (if there's room, -// and we're not draining, and we haven't hit EOF). send any synthesized -// signal as the last thing we do. +// shove the assembled input |tni| into the input queue (if there's room, and +// we're not draining, and we haven't hit EOF). send any synthesized signal as +// the last thing we do. if Ctrl is among the modifiers, we replace any +// lowercase letter with its uppercase form, to maintain compatibility with +// other input methods. static void -load_ncinput(inputctx* ictx, const ncinput *tni, int synthsig){ +load_ncinput(inputctx* ictx, ncinput *tni, int synthsig){ inc_input_events(ictx); if(ictx->drain || ictx->stdineof){ send_synth_signal(synthsig); return; } + if(tni->modifiers & NCKEY_MOD_CTRL){ + // when ctrl is used with an ASCII (0..127) lowercase letter, we always + // supply the capitalized form, to maintain compatibility among solutions + if(tni->id < 0x7f){ + if(islower(tni->id)){ + tni->id = toupper(tni->id); + } + } + } pthread_mutex_lock(&ictx->ilock); if(ictx->ivalid == ictx->isize){ pthread_mutex_unlock(&ictx->ilock);