Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented xterm's ModifyOtherKeys #2629

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
12 changes: 11 additions & 1 deletion WinPort/src/Backend/TTY/TTYInputSequenceParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ size_t TTYInputSequenceParser::ParseEscapeSequence(const char *s, size_t l)
}
}

// None of above? May be ModifyOtherKeys
if (l > 3 && s[0] == '[' && s[1] == '2' && s[2] == '7') {
r = TryParseModifyOtherKeys(s, l);
if (r != TTY_PARSED_BADSEQUENCE) {
return r;
}
}

// be well-responsive on panic-escaping
for (size_t i = 0; (i + 1) < l; ++i) {
Expand Down Expand Up @@ -447,7 +454,7 @@ size_t TTYInputSequenceParser::ParseIntoPending(const char *s, size_t l)
// return 1;

case 0x1c:
AddPendingKeyEvent(TTYInputKey{VK_OEM_5, 0});
AddPendingKeyEvent(TTYInputKey{VK_OEM_5, LEFT_CTRL_PRESSED});
return 1;

case 0x1d:
Expand Down Expand Up @@ -526,6 +533,9 @@ void TTYInputSequenceParser::AddPendingKeyEvent(const TTYInputKey &k)
if (k.vk == VK_SPACE) {
ir.Event.KeyEvent.uChar.UnicodeChar = L' ';
}
if (k.vk == VK_OEM_5) {
ir.Event.KeyEvent.uChar.UnicodeChar = L'\\';
}
ir.Event.KeyEvent.wVirtualKeyCode = k.vk;
ir.Event.KeyEvent.dwControlKeyState = k.control_keys | _extra_control_keys;
ir.Event.KeyEvent.wVirtualScanCode = WINPORT(MapVirtualKey)(k.vk,MAPVK_VK_TO_VSC);
Expand Down
1 change: 1 addition & 0 deletions WinPort/src/Backend/TTY/TTYInputSequenceParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class TTYInputSequenceParser
size_t ReadUTF8InHex(const char *s, wchar_t *uni_char);
size_t TryParseAsITerm2EscapeSequence(const char *s, size_t l);
size_t TryParseAsKittyEscapeSequence(const char *s, size_t l);
size_t TryParseModifyOtherKeys(const char *s, size_t l);
size_t ParseEscapeSequence(const char *s, size_t l);
void OnBracketedPaste(bool start);

Expand Down
33 changes: 33 additions & 0 deletions WinPort/src/Backend/TTY/TTYInputSequenceParserExts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,39 @@ size_t TTYInputSequenceParser::TryParseAsKittyEscapeSequence(const char *s, size
return i+1;
}

size_t TTYInputSequenceParser::TryParseModifyOtherKeys(const char *s, size_t l) {

int modif_state = 0, code = 0;
int state = 0; // 0 - initial state, 1 - reading modif_state, 2 - reading code

for (size_t i = 1; i < l; ++i) { // Starting with 1 to skip '['
if (s[i] == ';') {
state++;
continue;
} else if (s[i] == '~') {
break; // End of sequence
}

if (state == 1) {
modif_state = modif_state * 10 + (s[i] - '0');
} else if (state == 2) {
code = code * 10 + (s[i] - '0');
}
}

if (!code) return TTY_PARSED_BADSEQUENCE;

// Convert to kitty escape sequence format
// and let kitty parser do the rest

char buffer[32];
snprintf(buffer, sizeof(buffer), "[%d;%du", code, modif_state);
size_t length = strlen(buffer);
size_t result = TryParseAsKittyEscapeSequence(buffer, length);

if (result == length) { return l; } else { return TTY_PARSED_BADSEQUENCE; }
}

size_t TTYInputSequenceParser::TryParseAsWinTermEscapeSequence(const char *s, size_t l)
{
// check for nasty win32-input-mode sequence: as described in
Expand Down
14 changes: 14 additions & 0 deletions WinPort/src/Backend/TTY/TTYOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ TTYOutput::TTYOutput(int out, bool far2l_tty, bool norgb, DWORD nodetect)
Format(ESC "[=15;1u"); // kovidgoyal's kitty mode on
}

// ModifyOtherKeys on, set to mode 2 if possible (more keys supported)
Format(ESC "[?1036h");
// oops, this breakes Alt+letter quick search in non-latin kb layouts
// Format(ESC "[>4;2m");
// todo:
// user should have an option to decide if he wants Ctrl+numbers etc (mode 2)
// or Alt+non_latin_letters working (mode 1)
Format(ESC "[>4;1m");

ChangeKeypad(true);
ChangeMouse(true);

Expand Down Expand Up @@ -224,6 +233,11 @@ TTYOutput::~TTYOutput()
if ((_nodetect & NODETECT_A) == 0) {
Format(ESC "[?1337l"); // iTerm2 input mode off
}

// ModifyOtherKeys off
Format(ESC "[?1036l");
Format(ESC "[>4;0m");

TTYBasePalette def_palette;
ChangePalette(def_palette);
Flush();
Expand Down
Loading