Skip to content

Commit bf8d0b5

Browse files
lheckerDHowett
authored andcommitted
Avoid animations during startup
1 parent da0a6d4 commit bf8d0b5

File tree

9 files changed

+235
-169
lines changed

9 files changed

+235
-169
lines changed

src/cascadia/TerminalApp/App.xaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<Application x:Class="TerminalApp.App"
66
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
77
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
8-
xmlns:TA="using:TerminalApp"
98
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
109
xmlns:local="using:TerminalApp"
1110
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11+
xmlns:primitives="using:Microsoft.UI.Xaml.Controls.Primitives"
1212
mc:Ignorable="d">
1313
<!--
1414
If you want to prove this works, then add `RequestedTheme="Light"` to
@@ -48,6 +48,23 @@
4848
<Thickness x:Key="TabViewHeaderPadding">9,0,5,0</Thickness>
4949
<Thickness x:Key="TabViewItemBorderThickness">1,1,1,0</Thickness>
5050

51+
<!--
52+
Disable the EntranceThemeTransition for our muxc:TabView, which would slowly slide in the tabs
53+
while the window opens. The difference is especially noticeable if window fade-in transitions are
54+
disabled system-wide. On my system this shaves off about 10% of the startup cost and looks better.
55+
-->
56+
<Style TargetType="primitives:TabViewListView">
57+
<Setter Property="ItemContainerTransitions">
58+
<Setter.Value>
59+
<TransitionCollection>
60+
<AddDeleteThemeTransition />
61+
<ContentThemeTransition />
62+
<ReorderThemeTransition />
63+
</TransitionCollection>
64+
</Setter.Value>
65+
</Setter>
66+
</Style>
67+
5168
<!-- Shadow that can be used by any control. -->
5269
<ThemeShadow x:Name="SharedShadow" />
5370

src/cascadia/TerminalApp/SettingsTab.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace winrt
2121
namespace WUX = Windows::UI::Xaml;
2222
}
2323

24+
#define ASSERT_UI_THREAD() assert(TabViewItem().Dispatcher().HasThreadAccess())
25+
2426
namespace winrt::TerminalApp::implementation
2527
{
2628
SettingsTab::SettingsTab(MainPage settingsUI,
@@ -36,6 +38,8 @@ namespace winrt::TerminalApp::implementation
3638

3739
void SettingsTab::UpdateSettings(CascadiaSettings settings)
3840
{
41+
ASSERT_UI_THREAD();
42+
3943
auto settingsUI{ Content().as<MainPage>() };
4044
settingsUI.UpdateSettings(settings);
4145

@@ -55,6 +59,8 @@ namespace winrt::TerminalApp::implementation
5559
// - The list of actions.
5660
std::vector<ActionAndArgs> SettingsTab::BuildStartupActions(const bool /*asContent*/) const
5761
{
62+
ASSERT_UI_THREAD();
63+
5864
ActionAndArgs action;
5965
action.Action(ShortcutAction::OpenSettings);
6066
OpenSettingsArgs args{ SettingsTarget::SettingsUI };
@@ -71,6 +77,8 @@ namespace winrt::TerminalApp::implementation
7177
// - <none>
7278
void SettingsTab::Focus(WUX::FocusState focusState)
7379
{
80+
ASSERT_UI_THREAD();
81+
7482
_focusState = focusState;
7583

7684
if (_focusState != FocusState::Unfocused)
@@ -99,20 +107,14 @@ namespace winrt::TerminalApp::implementation
99107
// - <none>
100108
// Return Value:
101109
// - <none>
102-
winrt::fire_and_forget SettingsTab::_CreateIcon()
110+
void SettingsTab::_CreateIcon()
103111
{
104-
auto weakThis{ get_weak() };
112+
// This is the Setting icon (looks like a gear)
113+
static constexpr std::wstring_view glyph{ L"\xE713" };
105114

106-
co_await wil::resume_foreground(TabViewItem().Dispatcher());
107-
108-
if (auto tab{ weakThis.get() })
109-
{
110-
auto glyph = L"\xE713"; // This is the Setting icon (looks like a gear)
111-
112-
// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
113-
Icon(glyph);
114-
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(glyph));
115-
}
115+
// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
116+
Icon(winrt::hstring{ glyph });
117+
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(glyph));
116118
}
117119

118120
winrt::Windows::UI::Xaml::Media::Brush SettingsTab::_BackgroundBrush()

src/cascadia/TerminalApp/SettingsTab.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace winrt::TerminalApp::implementation
3636
winrt::Windows::UI::Xaml::ElementTheme _requestedTheme;
3737

3838
void _MakeTabViewItem() override;
39-
winrt::fire_and_forget _CreateIcon();
39+
void _CreateIcon();
4040

4141
virtual winrt::Windows::UI::Xaml::Media::Brush _BackgroundBrush() override;
4242
};

src/cascadia/TerminalApp/TabBase.cpp

+42-48
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace winrt
2121
namespace WUX = Windows::UI::Xaml;
2222
}
2323

24+
#define ASSERT_UI_THREAD() assert(TabViewItem().Dispatcher().HasThreadAccess())
25+
2426
namespace winrt::TerminalApp::implementation
2527
{
2628
WUX::FocusState TabBase::FocusState() const noexcept
@@ -32,6 +34,8 @@ namespace winrt::TerminalApp::implementation
3234
// - Prepares this tab for being removed from the UI hierarchy
3335
void TabBase::Shutdown()
3436
{
37+
ASSERT_UI_THREAD();
38+
3539
Content(nullptr);
3640
_ClosedHandlers(nullptr, nullptr);
3741
}
@@ -159,6 +163,8 @@ namespace winrt::TerminalApp::implementation
159163

160164
void TabBase::UpdateTabViewIndex(const uint32_t idx, const uint32_t numTabs)
161165
{
166+
ASSERT_UI_THREAD();
167+
162168
TabViewIndex(idx);
163169
TabViewNumTabs(numTabs);
164170
_EnableCloseMenuItems();
@@ -167,11 +173,15 @@ namespace winrt::TerminalApp::implementation
167173

168174
void TabBase::SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch)
169175
{
176+
ASSERT_UI_THREAD();
177+
170178
_dispatch = dispatch;
171179
}
172180

173181
void TabBase::SetActionMap(const Microsoft::Terminal::Settings::Model::IActionMapView& actionMap)
174182
{
183+
ASSERT_UI_THREAD();
184+
175185
_actionMap = actionMap;
176186
_UpdateSwitchToTabKeyChord();
177187
}
@@ -183,26 +193,18 @@ namespace winrt::TerminalApp::implementation
183193
// - keyChord - string representation of the key chord that switches to the current tab
184194
// Return Value:
185195
// - <none>
186-
winrt::fire_and_forget TabBase::_UpdateSwitchToTabKeyChord()
196+
void TabBase::_UpdateSwitchToTabKeyChord()
187197
{
188198
const auto keyChord = _actionMap ? _actionMap.GetKeyBindingForAction(ShortcutAction::SwitchToTab, SwitchToTabArgs{ _TabViewIndex }) : nullptr;
189199
const auto keyChordText = keyChord ? KeyChordSerialization::ToString(keyChord) : L"";
190200

191201
if (_keyChord == keyChordText)
192202
{
193-
co_return;
203+
return;
194204
}
195205

196206
_keyChord = keyChordText;
197-
198-
auto weakThis{ get_weak() };
199-
200-
co_await wil::resume_foreground(TabViewItem().Dispatcher());
201-
202-
if (auto tab{ weakThis.get() })
203-
{
204-
_UpdateToolTip();
205-
}
207+
_UpdateToolTip();
206208
}
207209

208210
// Method Description:
@@ -281,13 +283,17 @@ namespace winrt::TerminalApp::implementation
281283

282284
std::optional<winrt::Windows::UI::Color> TabBase::GetTabColor()
283285
{
286+
ASSERT_UI_THREAD();
287+
284288
return std::nullopt;
285289
}
286290

287291
void TabBase::ThemeColor(const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& focused,
288292
const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& unfocused,
289293
const til::color& tabRowColor)
290294
{
295+
ASSERT_UI_THREAD();
296+
291297
_themeColor = focused;
292298
_unfocusedThemeColor = unfocused;
293299
_tabRowColor = tabRowColor;
@@ -305,49 +311,37 @@ namespace winrt::TerminalApp::implementation
305311
// - <none>
306312
void TabBase::_RecalculateAndApplyTabColor()
307313
{
308-
auto weakThis{ get_weak() };
309-
310-
TabViewItem().Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [weakThis]() {
311-
auto ptrTab = weakThis.get();
312-
if (!ptrTab)
313-
{
314-
return;
315-
}
316-
317-
auto tab{ ptrTab };
314+
// GetTabColor will return the color set by the color picker, or the
315+
// color specified in the profile. If neither of those were set,
316+
// then look to _themeColor to see if there's a value there.
317+
// Otherwise, clear our color, falling back to the TabView defaults.
318+
const auto currentColor = GetTabColor();
319+
if (currentColor.has_value())
320+
{
321+
_ApplyTabColorOnUIThread(currentColor.value());
322+
}
323+
else if (_themeColor != nullptr)
324+
{
325+
// Safely get the active control's brush.
326+
const Media::Brush terminalBrush{ _BackgroundBrush() };
318327

319-
// GetTabColor will return the color set by the color picker, or the
320-
// color specified in the profile. If neither of those were set,
321-
// then look to _themeColor to see if there's a value there.
322-
// Otherwise, clear our color, falling back to the TabView defaults.
323-
const auto currentColor = tab->GetTabColor();
324-
if (currentColor.has_value())
328+
if (const auto themeBrush{ _themeColor.Evaluate(Application::Current().Resources(), terminalBrush, false) })
325329
{
326-
tab->_ApplyTabColorOnUIThread(currentColor.value());
327-
}
328-
else if (tab->_themeColor != nullptr)
329-
{
330-
// Safely get the active control's brush.
331-
const Media::Brush terminalBrush{ tab->_BackgroundBrush() };
332-
333-
if (const auto themeBrush{ tab->_themeColor.Evaluate(Application::Current().Resources(), terminalBrush, false) })
334-
{
335-
// ThemeColor.Evaluate will get us a Brush (because the
336-
// TermControl could have an acrylic BG, for example). Take
337-
// that brush, and get the color out of it. We don't really
338-
// want to have the tab items themselves be acrylic.
339-
tab->_ApplyTabColorOnUIThread(til::color{ ThemeColor::ColorFromBrush(themeBrush) });
340-
}
341-
else
342-
{
343-
tab->_ClearTabBackgroundColor();
344-
}
330+
// ThemeColor.Evaluate will get us a Brush (because the
331+
// TermControl could have an acrylic BG, for example). Take
332+
// that brush, and get the color out of it. We don't really
333+
// want to have the tab items themselves be acrylic.
334+
_ApplyTabColorOnUIThread(til::color{ ThemeColor::ColorFromBrush(themeBrush) });
345335
}
346336
else
347337
{
348-
tab->_ClearTabBackgroundColor();
338+
_ClearTabBackgroundColor();
349339
}
350-
});
340+
}
341+
else
342+
{
343+
_ClearTabBackgroundColor();
344+
}
351345
}
352346

353347
// Method Description:

src/cascadia/TerminalApp/TabBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace winrt::TerminalApp::implementation
6969
void _EnableCloseMenuItems();
7070
void _CloseTabsAfter();
7171
void _CloseOtherTabs();
72-
winrt::fire_and_forget _UpdateSwitchToTabKeyChord();
72+
void _UpdateSwitchToTabKeyChord();
7373
void _UpdateToolTip();
7474

7575
void _RecalculateAndApplyTabColor();

0 commit comments

Comments
 (0)