Skip to content

Commit

Permalink
[kitty] handle level 1 of keyboard protocol #2131
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Sep 2, 2021
1 parent ad87e8c commit fc52a9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/lib/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ handle_csi(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin){
ni->x = param - 1;
ni->y = param1 - 1;
return NCKEY_CURSOR_LOCATION_REPORT;
}else if(candidate == 'u'){ // kitty keyboard protocol
ni->id = param1;
if((param - 1) & 0x1){
ni->shift = 1;
}
if((param - 1) & 0x2){
ni->alt = 1;
}
if((param - 1) & 0x4){
ni->ctrl = 1;
}
// FIXME decode remaining modifiers through 128
logdebug("KITTY PROTOCOL %d/%d\n", param1, param);
return param1;
}else if(candidate == ';'){
state = PARAM3;
if(param == 0){
Expand Down Expand Up @@ -366,6 +380,7 @@ handle_getc(ncinputlayer* nc, int kpress, ncinput* ni, int leftmargin, int topma
if(kpress < 0){
return -1;
}
unsigned csiidx = 0;
if(kpress == NCKEY_ESC){
const esctrie* esc = nc->inputescapes;
int candidate = 0;
Expand All @@ -380,6 +395,9 @@ handle_getc(ncinputlayer* nc, int kpress, ncinput* ni, int leftmargin, int topma
}
candidate = pop_input_keypress(nc);
logdebug("trie candidate: %c %d (%d)\n", candidate, esc->special, candidate);
if(csi){
nc->csibuf[csiidx++] = candidate;
}
if(esc->trie == NULL){
esc = NULL;
}else if(candidate >= 0x80 || candidate < 0){
Expand All @@ -396,8 +414,9 @@ handle_getc(ncinputlayer* nc, int kpress, ncinput* ni, int leftmargin, int topma
return esc->special;
}
if(csi){
// FIXME might need to unpop more than one
unpop_keypress(nc, candidate);
while(csiidx){
unpop_keypress(nc, nc->csibuf[--csiidx]);
}
return handle_csi(nc, ni, leftmargin, topmargin);
}
// interpret it as alt + candidate FIXME broken for first char matching
Expand Down
2 changes: 1 addition & 1 deletion src/lib/termdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ init_terminfo_esc(tinfo* ti, const char* name, escape_e idx,

// request kitty keyboard protocol through level 31, and push current.
// see https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
#define KBDSUPPORT "\x1b[>u\x1b[=31u"
#define KBDSUPPORT "\x1b[>u\x1b[=1u"

// the kitty keyboard protocol allows unambiguous, complete identification of
// input events. this queries for the level of support.
Expand Down
1 change: 1 addition & 0 deletions src/lib/termdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef struct ncinputlayer {
int ttyfd; // file descriptor for connected tty
int infd; // file descriptor for processing input, from stdin
unsigned char inputbuf[BUFSIZ];
unsigned char csibuf[BUFSIZ]; // running buffer while parsing CSIs
// we keep a wee ringbuffer of input queued up for delivery. if
// inputbuf_occupied == sizeof(inputbuf), there is no room. otherwise, data
// can be read to inputbuf_write_at until we fill up. the first datum
Expand Down

0 comments on commit fc52a9c

Please sign in to comment.