Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spelling/allow/microsoft.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ wtl
wtt
wttlog
Xamarin
XBOX
xfgcheck
34 changes: 34 additions & 0 deletions src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ namespace winrt::TerminalApp::implementation
}
});

// BODGY: Work around a fail-fast crash in WinUI 2's TabView. When a
// game controller (e.g. an XBOX controller's d-pad/stick) moves focus
// Up or Down between two TabViewItems, MUX's TabView::OnListViewGettingFocus
// runs a GameController-only code path that calls
// DispatcherQueue.TryEnqueue, which fails with E_INVALIDARG. That
// unhandled error inside a GettingFocus callback makes XAML fail-fast,
// and the whole window vanishes. See
// microsoft-ui-xaml/blob/840c6cd4ac9d16d9aa99b24f0bd43997fe21bef8/dev/TabView/TabView.cpp#L246
//
// This GettingFocus handler is on the TabViewItem, which is closer to
// the focus source than the TabViewListView that MUX's handler lives
// on, so it runs first. Marking the event Handled - and cancelling the
// focus move, which is exactly what MUX itself does for the keyboard
// case - preempts MUX's broken handler. Keyboard navigation is left
// untouched; MUX handles that path safely.
TabViewItem().GettingFocus([](auto&&, const winrt::WUX::Input::GettingFocusEventArgs& args) {
const auto direction{ args.Direction() };
if (direction != winrt::WUX::Input::FocusNavigationDirection::Up &&
direction != winrt::WUX::Input::FocusNavigationDirection::Down)
{
return;
}
if (args.InputDevice() != winrt::WUX::Input::FocusInputDeviceKind::GameController)
{
return;
}
if (args.OldFocusedElement().try_as<winrt::MUX::Controls::TabViewItem>() &&
args.NewFocusedElement().try_as<winrt::MUX::Controls::TabViewItem>())
{
args.Cancel(true);
args.Handled(true);
}
});

UpdateTitle();
_RecalculateAndApplyTabColor();
}
Expand Down
Loading