Skip to content

Commit

Permalink
When we detach a tab, Close()ing the control shouldn't close the cont…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
zadjii-msft committed Feb 7, 2023
1 parent e288205 commit c9ed8dc
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 35 deletions.
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/ContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ namespace winrt::TerminalApp::implementation
return _content.TryLookup(id);
}

void ContentManager::Detach(const winrt::guid& contentGuid)
void ContentManager::Detach(const Microsoft::Terminal::Control::TermControl& control)
{
const auto contentGuid{ control.ContentGuid() };
if (const auto& content{ LookupCore(contentGuid) })
{
control.Detach();
content.Attached({ get_weak(), &ContentManager::_finalizeDetach });
_recentlyDetachedContent.Insert(contentGuid, content);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/ContentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace winrt::TerminalApp::implementation
Microsoft::Terminal::TerminalConnection::ITerminalConnection connection);
Microsoft::Terminal::Control::ControlInteractivity LookupCore(winrt::guid id);

void Detach(const winrt::guid& contentGuid);
void Detach(const Microsoft::Terminal::Control::TermControl& control);

private:
Windows::Foundation::Collections::IMap<winrt::guid, Microsoft::Terminal::Control::ControlInteractivity> _content{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ namespace winrt::TerminalApp::implementation
rootPane->WalkTree([&](auto p) {
if (const auto& control{ p->GetTerminalControl() })
{
_manager.Detach(control.ContentGuid());
_manager.Detach(control);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace TerminalApp
Microsoft.Terminal.Control.IControlAppearance unfocusedAppearance,
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
Microsoft.Terminal.Control.ControlInteractivity LookupCore(Guid id);
void Detach(Guid id);
void Detach(Microsoft.Terminal.Control.TermControl control);
}

delegate void LastTabClosedEventArgs();
Expand Down
31 changes: 16 additions & 15 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,18 +979,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ControlCore::SizeChanged(const double width,
const double height)
{
// _refreshSizeUnderLock redraws the entire terminal.
// Don't call it if we don't have to.
if (_panelWidth == width && _panelHeight == height)
{
return;
}

_panelWidth = width;
_panelHeight = height;

auto lock = _terminal->LockForWriting();
_refreshSizeUnderLock();
SizeOrScaleChanged(width, height, _compositionScale);
}

void ControlCore::ScaleChanged(const double scale)
Expand All @@ -999,19 +988,31 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
return;
}
SizeOrScaleChanged(_panelWidth, _panelHeight, scale);
}

void ControlCore::SizeOrScaleChanged(const double width,
const double height,
const double scale)
{
// _refreshSizeUnderLock redraws the entire terminal.
// Don't call it if we don't have to.
if (_compositionScale == scale)
if (_panelWidth == width && _panelHeight == height && _compositionScale == scale)
{
return;
}
const auto oldScale = _compositionScale;

_panelWidth = width;
_panelHeight = height;
_compositionScale = scale;

auto lock = _terminal->LockForWriting();
// _updateFont relies on the new _compositionScale set above
_updateFont();
if (oldScale != scale)
{
// _updateFont relies on the new _compositionScale set above
_updateFont();
}
_refreshSizeUnderLock();
}

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void SizeChanged(const double width, const double height);
void ScaleChanged(const double scale);
void SizeOrScaleChanged(const double width, const double height, const double scale);

void AdjustFontSize(float fontSizeDelta);
void ResetFontSize();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace Microsoft.Terminal.Control
void AdjustFontSize(Single fontSizeDelta);
void SizeChanged(Double width, Double height);
void ScaleChanged(Double scale);
void SizeOrScaleChanged(Double width, Double height, Double scale);

void ToggleShaderEffects();
void ToggleReadOnlyMode();
Expand Down
54 changes: 39 additions & 15 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// least we don't need to quick return if the core was already
// initialized - we still have state to set up, and resize the core
// to the new swapchain size, etc.
if (_InitializeTerminal())
if (_InitializeTerminal(false))
{
// Only let this succeed once.
_layoutUpdatedRevoker.revoke();
Expand Down Expand Up @@ -158,12 +158,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const auto term{ winrt::make_self<TermControl>(content) };
term->_AttachDxgiSwapChainToXaml(reinterpret_cast<HANDLE>(term->_core.SwapChainHandle()));
content.Reparent(keyBindings);
// if (const auto h{ reinterpret_cast<HANDLE>(_core.SwapChainHandle()) })
// {
// // Reparent will fire off a _core.CloseTerminalRequested, which the
// // old window will listen to and know to remove its old control,
// // leaving us as the owner.
// }

// Initialize the terminal only once the swapchainpanel is loaded - that
// way, we'll be able to query the real pixel size it got on layout
auto r = term->SwapChainPanel().LayoutUpdated(winrt::auto_revoke, [term](auto /*s*/, auto /*e*/) {
// Replace the normal initialize routine with one that will allow up
// to complete initialization even though the Core was already
// initialized.
if (term->_InitializeTerminal(true))
{
// Only let this succeed once.
term->_layoutUpdatedRevoker.revoke();
}
});
term->_layoutUpdatedRevoker.swap(r);

return *term;
}

Expand Down Expand Up @@ -843,7 +852,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
nativePanel->SetSwapChainHandle(swapChainHandle);
}

bool TermControl::_InitializeTerminal()
bool TermControl::_InitializeTerminal(const bool reattach)
{
if (_initializedTerminal)
{
Expand All @@ -869,14 +878,22 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// the first paint will be ignored!
_core.RendererWarning({ get_weak(), &TermControl::_RendererWarning });

const auto coreInitialized = _core.Initialize(panelWidth,
panelHeight,
panelScaleX);
if (!coreInitialized)
// If we're re-attaching an existing content, then we want to proceed even though the Terminal was already initialized.
if (!reattach)
{
return false;
const auto coreInitialized = _core.Initialize(panelWidth,
panelHeight,
panelScaleX);
if (!coreInitialized)
{
return false;
}
_interactivity.Initialize();
}
else
{
_core.SizeOrScaleChanged(panelWidth, panelHeight, panelScaleX);
}
_interactivity.Initialize();

_core.SwapChainChanged({ get_weak(), &TermControl::RenderEngineSwapChainChanged });
_core.EnablePainting();
Expand Down Expand Up @@ -2037,9 +2054,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
TSFInputControl().Close();
_autoScrollTimer.Stop();

_core.Close();
if (!_detached)
{
_core.Close();
}
}
}
void TermControl::Detach()
{
_detached = true;
}

// Method Description:
// - Scrolls the viewport of the terminal and updates the scroll bar accordingly
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void AdjustOpacity(const double opacity, const bool relative);

void Detach();

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);

// -------------------------------- WinRT Events ---------------------------------
Expand Down Expand Up @@ -222,6 +224,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool _showMarksInScrollbar{ false };

bool _isBackgroundLight{ false };
bool _detached{ false };

inline bool _IsClosing() const noexcept
{
Expand All @@ -247,7 +250,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
static bool _isColorLight(til::color bg) noexcept;
void _changeBackgroundOpacity();

bool _InitializeTerminal();
bool _InitializeTerminal(const bool reattach);
void _SetFontSize(int fontSize);
void _TappedHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& e);
void _KeyDownHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& e);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ namespace Microsoft.Terminal.Control
Windows.UI.Xaml.Media.Brush BackgroundBrush { get; };

void ColorSelection(SelectionColor fg, SelectionColor bg, Microsoft.Terminal.Core.MatchMode matchMode);

void Detach();
}
}

1 comment on commit c9ed8dc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (9)

Acn
APeasant
connectecd
onarch
taht
tearout
TOODO
unzoom
wehn

Previously acknowledged words that are now absent CLA demoable everytime Hirots inthread reingest unmark :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/migrie/oop/3/quenta-silmarillion branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/4116515723/attempts/1'
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.