Skip to content

Commit a331c42

Browse files
authored
Prevent redundant SetWindowAssociatedProcesses calls (#19658)
This is just an idea. Tmux tabs don't have any associated processes, so switching between them would raise debug logs all the time. Not really an issue per se, so I'd be happy to just close this PR.
1 parent 5f6b814 commit a331c42

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/cascadia/TerminalApp/TerminalPage.cpp

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

8+
#include <TerminalCore/ControlKeyStates.hpp>
89
#include <TerminalThemeHelpers.h>
10+
#include <til/hash.h>
911
#include <Utils.h>
10-
#include <TerminalCore/ControlKeyStates.hpp>
1112

13+
#include "../../types/inc/ColorFix.hpp"
14+
#include "../../types/inc/utils.hpp"
15+
#include "../TerminalSettingsAppAdapterLib/TerminalSettings.h"
1216
#include "App.h"
1317
#include "DebugTapConnection.h"
1418
#include "MarkdownPaneContent.h"
@@ -18,9 +22,6 @@
1822
#include "SnippetsPaneContent.h"
1923
#include "TabRowControl.h"
2024
#include "TerminalSettingsCache.h"
21-
#include "../../types/inc/ColorFix.hpp"
22-
#include "../../types/inc/utils.hpp"
23-
#include "../TerminalSettingsAppAdapterLib/TerminalSettings.h"
2425

2526
#include "LaunchPositionRequest.g.cpp"
2627
#include "RenameWindowRequestedArgs.g.cpp"
@@ -5000,9 +5001,10 @@ namespace winrt::TerminalApp::implementation
50005001
void TerminalPage::_adjustProcessPriority() const
50015002
{
50025003
// Windowing is single-threaded, so this will not cause a race condition.
5003-
static bool supported{ true };
5004+
static uint64_t s_lastUpdateHash{ 0 };
5005+
static bool s_supported{ true };
50045006

5005-
if (!supported || !_hostingHwnd.has_value())
5007+
if (!s_supported || !_hostingHwnd.has_value())
50065008
{
50075009
return;
50085010
}
@@ -5066,11 +5068,20 @@ namespace winrt::TerminalApp::implementation
50665068
}
50675069

50685070
const auto count{ gsl::narrow_cast<DWORD>(it - processes.begin()) };
5071+
const auto hash = til::hash((void*)processes.data(), count * sizeof(HANDLE));
5072+
5073+
if (hash == s_lastUpdateHash)
5074+
{
5075+
return;
5076+
}
5077+
5078+
s_lastUpdateHash = hash;
50695079
const auto hr = TerminalTrySetWindowAssociatedProcesses(_hostingHwnd.value(), count, count ? processes.data() : nullptr);
5080+
50705081
if (S_FALSE == hr)
50715082
{
50725083
// Don't bother trying again or logging. The wrapper tells us it's unsupported.
5073-
supported = false;
5084+
s_supported = false;
50745085
return;
50755086
}
50765087

0 commit comments

Comments
 (0)