mirror of
https://github.com/microsoft/terminal.git
synced 2026-07-09 02:26:45 +00:00
When we detach a tab, Close()ing the control shouldn't close the content.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -843,7 +852,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
nativePanel->SetSwapChainHandle(swapChainHandle);
|
||||
}
|
||||
|
||||
bool TermControl::_InitializeTerminal()
|
||||
bool TermControl::_InitializeTerminal(const bool reattach)
|
||||
{
|
||||
if (_initializedTerminal)
|
||||
{
|
||||
@@ -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();
|
||||
@@ -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
|
||||
|
||||
@@ -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 ---------------------------------
|
||||
@@ -222,6 +224,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
bool _showMarksInScrollbar{ false };
|
||||
|
||||
bool _isBackgroundLight{ false };
|
||||
bool _detached{ false };
|
||||
|
||||
inline bool _IsClosing() const noexcept
|
||||
{
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user