Skip to content

Commit 24475ac

Browse files
lheckerDHowett
authored andcommitted
Add input scope startup setting (#17953)
This adds a "defaultInputScope" setting, hooks it up to our TSF, and exposes it as a setting in the UI under the startup page. In order to stay close with the other language setting, I moved that one from the appearance to the startup page as well. 20 out of the 26 files in this PR are boilerplate unfortunately. Closes #17816 ## Validation Steps Performed * Install and use the Chinese IME * Launch WT * Chinese input ✅ * Change setting to `alphanumericHalfWidth` * Restart WT * English input ✅ (cherry picked from commit fc606d2) Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgTTKAI Service-Version: 1.22
1 parent 2a8dee2 commit 24475ac

28 files changed

+399
-255
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ INLINEPREFIX
864864
inproc
865865
Inputkeyinfo
866866
Inputreadhandledata
867+
INPUTSCOPE
867868
INSERTMODE
868869
INTERACTIVITYBASE
869870
INTERCEPTCOPYPASTE
@@ -1289,6 +1290,7 @@ parms
12891290
PATCOPY
12901291
pathcch
12911292
PATTERNID
1293+
pbstr
12921294
pcb
12931295
pcch
12941296
PCCHAR
@@ -1374,9 +1376,11 @@ POSTCHARBREAKS
13741376
POSX
13751377
POSXSCROLL
13761378
POSYSCROLL
1379+
ppbstr
13771380
PPEB
13781381
ppf
13791382
ppidl
1383+
pprg
13801384
PPROC
13811385
ppropvar
13821386
ppsi
@@ -1692,6 +1696,7 @@ srcsrv
16921696
SRCSRVTRG
16931697
srctool
16941698
srect
1699+
SRGS
16951700
srvinit
16961701
srvpipe
16971702
ssa
@@ -1838,7 +1843,6 @@ triaging
18381843
TRIMZEROHEADINGS
18391844
trx
18401845
tsa
1841-
tsattrs
18421846
tsgr
18431847
tsm
18441848
TStr
@@ -1966,10 +1970,8 @@ vswhere
19661970
vtapp
19671971
VTE
19681972
VTID
1969-
vtio
19701973
vtmode
19711974
vtpipeterm
1972-
vtpt
19731975
VTRGB
19741976
VTRGBTo
19751977
vtseq

src/cascadia/TerminalControl/EventArgs.idl

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace Microsoft.Terminal.Control
2525
Console,
2626
};
2727

28+
enum DefaultInputScope
29+
{
30+
Default,
31+
AlphanumericHalfWidth,
32+
};
33+
2834
runtimeclass FontSizeChangedArgs
2935
{
3036
Int32 Width { get; };

src/cascadia/TerminalControl/IControlSettings.idl

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace Microsoft.Terminal.Control
6363
Boolean DisablePartialInvalidation { get; };
6464
Boolean SoftwareRendering { get; };
6565
Microsoft.Terminal.Control.TextMeasurement TextMeasurement { get; };
66+
Microsoft.Terminal.Control.DefaultInputScope DefaultInputScope { get; };
6667
Boolean ShowMarks { get; };
6768
Boolean UseBackgroundImageForWindow { get; };
6869
Boolean RightClickContextMenu { get; };

src/cascadia/TerminalControl/TermControl.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
861861
}
862862

863863
_interactivity.UpdateSettings();
864+
{
865+
const auto inputScope = settings.DefaultInputScope();
866+
const auto alpha = inputScope == DefaultInputScope::AlphanumericHalfWidth;
867+
::Microsoft::Console::TSF::Handle::SetDefaultScopeAlphanumericHalfWidth(alpha);
868+
}
864869
if (_automationPeer)
865870
{
866871
_automationPeer.SetControlPadding(Core::Padding{

src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml

-14
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@
2727
</Page.Resources>
2828

2929
<StackPanel Style="{StaticResource SettingsStackStyle}">
30-
<!-- Language -->
31-
<local:SettingContainer x:Uid="Globals_Language"
32-
Visibility="{x:Bind ViewModel.LanguageSelectorAvailable}">
33-
<ComboBox ItemsSource="{x:Bind ViewModel.LanguageList}"
34-
SelectedItem="{x:Bind ViewModel.CurrentLanguage, Mode=TwoWay}"
35-
Style="{StaticResource ComboBoxSettingStyle}">
36-
<ComboBox.ItemTemplate>
37-
<DataTemplate x:DataType="x:String">
38-
<TextBlock Text="{x:Bind local:GlobalAppearanceViewModel.LanguageDisplayConverter((x:String))}" />
39-
</DataTemplate>
40-
</ComboBox.ItemTemplate>
41-
</ComboBox>
42-
</local:SettingContainer>
43-
4430
<!-- Theme -->
4531
<local:SettingContainer x:Uid="Globals_Theme">
4632
<ComboBox AutomationProperties.AccessibilityView="Content"

src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.cpp

-163
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "EnumEntry.h"
88

99
#include <LibraryResources.h>
10-
#include <WtExeUtils.h>
1110

1211
using namespace winrt;
1312
using namespace winrt::Windows::UI::Xaml;
@@ -18,28 +17,6 @@ using namespace winrt::Windows::Foundation::Collections;
1817

1918
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
2019
{
21-
// For ComboBox an empty SelectedItem string denotes no selection.
22-
// What we want instead is for "Use system language" to be selected by default.
23-
// --> "und" is synonymous for "Use system language".
24-
constexpr std::wstring_view systemLanguageTag{ L"und" };
25-
26-
static constexpr std::array appLanguageTags{
27-
L"en-US",
28-
L"de-DE",
29-
L"es-ES",
30-
L"fr-FR",
31-
L"it-IT",
32-
L"ja",
33-
L"ko",
34-
L"pt-BR",
35-
L"qps-PLOC",
36-
L"qps-PLOCA",
37-
L"qps-PLOCM",
38-
L"ru",
39-
L"zh-Hans",
40-
L"zh-Hant",
41-
};
42-
4320
constexpr std::wstring_view systemThemeName{ L"system" };
4421
constexpr std::wstring_view darkThemeName{ L"dark" };
4522
constexpr std::wstring_view lightThemeName{ L"light" };
@@ -56,146 +33,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
5633
_UpdateThemeList();
5734
}
5835

59-
winrt::hstring GlobalAppearanceViewModel::LanguageDisplayConverter(const winrt::hstring& tag)
60-
{
61-
if (tag == systemLanguageTag)
62-
{
63-
return RS_(L"Globals_LanguageDefault");
64-
}
65-
66-
winrt::Windows::Globalization::Language language{ tag };
67-
return language.NativeName();
68-
}
69-
70-
// Returns whether the language selector is available/shown.
71-
//
72-
// winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride()
73-
// doesn't work for unpackaged applications. The corresponding code in TerminalApp is disabled.
74-
// It would be confusing for our users if we presented a dysfunctional language selector.
75-
bool GlobalAppearanceViewModel::LanguageSelectorAvailable()
76-
{
77-
return IsPackaged();
78-
}
79-
80-
// Returns the list of languages the user may override the application language with.
81-
// The returned list are BCP 47 language tags like {"und", "en-US", "de-DE", "es-ES", ...}.
82-
// "und" is short for "undefined" and is synonymous for "Use system language" in this code.
83-
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> GlobalAppearanceViewModel::LanguageList()
84-
{
85-
if (_languageList)
86-
{
87-
return _languageList;
88-
}
89-
90-
if (!LanguageSelectorAvailable())
91-
{
92-
_languageList = {};
93-
return _languageList;
94-
}
95-
96-
// In order to return the language list this code does the following:
97-
// [1] Get all possible languages we want to allow the user to choose.
98-
// We have to acquire languages from multiple sources, creating duplicates. See below at [1].
99-
// [2] Sort languages by their ASCII tags, forcing the UI in a consistent/stable order.
100-
// I wanted to sort the localized language names initially, but it turned out to be complex.
101-
// [3] Remove potential duplicates in our language list from [1].
102-
// We don't want to have en-US twice in the list, do we?
103-
// [4] Optionally remove unwanted language tags (like pseudo-localizations).
104-
105-
std::vector<winrt::hstring> tags;
106-
107-
// [1]:
108-
{
109-
// ManifestLanguages contains languages the app ships with.
110-
// Unfortunately, we cannot use this source. Our manifest must contain the
111-
// ~100 languages that are localized for the shell extension and start menu
112-
// presentation so we align with Windows display languages for those surfaces.
113-
// However, the actual content of our application is limited to a much smaller
114-
// subset of approximately 14 languages. As such, we will code the limited
115-
// subset of languages that we support for selection within the Settings
116-
// dropdown to steer users towards the ones that we can display in the app.
117-
118-
// As per the function definition, the first item
119-
// is always "Use system language" ("und").
120-
tags.emplace_back(systemLanguageTag);
121-
122-
// Add our hard-coded languages after the system definition.
123-
for (const auto& v : appLanguageTags)
124-
{
125-
tags.push_back(v);
126-
}
127-
}
128-
129-
// NOTE: The size of tags is always >0, due to tags[0] being hard-coded to "und".
130-
const auto tagsBegin = ++tags.begin();
131-
const auto tagsEnd = tags.end();
132-
133-
// [2]:
134-
std::sort(tagsBegin, tagsEnd);
135-
136-
// I'd love for both, std::unique and std::remove_if, to occur in a single loop,
137-
// but the code turned out to be complex and even less maintainable, so I gave up.
138-
{
139-
// [3] part 1:
140-
auto it = std::unique(tagsBegin, tagsEnd);
141-
142-
// The qps- languages are useful for testing ("pseudo-localization").
143-
// --> Leave them in if debug features are enabled.
144-
if (!_GlobalSettings.DebugFeaturesEnabled())
145-
{
146-
// [4] part 1:
147-
it = std::remove_if(tagsBegin, it, [](const winrt::hstring& tag) -> bool {
148-
return til::starts_with(tag, L"qps-");
149-
});
150-
}
151-
152-
// [3], [4] part 2 (completing the so called "erase-remove idiom"):
153-
tags.erase(it, tagsEnd);
154-
}
155-
156-
_languageList = winrt::single_threaded_observable_vector(std::move(tags));
157-
return _languageList;
158-
}
159-
160-
winrt::Windows::Foundation::IInspectable GlobalAppearanceViewModel::CurrentLanguage()
161-
{
162-
if (_currentLanguage)
163-
{
164-
return _currentLanguage;
165-
}
166-
167-
if (!LanguageSelectorAvailable())
168-
{
169-
_currentLanguage = {};
170-
return _currentLanguage;
171-
}
172-
173-
// NOTE: PrimaryLanguageOverride throws if this instance is unpackaged.
174-
auto currentLanguage = winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride();
175-
if (currentLanguage.empty())
176-
{
177-
currentLanguage = systemLanguageTag;
178-
}
179-
180-
_currentLanguage = winrt::box_value(currentLanguage);
181-
return _currentLanguage;
182-
}
183-
184-
void GlobalAppearanceViewModel::CurrentLanguage(const winrt::Windows::Foundation::IInspectable& tag)
185-
{
186-
_currentLanguage = tag;
187-
188-
const auto currentLanguage = winrt::unbox_value<winrt::hstring>(_currentLanguage);
189-
if (currentLanguage == systemLanguageTag)
190-
{
191-
_GlobalSettings.ClearLanguage();
192-
}
193-
else
194-
{
195-
_GlobalSettings.Language(currentLanguage);
196-
}
197-
}
198-
19936
// Function Description:
20037
// - Updates the list of all themes available to choose from.
20138
void GlobalAppearanceViewModel::_UpdateThemeList()

src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.h

-12
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
2222
GETSET_BINDABLE_ENUM_SETTING(TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, _GlobalSettings.TabWidthMode);
2323

2424
public:
25-
// LanguageDisplayConverter maps the given BCP 47 tag to a localized string.
26-
// For instance "en-US" produces "English (United States)", while "de-DE" produces
27-
// "Deutsch (Deutschland)". This works independently of the user's locale.
28-
static winrt::hstring LanguageDisplayConverter(const winrt::hstring& tag);
29-
30-
bool LanguageSelectorAvailable();
31-
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> LanguageList();
32-
winrt::Windows::Foundation::IInspectable CurrentLanguage();
33-
void CurrentLanguage(const winrt::Windows::Foundation::IInspectable& tag);
34-
3525
winrt::Windows::Foundation::IInspectable CurrentTheme();
3626
void CurrentTheme(const winrt::Windows::Foundation::IInspectable& tag);
3727
static winrt::hstring ThemeNameConverter(const Model::Theme& theme);
@@ -52,8 +42,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
5242

5343
private:
5444
Model::GlobalAppSettings _GlobalSettings;
55-
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> _languageList;
56-
winrt::Windows::Foundation::IInspectable _currentLanguage;
5745
winrt::Windows::Foundation::IInspectable _currentTheme;
5846

5947
void _UpdateThemeList();

src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.idl

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ namespace Microsoft.Terminal.Settings.Editor
1111
{
1212
GlobalAppearanceViewModel(Microsoft.Terminal.Settings.Model.GlobalAppSettings globalSettings);
1313

14-
static String LanguageDisplayConverter(String tag);
15-
Boolean LanguageSelectorAvailable { get; };
16-
Windows.Foundation.Collections.IObservableVector<String> LanguageList { get; };
17-
IInspectable CurrentLanguage;
18-
1914
IInspectable CurrentTheme;
2015
static String ThemeNameConverter(Microsoft.Terminal.Settings.Model.Theme theme);
2116
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Model.Theme> ThemeList { get; };

src/cascadia/TerminalSettingsEditor/Launch.xaml

+23
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,29 @@
139139
</ComboBox>
140140
</local:SettingContainer>
141141

142+
<!-- Language -->
143+
<local:SettingContainer x:Uid="Globals_Language"
144+
Visibility="{x:Bind ViewModel.LanguageSelectorAvailable}">
145+
<ComboBox ItemsSource="{x:Bind ViewModel.LanguageList}"
146+
SelectedItem="{x:Bind ViewModel.CurrentLanguage, Mode=TwoWay}"
147+
Style="{StaticResource ComboBoxSettingStyle}">
148+
<ComboBox.ItemTemplate>
149+
<DataTemplate x:DataType="x:String">
150+
<TextBlock Text="{x:Bind local:LaunchViewModel.LanguageDisplayConverter((x:String))}" />
151+
</DataTemplate>
152+
</ComboBox.ItemTemplate>
153+
</ComboBox>
154+
</local:SettingContainer>
155+
156+
<!-- Language -->
157+
<local:SettingContainer x:Uid="Globals_DefaultInputScope">
158+
<ComboBox AutomationProperties.AccessibilityView="Content"
159+
ItemTemplate="{StaticResource EnumComboBoxTemplate}"
160+
ItemsSource="{x:Bind ViewModel.DefaultInputScopeList}"
161+
SelectedItem="{x:Bind ViewModel.CurrentDefaultInputScope, Mode=TwoWay}"
162+
Style="{StaticResource ComboBoxSettingStyle}" />
163+
</local:SettingContainer>
164+
142165
<!-- Start on User Login -->
143166
<local:SettingContainer x:Uid="Globals_StartOnUserLogin">
144167
<ToggleSwitch IsOn="{x:Bind ViewModel.StartOnUserLogin, Mode=TwoWay}"

0 commit comments

Comments
 (0)