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.
This commit is contained in:
Leonard Hecker
2025-12-17 17:50:32 +01:00
committed by GitHub
parent 5f6b814057
commit a331c42d3c

View File

@@ -5,10 +5,14 @@
#include "pch.h"
#include "TerminalPage.h"
#include <TerminalThemeHelpers.h>
#include <Utils.h>
#include <TerminalCore/ControlKeyStates.hpp>
#include <TerminalThemeHelpers.h>
#include <til/hash.h>
#include <Utils.h>
#include "../../types/inc/ColorFix.hpp"
#include "../../types/inc/utils.hpp"
#include "../TerminalSettingsAppAdapterLib/TerminalSettings.h"
#include "App.h"
#include "DebugTapConnection.h"
#include "MarkdownPaneContent.h"
@@ -18,9 +22,6 @@
#include "SnippetsPaneContent.h"
#include "TabRowControl.h"
#include "TerminalSettingsCache.h"
#include "../../types/inc/ColorFix.hpp"
#include "../../types/inc/utils.hpp"
#include "../TerminalSettingsAppAdapterLib/TerminalSettings.h"
#include "LaunchPositionRequest.g.cpp"
#include "RenameWindowRequestedArgs.g.cpp"
@@ -5000,9 +5001,10 @@ namespace winrt::TerminalApp::implementation
void TerminalPage::_adjustProcessPriority() const
{
// Windowing is single-threaded, so this will not cause a race condition.
static bool supported{ true };
static uint64_t s_lastUpdateHash{ 0 };
static bool s_supported{ true };
if (!supported || !_hostingHwnd.has_value())
if (!s_supported || !_hostingHwnd.has_value())
{
return;
}
@@ -5066,11 +5068,20 @@ namespace winrt::TerminalApp::implementation
}
const auto count{ gsl::narrow_cast<DWORD>(it - processes.begin()) };
const auto hash = til::hash((void*)processes.data(), count * sizeof(HANDLE));
if (hash == s_lastUpdateHash)
{
return;
}
s_lastUpdateHash = hash;
const auto hr = TerminalTrySetWindowAssociatedProcesses(_hostingHwnd.value(), count, count ? processes.data() : nullptr);
if (S_FALSE == hr)
{
// Don't bother trying again or logging. The wrapper tells us it's unsupported.
supported = false;
s_supported = false;
return;
}