Skip to content

Commit 34ccabc

Browse files
Dargon789lhecker
andauthored
Implement the Kitty Keyboard Protocol (microsoft#19817) (#7)
This essentially rewrites `TerminalInput` from scratch. There's significant overlap between what kind of information the Kitty protocol needs from the OS and our existing code. The rewrite allows us to share large parts of the implementation. Closes microsoft#11509 ## Validation Steps Performed * `kitten show-key -m kitty` ✅ * US Intern. " + ' produces `\'` ✅ * Hebrew base keys produce Unicode ✅ * Hebrew AltGr combinations produce Unicode ✅ * French AltGr+Space produces U+00A0 ✅ * German AltGr+Decimals produce []{}... ✅ Co-authored-by: Leonard Hecker <[email protected]>
1 parent fe06d8b commit 34ccabc

File tree

31 files changed

+1901
-676
lines changed

31 files changed

+1901
-676
lines changed

.github/actions/spelling/expect/expect.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ conterm
256256
contsf
257257
contypes
258258
conwinuserrefs
259-
coordnew
260259
COPYCOLOR
261260
COPYDATA
262261
COPYDATASTRUCT
@@ -622,7 +621,6 @@ fuzzmap
622621
fuzzwrapper
623622
fwdecl
624623
fwe
625-
fwlink
626624
fzf
627625
gci
628626
gcx
@@ -866,6 +864,7 @@ KILLACTIVE
866864
KILLFOCUS
867865
kinda
868866
KIYEOK
867+
KKP
869868
KLF
870869
KLMNO
871870
KOK
@@ -885,6 +884,7 @@ LBUTTONDOWN
885884
LBUTTONUP
886885
lcb
887886
lci
887+
LCMAP
888888
LCONTROL
889889
LCTRL
890890
lcx

src/buffer/out/ut_textbuffer/ReflowTests.cpp

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -600,90 +600,6 @@ namespace
600600
},
601601
},
602602
};
603-
604-
#pragma region TAEF hookup for the test case array above
605-
struct ArrayIndexTaefAdapterRow : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom | Microsoft::WRL::InhibitFtmBase>, IDataRow>
606-
{
607-
HRESULT RuntimeClassInitialize(const size_t index)
608-
{
609-
_index = index;
610-
return S_OK;
611-
}
612-
613-
STDMETHODIMP GetTestData(BSTR /*pszName*/, SAFEARRAY** ppData) override
614-
{
615-
const auto indexString{ wil::str_printf<std::wstring>(L"%zu", _index) };
616-
auto safeArray{ SafeArrayCreateVector(VT_BSTR, 0, 1) };
617-
LONG index{ 0 };
618-
auto indexBstr{ wil::make_bstr(indexString.c_str()) };
619-
(void)SafeArrayPutElement(safeArray, &index, indexBstr.release());
620-
*ppData = safeArray;
621-
return S_OK;
622-
}
623-
624-
STDMETHODIMP GetMetadataNames(SAFEARRAY** ppMetadataNames) override
625-
{
626-
*ppMetadataNames = nullptr;
627-
return S_FALSE;
628-
}
629-
630-
STDMETHODIMP GetMetadata(BSTR /*pszName*/, SAFEARRAY** ppData) override
631-
{
632-
*ppData = nullptr;
633-
return S_FALSE;
634-
}
635-
636-
STDMETHODIMP GetName(BSTR* ppszRowName) override
637-
{
638-
*ppszRowName = nullptr;
639-
return S_FALSE;
640-
}
641-
642-
private:
643-
size_t _index;
644-
};
645-
646-
struct ArrayIndexTaefAdapterSource : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom | Microsoft::WRL::InhibitFtmBase>, IDataSource>
647-
{
648-
STDMETHODIMP Advance(IDataRow** ppDataRow) override
649-
{
650-
if (_index < std::extent_v<decltype(testCases)>)
651-
{
652-
Microsoft::WRL::MakeAndInitialize<ArrayIndexTaefAdapterRow>(ppDataRow, _index++);
653-
}
654-
else
655-
{
656-
*ppDataRow = nullptr;
657-
}
658-
return S_OK;
659-
}
660-
661-
STDMETHODIMP Reset() override
662-
{
663-
_index = 0;
664-
return S_OK;
665-
}
666-
667-
STDMETHODIMP GetTestDataNames(SAFEARRAY** names) override
668-
{
669-
auto safeArray{ SafeArrayCreateVector(VT_BSTR, 0, 1) };
670-
LONG index{ 0 };
671-
auto dataNameBstr{ wil::make_bstr(L"index") };
672-
(void)SafeArrayPutElement(safeArray, &index, dataNameBstr.release());
673-
*names = safeArray;
674-
return S_OK;
675-
}
676-
677-
STDMETHODIMP GetTestDataType(BSTR /*name*/, BSTR* type) override
678-
{
679-
*type = nullptr;
680-
return S_OK;
681-
}
682-
683-
private:
684-
size_t _index{ 0 };
685-
};
686-
#pragma endregion
687603
}
688604

689605
extern "C" HRESULT __declspec(dllexport) __cdecl ReflowTestDataSource(IDataSource** ppDataSource, void*)

src/cascadia/TerminalCore/ICoreSettings.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ namespace Microsoft.Terminal.Core
121121
String WordDelimiters { get; };
122122

123123
Boolean ForceVTInput { get; };
124+
Boolean AllowKittyKeyboardMode { get; };
124125
Boolean AllowVtChecksumReport { get; };
125126
Boolean AllowVtClipboardWrite { get; };
126127
Boolean TrimBlockSelection { get; };

src/cascadia/TerminalCore/Terminal.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void Terminal::UpdateSettings(ICoreSettings settings)
9898
}
9999

100100
_getTerminalInput().ForceDisableWin32InputMode(settings.ForceVTInput());
101+
_getTerminalInput().ForceDisableKittyKeyboardProtocol(!settings.AllowKittyKeyboardMode());
101102

102103
if (settings.TabColor() == nullptr)
103104
{

src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ namespace winrt::Microsoft::Terminal::Settings
349349
_ReloadEnvironmentVariables = profile.ReloadEnvironmentVariables();
350350
_RainbowSuggestions = profile.RainbowSuggestions();
351351
_ForceVTInput = profile.ForceVTInput();
352+
_AllowKittyKeyboardMode = profile.AllowKittyKeyboardMode();
352353
_AllowVtChecksumReport = profile.AllowVtChecksumReport();
353354
_AllowVtClipboardWrite = profile.AllowVtClipboardWrite();
354355
_PathTranslationStyle = profile.PathTranslationStyle();

src/cascadia/TerminalSettingsEditor/ProfileViewModel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
139139
OBSERVABLE_PROJECTED_SETTING(_profile, AutoMarkPrompts);
140140
OBSERVABLE_PROJECTED_SETTING(_profile, RepositionCursorWithMouse);
141141
OBSERVABLE_PROJECTED_SETTING(_profile, ForceVTInput);
142+
OBSERVABLE_PROJECTED_SETTING(_profile, AllowKittyKeyboardMode);
142143
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtChecksumReport);
143144
OBSERVABLE_PROJECTED_SETTING(_profile, AllowVtClipboardWrite);
144145
OBSERVABLE_PROJECTED_SETTING(_profile, AnswerbackMessage);

src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ namespace Microsoft.Terminal.Settings.Editor
134134
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AutoMarkPrompts);
135135
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, RepositionCursorWithMouse);
136136
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, ForceVTInput);
137+
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowKittyKeyboardMode);
137138
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AllowVtChecksumReport);
138139
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, AnswerbackMessage);
139140
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, RainbowSuggestions);

src/cascadia/TerminalSettingsEditor/Profiles_Terminal.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
5050
</local:SettingContainer>
5151

52+
<!-- Kitty Keyboard Mode -->
53+
<local:SettingContainer x:Name="AllowKittyKeyboardMode"
54+
x:Uid="Profile_AllowKittyKeyboardMode"
55+
ClearSettingValue="{x:Bind Profile.ClearAllowKittyKeyboardMode}"
56+
HasSettingValue="{x:Bind Profile.HasAllowKittyKeyboardMode, Mode=OneWay}"
57+
SettingOverrideSource="{x:Bind Profile.AllowKittyKeyboardModeOverrideSource, Mode=OneWay}">
58+
<ToggleSwitch IsOn="{x:Bind Profile.AllowKittyKeyboardMode, Mode=TwoWay}"
59+
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
60+
</local:SettingContainer>
61+
5262
<!-- Allow VT Checksum Report -->
5363
<local:SettingContainer x:Uid="Profile_AllowVtChecksumReport"
5464
ClearSettingValue="{x:Bind Profile.ClearAllowVtChecksumReport}"

src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@
546546
<value>Use the legacy input encoding</value>
547547
<comment>Header for a control to toggle legacy input encoding for the terminal.</comment>
548548
</data>
549+
<data name="Profile_AllowKittyKeyboardMode.Header" xml:space="preserve">
550+
<value>Allow Kitty Keyboard Protocol</value>
551+
<comment>{Locked="Kitty"}Kitty is a moniker and its Keyboard Protocol is a protocol specification.</comment>
552+
</data>
549553
<data name="Profile_AllowVtChecksumReport.Header" xml:space="preserve">
550554
<value>Allow DECRQCRA (Request Checksum of Rectangular Area)</value>
551555
<comment>{Locked="DECRQCRA"}{Locked="Request Checksum of Rectangular Area"}Header for a control to toggle support for the DECRQCRA control sequence.</comment>
@@ -2591,19 +2595,19 @@
25912595
<comment>An option to choose from for the "path translation" setting.</comment>
25922596
</data>
25932597
<data name="Profile_PathTranslationStyleWsl.Content" xml:space="preserve">
2594-
<value>WSL (C:\ -> /mnt/c)</value>
2598+
<value>WSL (C:\ -&gt; /mnt/c)</value>
25952599
<comment>{Locked="WSL","C:\","/mnt/c"} An option to choose from for the "path translation" setting.</comment>
25962600
</data>
25972601
<data name="Profile_PathTranslationStyleCygwin.Content" xml:space="preserve">
2598-
<value>Cygwin (C:\ -> /cygdrive/c)</value>
2602+
<value>Cygwin (C:\ -&gt; /cygdrive/c)</value>
25992603
<comment>{Locked="Cygwin","C:\","/cygdrive/c"} An option to choose from for the "path translation" setting.</comment>
26002604
</data>
26012605
<data name="Profile_PathTranslationStyleMsys2.Content" xml:space="preserve">
2602-
<value>MSYS2 (C:\ -> /c)</value>
2606+
<value>MSYS2 (C:\ -&gt; /c)</value>
26032607
<comment>{Locked="MSYS2","C:\","/c"} An option to choose from for the "path translation" setting.</comment>
26042608
</data>
26052609
<data name="Profile_PathTranslationStyleMinGW.Content" xml:space="preserve">
2606-
<value>MinGW (C:\ -> C:/)</value>
2610+
<value>MinGW (C:\ -&gt; C:/)</value>
26072611
<comment>{Locked="MinGW","C:\","C:/"} An option to choose from for the "path translation" setting.</comment>
26082612
</data>
26092613
<data name="Profile_Delete_Orphaned.Header" xml:space="preserve">

src/cascadia/TerminalSettingsModel/MTSMSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Author(s):
103103
X(bool, ReloadEnvironmentVariables, "compatibility.reloadEnvironmentVariables", true) \
104104
X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false) \
105105
X(bool, ForceVTInput, "compatibility.input.forceVT", false) \
106+
X(bool, AllowKittyKeyboardMode, "compatibility.kittyKeyboardMode", true) \
106107
X(bool, AllowVtChecksumReport, "compatibility.allowDECRQCRA", false) \
107108
X(bool, AllowVtClipboardWrite, "compatibility.allowOSC52", true) \
108109
X(bool, AllowKeypadMode, "compatibility.allowDECNKM", false) \

0 commit comments

Comments
 (0)