Skip to content

Commit

Permalink
feat(DBCS input): handle automatic key repeats for DBCS characters by…
Browse files Browse the repository at this point in the history
… adding vkey_process_no_dbcs_repeat()

* maple/visio.c:
    * vkey(): Invoke vkey_process_no_dbcs_repeat() for key post-processing
* include/proto.h:
    * Add declaration for vkey_process_no_dbcs_repeat()
  • Loading branch information
IepIweidieng committed Mar 6, 2021
1 parent 20d8ac1 commit df69c19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ int iac_process(const unsigned char *current, const unsigned char *end, int *pco
int iac_count(const unsigned char *current);
int igetch(void);
GCC_CHECK_NONNULL_ALL int vkey_process(int (*fgetch)(void));
GCC_CHECK_NONNULL_ALL int vkey_process_no_dbcs_repeat(int (*fgetch)(void));
int vkey(void);
BRD *ask_board(char *board, unsigned int perm, const char *msg);
int vget(int y_ref, int x_ref, const char *prompt, char *data, int max, int echo);
Expand Down
41 changes: 40 additions & 1 deletion maple/visio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,10 +2208,49 @@ int vkey_process(int (*fgetch)(void))
return ch;
}

/* Ignore automatic key repeats for DBCS characters send by some clients */
GCC_CHECK_NONNULL_ALL
int vkey_process_no_dbcs_repeat(int (*fgetch)(void))
{
static int unget_key = KEY_NONE;
if (unget_key != KEY_NONE)
{
const int key = unget_key;
unget_key = KEY_NONE;
return key;
}

const int key = vkey_process(fgetch);
switch (key)
{
case Ctrl('H'): /* Backspace */
/* case Ctrl('D'): */ /* KKman 3 handles this as Del */
/* However KKman users are probably few in 2020 */
case KEY_DEL:
case KEY_LEFT:
case KEY_RIGHT:
{
/* Check the upcoming key to see whether the key is repeated */
const struct timeval vio_to_backup = vio_to;
vio_to = seq_tv;
{
const int key2 = vkey_process(fgetch);
if (key2 != I_TIMEOUT && key2 != KEY_INVALID && key2 != key)
unget_key = key2; /* Not repeated; put it back */
}
vio_to = vio_to_backup;
}
break;
default:
;
}
return key;
}

int
vkey(void)
{
const int key = vkey_process(igetch);
const int key = vkey_process_no_dbcs_repeat(igetch);

switch (key)
{
Expand Down

0 comments on commit df69c19

Please sign in to comment.