@@ -21,6 +21,8 @@ namespace winrt
21
21
namespace WUX = Windows::UI::Xaml;
22
22
}
23
23
24
+ #define ASSERT_UI_THREAD () assert(TabViewItem().Dispatcher().HasThreadAccess())
25
+
24
26
namespace winrt ::TerminalApp::implementation
25
27
{
26
28
WUX::FocusState TabBase::FocusState () const noexcept
@@ -32,6 +34,8 @@ namespace winrt::TerminalApp::implementation
32
34
// - Prepares this tab for being removed from the UI hierarchy
33
35
void TabBase::Shutdown ()
34
36
{
37
+ ASSERT_UI_THREAD ();
38
+
35
39
Content (nullptr );
36
40
_ClosedHandlers (nullptr , nullptr );
37
41
}
@@ -159,6 +163,8 @@ namespace winrt::TerminalApp::implementation
159
163
160
164
void TabBase::UpdateTabViewIndex (const uint32_t idx, const uint32_t numTabs)
161
165
{
166
+ ASSERT_UI_THREAD ();
167
+
162
168
TabViewIndex (idx);
163
169
TabViewNumTabs (numTabs);
164
170
_EnableCloseMenuItems ();
@@ -167,11 +173,15 @@ namespace winrt::TerminalApp::implementation
167
173
168
174
void TabBase::SetDispatch (const winrt::TerminalApp::ShortcutActionDispatch& dispatch)
169
175
{
176
+ ASSERT_UI_THREAD ();
177
+
170
178
_dispatch = dispatch;
171
179
}
172
180
173
181
void TabBase::SetActionMap (const Microsoft::Terminal::Settings::Model::IActionMapView& actionMap)
174
182
{
183
+ ASSERT_UI_THREAD ();
184
+
175
185
_actionMap = actionMap;
176
186
_UpdateSwitchToTabKeyChord ();
177
187
}
@@ -183,26 +193,18 @@ namespace winrt::TerminalApp::implementation
183
193
// - keyChord - string representation of the key chord that switches to the current tab
184
194
// Return Value:
185
195
// - <none>
186
- winrt::fire_and_forget TabBase::_UpdateSwitchToTabKeyChord ()
196
+ void TabBase::_UpdateSwitchToTabKeyChord ()
187
197
{
188
198
const auto keyChord = _actionMap ? _actionMap.GetKeyBindingForAction (ShortcutAction::SwitchToTab, SwitchToTabArgs{ _TabViewIndex }) : nullptr ;
189
199
const auto keyChordText = keyChord ? KeyChordSerialization::ToString (keyChord) : L" " ;
190
200
191
201
if (_keyChord == keyChordText)
192
202
{
193
- co_return ;
203
+ return ;
194
204
}
195
205
196
206
_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 ();
206
208
}
207
209
208
210
// Method Description:
@@ -281,13 +283,17 @@ namespace winrt::TerminalApp::implementation
281
283
282
284
std::optional<winrt::Windows::UI::Color> TabBase::GetTabColor ()
283
285
{
286
+ ASSERT_UI_THREAD ();
287
+
284
288
return std::nullopt;
285
289
}
286
290
287
291
void TabBase::ThemeColor (const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& focused,
288
292
const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& unfocused,
289
293
const til::color& tabRowColor)
290
294
{
295
+ ASSERT_UI_THREAD ();
296
+
291
297
_themeColor = focused;
292
298
_unfocusedThemeColor = unfocused;
293
299
_tabRowColor = tabRowColor;
@@ -305,49 +311,37 @@ namespace winrt::TerminalApp::implementation
305
311
// - <none>
306
312
void TabBase::_RecalculateAndApplyTabColor ()
307
313
{
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 () };
318
327
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 ) })
325
329
{
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) });
345
335
}
346
336
else
347
337
{
348
- tab-> _ClearTabBackgroundColor ();
338
+ _ClearTabBackgroundColor ();
349
339
}
350
- });
340
+ }
341
+ else
342
+ {
343
+ _ClearTabBackgroundColor ();
344
+ }
351
345
}
352
346
353
347
// Method Description:
0 commit comments