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
7 changes: 6 additions & 1 deletion src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,12 @@ TerminalInput::OutputType Terminal::SendCharEvent(const wchar_t ch, const WORD s
// - none
TerminalInput::OutputType Terminal::FocusChanged(const bool focused)
{
return _getTerminalInput().HandleFocus(focused);
if (_isFocused != focused)
{
_isFocused = focused;
return _getTerminalInput().HandleFocus(focused);
}
return {};
}

// Method Description:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ class Microsoft::Terminal::Core::Terminal final :
til::CoordType _scrollbackLines = 0;
bool _detectURLs = false;
bool _clipboardOperationsAllowed = true;
bool _isFocused = false;

til::size _altBufferSize;
std::optional<til::size> _deferredResize;
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ unsigned int Terminal::GetInputCodePage() const noexcept

void Terminal::CopyToClipboard(wil::zwstring_view content)
{
if (_clipboardOperationsAllowed)
// Only allow VT clipboard writes when the terminal has focus
if (_clipboardOperationsAllowed && _isFocused)
{
_pfnCopyToClipboard(content);
}
Expand Down
8 changes: 7 additions & 1 deletion src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ unsigned int ConhostInternalGetSet::GetInputCodePage() const
// - <none>
void ConhostInternalGetSet::CopyToClipboard(const wil::zwstring_view content)
{
ServiceLocator::LocateGlobals().getConsoleInformation().CopyTextToClipboard(content);
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();

// Only allow VT clipboard writes when the console has focus
if (WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS))
{
gci.CopyTextToClipboard(content);
}
}

// Routine Description:
Expand Down
Loading