Skip to content

Commit 671eb19

Browse files
committed
wip
1 parent 500f413 commit 671eb19

File tree

10 files changed

+353
-450
lines changed

10 files changed

+353
-450
lines changed

src/cascadia/TerminalApp/Tab.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,13 @@ namespace winrt::TerminalApp::implementation
934934
return res;
935935
}
936936

937+
void Tab::Close()
938+
{
939+
ASSERT_UI_THREAD();
940+
941+
Closed.raise(nullptr, nullptr);
942+
}
943+
937944
// Method Description:
938945
// - Prepares this tab for being removed from the UI hierarchy by shutting down all active connections.
939946
void Tab::Shutdown()

src/cascadia/TerminalApp/Tab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace winrt::TerminalApp::implementation
6161
void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);
6262
void UpdateTitle();
6363

64+
void Close();
6465
void Shutdown();
6566
void ClosePane();
6667

src/cascadia/TerminalApp/Tab.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace TerminalApp
2222
UInt32 TabViewNumTabs;
2323

2424
void Focus(Windows.UI.Xaml.FocusState focusState);
25+
void Close();
2526
void Shutdown();
2627

2728
void SetDispatch(ShortcutActionDispatch dispatch);

src/cascadia/TerminalApp/TabManagement.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,11 @@ namespace winrt::TerminalApp::implementation
413413
auto actions = t->BuildStartupActions(BuildStartupKind::None);
414414
_AddPreviouslyClosedPaneOrTab(std::move(actions));
415415

416-
_RemoveTab(tab);
416+
tab.Close();
417417
}
418418

419-
// Method Description:
420-
// - Removes the tab (both TerminalControl and XAML)
421-
// Arguments:
422-
// - tab: the tab to remove
419+
// Removes the tab (both TerminalControl and XAML).
420+
// NOTE: Don't call this directly, but rather `tab.Close()`.
423421
void TerminalPage::_RemoveTab(const winrt::TerminalApp::Tab& tab)
424422
{
425423
uint32_t tabIndex{};

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#include "TerminalPage.h"
77

88
#include <LibraryResources.h>
9+
#include <TerminalCore/ControlKeyStates.hpp>
910
#include <TerminalThemeHelpers.h>
11+
#include <til/hash.h>
1012
#include <Utils.h>
11-
#include <TerminalCore/ControlKeyStates.hpp>
1213

1314
#include "../../types/inc/ColorFix.hpp"
1415
#include "../../types/inc/utils.hpp"
@@ -2571,7 +2572,7 @@ namespace winrt::TerminalApp::implementation
25712572
auto startupActions = tab->BuildStartupActions(BuildStartupKind::Content);
25722573
_DetachTabFromWindow(tab);
25732574
_MoveContent(std::move(startupActions), windowId, 0);
2574-
_RemoveTab(*tab);
2575+
tab.Close();
25752576
if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this))
25762577
{
25772578
const auto tabTitle = tab->Title();
@@ -3614,7 +3615,7 @@ namespace winrt::TerminalApp::implementation
36143615
{
36153616
if (!_tmuxControl)
36163617
{
3617-
_tmuxControl = std::make_unique<TmuxControl>(*this);
3618+
_tmuxControl = std::make_shared<TmuxControl>(*this);
36183619
}
36193620

36203621
control.EnterTmuxControl([tmuxControl = _tmuxControl.get()](auto&& sender, auto&& args) {
@@ -5049,9 +5050,10 @@ namespace winrt::TerminalApp::implementation
50495050
void TerminalPage::_adjustProcessPriority() const
50505051
{
50515052
// Windowing is single-threaded, so this will not cause a race condition.
5052-
static bool supported{ true };
5053+
static uint64_t s_lastUpdateHash{ 0 };
5054+
static bool s_supported{ true };
50535055

5054-
if (!supported || !_hostingHwnd.has_value())
5056+
if (!s_supported || !_hostingHwnd.has_value())
50555057
{
50565058
return;
50575059
}
@@ -5115,11 +5117,20 @@ namespace winrt::TerminalApp::implementation
51155117
}
51165118

51175119
const auto count{ gsl::narrow_cast<DWORD>(it - processes.begin()) };
5120+
const auto hash = til::hash((void*)processes.data(), count * sizeof(HANDLE));
5121+
5122+
if (hash == s_lastUpdateHash)
5123+
{
5124+
return;
5125+
}
5126+
5127+
s_lastUpdateHash = hash;
51185128
const auto hr = TerminalTrySetWindowAssociatedProcesses(_hostingHwnd.value(), count, count ? processes.data() : nullptr);
5129+
51195130
if (S_FALSE == hr)
51205131
{
51215132
// Don't bother trying again or logging. The wrapper tells us it's unsupported.
5122-
supported = false;
5133+
s_supported = false;
51235134
return;
51245135
}
51255136

@@ -5705,7 +5716,7 @@ namespace winrt::TerminalApp::implementation
57055716

57065717
_MoveContent(std::move(startupActions), windowId, tabIndex, dragPoint);
57075718
// _RemoveTab will make sure to null out the _stashed.draggedTab
5708-
_RemoveTab(*_stashed.draggedTab);
5719+
_stashed.draggedTab.Close();
57095720
}
57105721

57115722
/// <summary>

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ namespace winrt::TerminalApp::implementation
257257
std::vector<std::vector<Microsoft::Terminal::Settings::Model::ActionAndArgs>> _previouslyClosedPanesAndTabs{};
258258

259259
uint32_t _systemRowsToScroll{ DefaultRowsToScroll };
260-
std::unique_ptr<TmuxControl> _tmuxControl{ nullptr };
260+
std::shared_ptr<TmuxControl> _tmuxControl{ nullptr };
261261

262262
// use a weak reference to prevent circular dependency with AppLogic
263263
winrt::weak_ref<winrt::TerminalApp::IDialogPresenter> _dialogPresenter;

0 commit comments

Comments
 (0)