Skip to content

Commit

Permalink
Set tab title as early as possible (#6433)
Browse files Browse the repository at this point in the history
When opening a new tab, it takes a few milliseconds before title to
appears. This PR makes it instantaneous.

* Updated the Terminal so that it can load the title from the settings
  before it is initialized.
* Load terminal settings in TermControl constructor before the terminal
  is initialized (see above).
* Update Tab so that it sets the TabViewItem's title in the constructor
  (in Tab::_MakeTabViewItem) instead of waiting for the VT sequence to
  set the title (from what I understand).

NOTE 1: there is a similar problem with the tabview icon which is not
fixed by this PR.

NOTE 2: This is only a problem with animations disabled because
otherwise the title fades in so there is enough time for it to be set
when it becomes visible.

## Validation

I ran the terminal and opened a new tab. The title appears instantly.

(cherry picked from commit f9b1238)
  • Loading branch information
1kjo authored and DHowett committed Jun 24, 2020
1 parent a4d6ad2 commit f2e90ce
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace winrt::TerminalApp::implementation
void Tab::_MakeTabViewItem()
{
_tabViewItem = ::winrt::MUX::Controls::TabViewItem{};
_UpdateTitle();
}

// Method Description:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
auto inputFn = std::bind(&TermControl::_SendInputToConnection, this, std::placeholders::_1);
_terminal->SetWriteInputCallback(inputFn);

_terminal->UpdateSettings(settings);

// Subscribe to the connection's disconnected event and call our connection closed handlers.
_connectionStateChangedRevoker = _connection.StateChanged(winrt::auto_revoke, [this](auto&& /*s*/, auto&& /*v*/) {
_ConnectionStateChangedHandlers(*this, nullptr);
Expand Down
14 changes: 6 additions & 8 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ void Terminal::CreateFromSettings(winrt::Microsoft::Terminal::Settings::ICoreSet
Create(viewportSize, Utils::ClampToShortMax(settings.HistorySize(), 0), renderTarget);

UpdateSettings(settings);

if (_suppressApplicationTitle)
{
_title = _startingTitle;
}
}

// Method Description:
Expand Down Expand Up @@ -130,9 +125,12 @@ void Terminal::UpdateSettings(winrt::Microsoft::Terminal::Settings::ICoreSetting
break;
}

_buffer->GetCursor().SetStyle(settings.CursorHeight(),
settings.CursorColor(),
cursorShape);
if (_buffer)
{
_buffer->GetCursor().SetStyle(settings.CursorHeight(),
settings.CursorColor(),
cursorShape);
}

for (int i = 0; i < 16; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Microsoft::Terminal::Core::Terminal final :
std::unique_ptr<::Microsoft::Console::VirtualTerminal::StateMachine> _stateMachine;
std::unique_ptr<::Microsoft::Console::VirtualTerminal::TerminalInput> _terminalInput;

std::wstring _title;
std::optional<std::wstring> _title;
std::wstring _startingTitle;

std::array<COLORREF, XTERM_COLOR_TABLE_SIZE> _colorTable;
Expand Down
9 changes: 5 additions & 4 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,11 @@ CATCH_LOG_RETURN_FALSE()
bool Terminal::SetWindowTitle(std::wstring_view title) noexcept
try
{
_title = _suppressApplicationTitle ? _startingTitle : title;

_pfnTitleChanged(_title);

if (!_suppressApplicationTitle)
{
_title.emplace(title);
_pfnTitleChanged(_title.value());
}
return true;
}
CATCH_LOG_RETURN_FALSE()
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalCore/terminalrenderdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ void Terminal::SelectNewRegion(const COORD coordStart, const COORD coordEnd)
const std::wstring Terminal::GetConsoleTitle() const noexcept
try
{
return _title;
if (_title.has_value())
{
return _title.value();
}
return _startingTitle;
}
catch (...)
{
Expand Down

0 comments on commit f2e90ce

Please sign in to comment.