Skip to content

Commit

Permalink
cherry-pick 479c6c9
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 31, 2022
1 parent 9dd1649 commit 1a1caf9
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

void ControlCore::GotFocus()
{
_connection.WriteInput(L"\x1b[I");
}

void ControlCore::LostFocus()
{
_connection.WriteInput(L"\x1b[O");
}

bool ControlCore::_isBackgroundTransparent()
{
// If we're:
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void PasteText(const winrt::hstring& hstr);
bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats);

void GotFocus();
void LostFocus();

void ToggleShaderEffects();
void AdjustOpacity(const double adjustment);
void ResumeRendering();
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
THROW_IF_FAILED(_uiaEngine->Enable());
}

_core->GotFocus();

_updateSystemParameterSettings();
}

Expand All @@ -120,6 +122,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
THROW_IF_FAILED(_uiaEngine->Disable());
}

_core->LostFocus();
}

// Method Description
Expand Down
7 changes: 7 additions & 0 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,10 @@ void ConhostInternalGetSet::UpdateSoftFont(const gsl::span<const uint16_t> bitPa
pRender->UpdateSoftFont(bitPattern, cellSize, centeringHint);
}
}

void ConhostInternalGetSet::FocusChanged(const bool focused)
{
auto& g = ServiceLocator::LocateGlobals();
auto& gci = g.getConsoleInformation();
gci.ProcessHandleList.ModifyConsoleProcessFocus(focused);
}
2 changes: 2 additions & 0 deletions src/host/outputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal::
const SIZE cellSize,
const size_t centeringHint) override;

void FocusChanged(const bool focused) override;

private:
void _modifyLines(const size_t count, const bool insert);

Expand Down
4 changes: 3 additions & 1 deletion src/server/IoDispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
return pReceiveMsg;
}

gci.ProcessHandleList.ModifyConsoleProcessFocus(WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS));
const bool hasFocus{ WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS) };
const auto grantFG{ hasFocus };
gci.ProcessHandleList.ModifyConsoleProcessFocus(grantFG);

// Create the handles.

Expand Down
3 changes: 2 additions & 1 deletion src/terminal/adapter/InteractDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ bool InteractDispatch::IsVtInputEnabled() const

bool InteractDispatch::FocusChanged(const bool focused) const
{
// * TODO!: plumb through to conapi and then gci.ProcessHandleList.ModifyConsoleProcessFocus(focused);
// * We should assume this is false by default?
// * TODO!: ConPTY should ask for this mode? Yea? Lets make sure that VTE will send that sequence even without other mouse sequences enabled.
// - in the past, this is something we've made opt-in (request cursor, for example. Maybe also the other mouse modes, can't recall)
// * gotta make sure that we can always handle the focus events, even if the client hasn't requested them.
_pConApi->FocusChanged(focused);
return true;
}
2 changes: 2 additions & 0 deletions src/terminal/adapter/conGetSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@ namespace Microsoft::Console::VirtualTerminal
virtual void UpdateSoftFont(const gsl::span<const uint16_t> bitPattern,
const SIZE cellSize,
const size_t centeringHint) = 0;

virtual void FocusChanged(const bool focused) = 0;
};
}

0 comments on commit 1a1caf9

Please sign in to comment.