From 6789ec0765f65635c02eacde9a109ca5be74a404 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Mar 2024 13:34:35 -0500 Subject: [PATCH 1/6] some of the easier nits --- src/cascadia/TerminalApp/Pane.cpp | 3 +++ src/cascadia/TerminalApp/Pane.h | 13 +++++++++++++ src/cascadia/TerminalApp/PaneArgs.cpp | 6 ------ src/cascadia/TerminalApp/PaneArgs.h | 18 ------------------ src/cascadia/TerminalApp/TerminalPage.cpp | 14 +++++++------- src/cascadia/TerminalApp/TerminalPaneContent.h | 4 +--- src/cascadia/TerminalApp/TerminalTab.cpp | 2 +- 7 files changed, 25 insertions(+), 35 deletions(-) delete mode 100644 src/cascadia/TerminalApp/PaneArgs.cpp delete mode 100644 src/cascadia/TerminalApp/PaneArgs.h diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 22927afdd38..90ec59719f6 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -3,6 +3,9 @@ #include "pch.h" #include "Pane.h" + +#include "BellEventArgs.g.cpp" + #include "AppLogic.h" #include "Utils.h" diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index ec4754c1373..f8f059bb053 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -22,6 +22,7 @@ #include "TaskbarState.h" #include "TerminalPaneContent.h" +#include "BellEventArgs.g.h" // fwdecl unittest classes namespace TerminalAppLocalTests @@ -59,6 +60,18 @@ struct PaneResources winrt::Windows::UI::Xaml::Media::SolidColorBrush broadcastBorderBrush{ nullptr }; }; +namespace winrt::TerminalApp::implementation +{ + struct BellEventArgs : public BellEventArgsT + { + public: + BellEventArgs(bool flashTaskbar) : + FlashTaskbar(flashTaskbar) {} + + til::property FlashTaskbar; + }; +}; + class Pane : public std::enable_shared_from_this { public: diff --git a/src/cascadia/TerminalApp/PaneArgs.cpp b/src/cascadia/TerminalApp/PaneArgs.cpp deleted file mode 100644 index 2b5beddb8b5..00000000000 --- a/src/cascadia/TerminalApp/PaneArgs.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#include "pch.h" -#include "PaneArgs.h" -#include "BellEventArgs.g.cpp" diff --git a/src/cascadia/TerminalApp/PaneArgs.h b/src/cascadia/TerminalApp/PaneArgs.h deleted file mode 100644 index 5627623be9e..00000000000 --- a/src/cascadia/TerminalApp/PaneArgs.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#pragma once - -#include "BellEventArgs.g.h" - -namespace winrt::TerminalApp::implementation -{ - struct BellEventArgs : public BellEventArgsT - { - public: - BellEventArgs(bool flashTaskbar) : - FlashTaskbar(flashTaskbar) {} - - til::property FlashTaskbar; - }; -}; diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 19c486b13a3..5fc8f121f31 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -3125,8 +3125,8 @@ namespace winrt::TerminalApp::implementation // serialize the actual profile's GUID along with the content guid. const auto& profile = _settings.GetProfileForArgs(newTerminalArgs); const auto control = _AttachControlToContent(newTerminalArgs.ContentId()); - auto terminalPane{ winrt::make(profile, control) }; - return std::make_shared(terminalPane); + auto paneContent{ winrt::make(profile, control) }; + return std::make_shared(paneContent); } TerminalSettingsCreateResult controlSettings{ nullptr }; @@ -3182,15 +3182,15 @@ namespace winrt::TerminalApp::implementation const auto control = _CreateNewControlAndContent(controlSettings, connection); - auto terminalPane{ winrt::make(profile, control) }; - auto resultPane = std::make_shared(terminalPane); + auto paneContent{ winrt::make(profile, control) }; + auto resultPane = std::make_shared(paneContent); if (debugConnection) // this will only be set if global debugging is on and tap is active { auto newControl = _CreateNewControlAndContent(controlSettings, debugConnection); // Split (auto) with the debug tap. - auto debugTerminalPane{ winrt::make(profile, newControl) }; - auto debugPane = std::make_shared(debugTerminalPane); + auto debugContent{ winrt::make(profile, newControl) }; + auto debugPane = std::make_shared(debugContent); // Since we're doing this split directly on the pane (instead of going through TerminalTab, // we need to handle the panes 'active' states @@ -3204,7 +3204,7 @@ namespace winrt::TerminalApp::implementation original->SetActive(); } - _RegisterPaneEvents(terminalPane); + _RegisterPaneEvents(paneContent); return resultPane; } diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h index 2d26e5b1924..0b6c968f4cc 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.h +++ b/src/cascadia/TerminalApp/TerminalPaneContent.h @@ -3,8 +3,6 @@ #pragma once #include "TerminalPaneContent.g.h" -#include "../../cascadia/inc/cppwinrt_utils.h" -#include namespace winrt::TerminalApp::implementation { @@ -29,7 +27,7 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::Settings::Model::Profile GetProfile() const { return _profile; - }; + } winrt::hstring Title() { return _control.Title(); } uint64_t TaskbarState() { return _control.TaskbarState(); } diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 66800ed7388..86be96b6204 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -930,7 +930,7 @@ namespace winrt::TerminalApp::implementation events.CloseRequested = content.CloseRequested( winrt::auto_revoke, [dispatcher, weakThis](auto sender, auto&&) -> winrt::fire_and_forget { - // Don't forget! this ^^^^^^^^ sender can't be a reference, this is a async callback. + // Don't forget! this ^^^^^^^^ sender can't be a reference, this is a async callback. // The lambda lives in the `std::function`-style container owned by `control`. That is, when the // `control` gets destroyed the lambda struct also gets destroyed. In other words, we need to From fd8b083a4693451523ef8999e51bd6eed7a55e27 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Mar 2024 13:55:11 -0500 Subject: [PATCH 2/6] get rid of this file --- src/cascadia/TerminalApp/IPaneContent.idl | 4 ++-- src/cascadia/TerminalApp/Pane.cpp | 12 ++++-------- src/cascadia/TerminalApp/Pane.h | 13 ------------- src/cascadia/TerminalApp/TerminalAppLib.vcxproj | 6 ------ src/cascadia/TerminalApp/TerminalPaneContent.cpp | 7 ++++--- src/cascadia/TerminalApp/TerminalPaneContent.h | 14 ++++++++++++-- 6 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/cascadia/TerminalApp/IPaneContent.idl b/src/cascadia/TerminalApp/IPaneContent.idl index 7232de01e1c..11da1e8fff2 100644 --- a/src/cascadia/TerminalApp/IPaneContent.idl +++ b/src/cascadia/TerminalApp/IPaneContent.idl @@ -13,7 +13,7 @@ namespace TerminalApp { Windows.UI.Xaml.FrameworkElement GetRoot(); - Windows.Foundation.Size MinSize { get; }; + Windows.Foundation.Size MinimumSize { get; }; String Title { get; }; UInt64 TaskbarState { get; }; @@ -47,6 +47,6 @@ namespace TerminalApp interface ISnappable { Single SnapDownToGrid(PaneSnapDirection direction, Single sizeToSnap); - Windows.Foundation.Size GridSize { get; }; + Windows.Foundation.Size GridUnitSize { get; }; }; } diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 90ec59719f6..6cd91801e82 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -4,8 +4,6 @@ #include "pch.h" #include "Pane.h" -#include "BellEventArgs.g.cpp" - #include "AppLogic.h" #include "Utils.h" @@ -2642,7 +2640,7 @@ Pane::SnapSizeResult Pane::_CalcSnappedDimension(const bool widthOrHeight, const } else { - const auto cellSize = snappable.GridSize(); + const auto cellSize = snappable.GridUnitSize(); const auto higher = lower + (direction == PaneSnapDirection::Width ? cellSize.Width : cellSize.Height); @@ -2703,13 +2701,11 @@ void Pane::_AdvanceSnappedDimension(const bool widthOrHeight, LayoutSizeNode& si // be, say, half a character, or fixed 10 pixels), so snap it upward. It might // however be already snapped, so add 1 to make sure it really increases // (not strictly necessary but to avoid surprises). - sizeNode.size = _CalcSnappedDimension(widthOrHeight, - sizeNode.size + 1) - .higher; + sizeNode.size = _CalcSnappedDimension(widthOrHeight, sizeNode.size + 1).higher; } else { - const auto cellSize = snappable.GridSize(); + const auto cellSize = snappable.GridUnitSize(); sizeNode.size += widthOrHeight ? cellSize.Width : cellSize.Height; } } @@ -2825,7 +2821,7 @@ Size Pane::_GetMinSize() const { if (_IsLeaf()) { - auto controlSize = _content.MinSize(); + auto controlSize = _content.MinimumSize(); auto newWidth = controlSize.Width; auto newHeight = controlSize.Height; diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index f8f059bb053..ec4754c1373 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -22,7 +22,6 @@ #include "TaskbarState.h" #include "TerminalPaneContent.h" -#include "BellEventArgs.g.h" // fwdecl unittest classes namespace TerminalAppLocalTests @@ -60,18 +59,6 @@ struct PaneResources winrt::Windows::UI::Xaml::Media::SolidColorBrush broadcastBorderBrush{ nullptr }; }; -namespace winrt::TerminalApp::implementation -{ - struct BellEventArgs : public BellEventArgsT - { - public: - BellEventArgs(bool flashTaskbar) : - FlashTaskbar(flashTaskbar) {} - - til::property FlashTaskbar; - }; -}; - class Pane : public std::enable_shared_from_this { public: diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index 30bf93f06a4..d6abba2db90 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -131,9 +131,6 @@ - - IPaneContent.idl - @@ -236,9 +233,6 @@ - - IPaneContent.idl - NotUsing diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.cpp b/src/cascadia/TerminalApp/TerminalPaneContent.cpp index 9d97788c6e7..ee7ec9d2cf2 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.cpp +++ b/src/cascadia/TerminalApp/TerminalPaneContent.cpp @@ -3,9 +3,10 @@ #include "pch.h" #include "TerminalPaneContent.h" -#include "PaneArgs.h" #include "TerminalPaneContent.g.cpp" +#include "BellEventArgs.g.cpp" + #include using namespace winrt::Windows::Foundation; using namespace winrt::Windows::UI::Xaml; @@ -49,7 +50,7 @@ namespace winrt::TerminalApp::implementation { return _control; } - winrt::Windows::Foundation::Size TerminalPaneContent::MinSize() + winrt::Windows::Foundation::Size TerminalPaneContent::MinimumSize() { return _control.MinimumSize(); } @@ -324,7 +325,7 @@ namespace winrt::TerminalApp::implementation { return _control.SnapDimensionToGrid(direction == PaneSnapDirection::Width, sizeToSnap); } - Windows::Foundation::Size TerminalPaneContent::GridSize() + Windows::Foundation::Size TerminalPaneContent::GridUnitSize() { return _control.CharacterDimensions(); } diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h index 0b6c968f4cc..fdb26707dae 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.h +++ b/src/cascadia/TerminalApp/TerminalPaneContent.h @@ -3,9 +3,19 @@ #pragma once #include "TerminalPaneContent.g.h" +#include "BellEventArgs.g.h" namespace winrt::TerminalApp::implementation { + struct BellEventArgs : public BellEventArgsT + { + public: + BellEventArgs(bool flashTaskbar) : + FlashTaskbar(flashTaskbar) {} + + til::property FlashTaskbar; + }; + struct TerminalPaneContent : TerminalPaneContentT { TerminalPaneContent(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile, @@ -13,7 +23,7 @@ namespace winrt::TerminalApp::implementation winrt::Windows::UI::Xaml::FrameworkElement GetRoot(); winrt::Microsoft::Terminal::Control::TermControl GetTerminal(); - winrt::Windows::Foundation::Size MinSize(); + winrt::Windows::Foundation::Size MinimumSize(); void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic); void Close(); @@ -35,7 +45,7 @@ namespace winrt::TerminalApp::implementation bool ReadOnly() { return _control.ReadOnly(); } float SnapDownToGrid(const TerminalApp::PaneSnapDirection direction, const float sizeToSnap); - Windows::Foundation::Size GridSize(); + Windows::Foundation::Size GridUnitSize(); til::typed_event RestartTerminalRequested; til::typed_event<> CloseRequested; From 052dc78af50ea11f4d66651bf0352dc844b05273 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Mar 2024 14:54:30 -0500 Subject: [PATCH 3/6] more nits --- src/cascadia/TerminalApp/Pane.cpp | 22 ++++--------------- src/cascadia/TerminalApp/TerminalPage.cpp | 4 ++-- .../TerminalApp/TerminalPaneContent.cpp | 2 +- .../TerminalApp/TerminalPaneContent.h | 2 +- .../TerminalApp/TerminalPaneContent.idl | 2 +- src/cascadia/TerminalApp/TerminalTab.cpp | 4 ++-- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 6cd91801e82..d2687d39891 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -1081,14 +1081,7 @@ TermControl Pane::GetLastFocusedTerminalControl() { if (p->_IsLeaf()) { - if (const auto& terminalPane{ p->_content.try_as() }) - { - return terminalPane.GetTerminal(); - } - else - { - return nullptr; - } + return p->GetTerminalControl(); } pane = p; } @@ -1096,15 +1089,8 @@ TermControl Pane::GetLastFocusedTerminalControl() } return _firstChild->GetLastFocusedTerminalControl(); } - - if (const auto& terminalPane{ _content.try_as() }) - { - return terminalPane.GetTerminal(); - } - else - { - return nullptr; - } + // we _are_ a leaf. + return GetTerminalControl(); } // Method Description: @@ -1118,7 +1104,7 @@ TermControl Pane::GetTerminalControl() const { if (const auto& terminalPane{ _getTerminalContent() }) { - return terminalPane.GetTerminal(); + return terminalPane.GetTermControl(); } else { diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 5fc8f121f31..adda5136679 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1306,7 +1306,7 @@ namespace winrt::TerminalApp::implementation return nullptr; } - const auto& control{ paneContent.GetTerminal() }; + const auto& control{ paneContent.GetTermControl() }; if (control == nullptr) { return nullptr; @@ -3219,7 +3219,7 @@ namespace winrt::TerminalApp::implementation // for nulls if (const auto& connection{ _duplicateConnectionForRestart(paneContent) }) { - paneContent.GetTerminal().Connection(connection); + paneContent.GetTermControl().Connection(connection); connection.Start(); } } diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.cpp b/src/cascadia/TerminalApp/TerminalPaneContent.cpp index ee7ec9d2cf2..597631d8fdc 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.cpp +++ b/src/cascadia/TerminalApp/TerminalPaneContent.cpp @@ -46,7 +46,7 @@ namespace winrt::TerminalApp::implementation { return _control; } - winrt::Microsoft::Terminal::Control::TermControl TerminalPaneContent::GetTerminal() + winrt::Microsoft::Terminal::Control::TermControl TerminalPaneContent::GetTermControl() { return _control; } diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h index fdb26707dae..1fd917fa325 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.h +++ b/src/cascadia/TerminalApp/TerminalPaneContent.h @@ -22,7 +22,7 @@ namespace winrt::TerminalApp::implementation const winrt::Microsoft::Terminal::Control::TermControl& control); winrt::Windows::UI::Xaml::FrameworkElement GetRoot(); - winrt::Microsoft::Terminal::Control::TermControl GetTerminal(); + winrt::Microsoft::Terminal::Control::TermControl GetTermControl(); winrt::Windows::Foundation::Size MinimumSize(); void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic); void Close(); diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.idl b/src/cascadia/TerminalApp/TerminalPaneContent.idl index 1e39f41c168..7e04c8b836c 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.idl +++ b/src/cascadia/TerminalApp/TerminalPaneContent.idl @@ -7,7 +7,7 @@ namespace TerminalApp { [default_interface] runtimeclass TerminalPaneContent : IPaneContent, ISnappable { - Microsoft.Terminal.Control.TermControl GetTerminal(); + Microsoft.Terminal.Control.TermControl GetTermControl(); void UpdateSettings(const Microsoft.Terminal.Settings.Model.TerminalSettingsCreateResult settings, const Microsoft.Terminal.Settings.Model.Profile profile); diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 86be96b6204..2325e149e60 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -1040,7 +1040,7 @@ namespace winrt::TerminalApp::implementation { if (const auto& termContent{ content.try_as() }) { - _addBroadcastHandlers(termContent.GetTerminal(), events); + _addBroadcastHandlers(termContent.GetTermControl(), events); } } @@ -1722,7 +1722,7 @@ namespace winrt::TerminalApp::implementation { if (const auto termContent{ content.try_as() }) { - return termContent.GetTerminal(); + return termContent.GetTermControl(); } } return nullptr; From a7533faf459211fa6fba1d632ca745498f66958c Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Mar 2024 15:15:08 -0500 Subject: [PATCH 4/6] eh these events are from pane content anyways! --- src/cascadia/TerminalApp/IPaneContent.idl | 14 +++++++------- src/cascadia/TerminalApp/TerminalPaneContent.h | 14 +++++++------- src/cascadia/TerminalApp/TerminalTab.cpp | 7 ++----- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/cascadia/TerminalApp/IPaneContent.idl b/src/cascadia/TerminalApp/IPaneContent.idl index 11da1e8fff2..ebe0914ea9c 100644 --- a/src/cascadia/TerminalApp/IPaneContent.idl +++ b/src/cascadia/TerminalApp/IPaneContent.idl @@ -26,15 +26,15 @@ namespace TerminalApp void Close(); - event Windows.Foundation.TypedEventHandler CloseRequested; + event Windows.Foundation.TypedEventHandler CloseRequested; - event Windows.Foundation.TypedEventHandler BellRequested; - event Windows.Foundation.TypedEventHandler TitleChanged; - event Windows.Foundation.TypedEventHandler TabColorChanged; - event Windows.Foundation.TypedEventHandler TaskbarProgressChanged; event Windows.Foundation.TypedEventHandler ConnectionStateChanged; - event Windows.Foundation.TypedEventHandler ReadOnlyChanged; - event Windows.Foundation.TypedEventHandler FocusRequested; + event Windows.Foundation.TypedEventHandler BellRequested; + event Windows.Foundation.TypedEventHandler TitleChanged; + event Windows.Foundation.TypedEventHandler TabColorChanged; + event Windows.Foundation.TypedEventHandler TaskbarProgressChanged; + event Windows.Foundation.TypedEventHandler ReadOnlyChanged; + event Windows.Foundation.TypedEventHandler FocusRequested; }; diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.h b/src/cascadia/TerminalApp/TerminalPaneContent.h index 1fd917fa325..2c2deee0124 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.h +++ b/src/cascadia/TerminalApp/TerminalPaneContent.h @@ -48,14 +48,14 @@ namespace winrt::TerminalApp::implementation Windows::Foundation::Size GridUnitSize(); til::typed_event RestartTerminalRequested; - til::typed_event<> CloseRequested; - til::typed_event BellRequested; - til::typed_event<> TitleChanged; - til::typed_event<> TabColorChanged; - til::typed_event<> TaskbarProgressChanged; til::typed_event<> ConnectionStateChanged; - til::typed_event<> ReadOnlyChanged; - til::typed_event<> FocusRequested; + til::typed_event CloseRequested; + til::typed_event BellRequested; + til::typed_event TitleChanged; + til::typed_event TabColorChanged; + til::typed_event TaskbarProgressChanged; + til::typed_event ReadOnlyChanged; + til::typed_event FocusRequested; private: winrt::Microsoft::Terminal::Control::TermControl _control{ nullptr }; diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 2325e149e60..5f44ae21d6a 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -1021,17 +1021,14 @@ namespace winrt::TerminalApp::implementation events.FocusRequested = content.FocusRequested( winrt::auto_revoke, - [dispatcher, weakThis](auto sender, auto) -> winrt::fire_and_forget { + [dispatcher, weakThis](TerminalApp::IPaneContent sender, auto) -> winrt::fire_and_forget { const auto weakThisCopy = weakThis; co_await wil::resume_foreground(dispatcher); if (const auto tab{ weakThisCopy.get() }) { if (tab->_focused()) { - if (const auto content{ sender.try_as() }) - { - content.Focus(FocusState::Pointer); - } + sender.Focus(FocusState::Pointer); } } }); From 826fc087b03f7aff6cd657651a54335f94e68ee5 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Mar 2024 15:50:58 -0500 Subject: [PATCH 5/6] hey there buddy, did you get lost? --- src/cascadia/TerminalApp/Pane.h | 1 - src/cascadia/TerminalApp/TerminalTab.cpp | 27 ++++++++++++++++++++ src/cascadia/TerminalControl/TermControl.cpp | 1 - 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index ec4754c1373..7b27fc6f31d 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -222,7 +222,6 @@ class Pane : public std::enable_shared_from_this WINRT_CALLBACK(GotFocus, gotFocusArgs); WINRT_CALLBACK(LostFocus, winrt::delegate>); - WINRT_CALLBACK(PaneRaiseBell, winrt::Windows::Foundation::EventHandler); WINRT_CALLBACK(Detached, winrt::delegate>); private: diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 5f44ae21d6a..287be2da5d0 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -1033,6 +1033,33 @@ namespace winrt::TerminalApp::implementation } }); + events.BellRequested = content.BellRequested( + winrt::auto_revoke, + [dispatcher, weakThis](TerminalApp::IPaneContent sender, auto bellArgs) -> winrt::fire_and_forget { + const auto weakThisCopy = weakThis; + co_await wil::resume_foreground(dispatcher); + if (const auto tab{ weakThisCopy.get() }) + { + if (bellArgs.FlashTaskbar()) + { + // If visual is set, we need to bubble this event all the way to app host to flash the taskbar + // In this part of the chain we bubble it from the hosting tab to the page + tab->_TabRaiseVisualBellHandlers(); + } + + // Show the bell indicator in the tab header + tab->ShowBellIndicator(true); + + // If this tab is focused, activate the bell indicator timer, which will + // remove the bell indicator once it fires + // (otherwise, the indicator is removed when the tab gets focus) + if (tab->_focusState != WUX::FocusState::Unfocused) + { + tab->ActivateBellIndicatorTimer(); + } + } + }); + if (_tabStatus.IsInputBroadcastActive()) { if (const auto& termContent{ content.try_as() }) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index b9c81abe67a..de7b6fc88a9 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -333,7 +333,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation // (The window has a min. size that ensures that there's always a scrollbar thumb.) if (drawableRange < 0) { - assert(false); return; } From 52970ef8544899c275e0c5abfbfcce518439d647 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Mar 2024 16:30:00 -0500 Subject: [PATCH 6/6] RegisterBigTimeEncapsulationViolatingTerminalPaneContentEvents --- src/cascadia/TerminalApp/TerminalPage.cpp | 17 +---------------- src/cascadia/TerminalApp/TerminalPage.h | 1 - src/cascadia/TerminalApp/TerminalTab.cpp | 11 ++++++++++- src/cascadia/TerminalApp/TerminalTab.h | 6 ++++++ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index adda5136679..fdc223bb9ab 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1731,11 +1731,8 @@ namespace winrt::TerminalApp::implementation // Add an event handler for when the terminal or tab wants to set a // progress indicator on the taskbar hostingTab.TaskbarProgressChanged({ get_weak(), &TerminalPage::_SetTaskbarProgressHandler }); - } - void TerminalPage::_RegisterPaneEvents(const TerminalApp::TerminalPaneContent& paneContent) - { - paneContent.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection }); + hostingTab.RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection }); } // Method Description: @@ -2384,16 +2381,6 @@ namespace winrt::TerminalApp::implementation _UnZoomIfNeeded(); auto [original, _] = activeTab->SplitPane(*realSplitType, splitSize, newPane); - // When we split the pane, the Pane itself will create a _new_ Pane - // instance for the original content. We need to make sure we also - // re-add our event handler to that newly created pane. - // - // _MakePane will already call this for the newly created pane. - if (const auto& paneContent{ original->GetContent().try_as() }) - { - _RegisterPaneEvents(*paneContent); - } - // After GH#6586, the control will no longer focus itself // automatically when it's finished being laid out. Manually focus // the control here instead. @@ -3204,8 +3191,6 @@ namespace winrt::TerminalApp::implementation original->SetActive(); } - _RegisterPaneEvents(paneContent); - return resultPane; } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 62ab115788d..02705fa71ca 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -345,7 +345,6 @@ namespace winrt::TerminalApp::implementation void _InitializeTab(winrt::com_ptr newTabImpl, uint32_t insertPosition = -1); void _RegisterTerminalEvents(Microsoft::Terminal::Control::TermControl term); void _RegisterTabEvents(TerminalTab& hostingTab); - void _RegisterPaneEvents(const TerminalApp::TerminalPaneContent& paneContent); void _DismissTabContextMenus(); void _FocusCurrentTab(const bool focusAlways); diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 287be2da5d0..4467659faa6 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -904,7 +904,6 @@ namespace winrt::TerminalApp::implementation if (it != _contentEvents.end()) { // revoke the event handlers by resetting the event struct - it->second = {}; // and remove it from the map _contentEvents.erase(paneId); } @@ -1060,6 +1059,11 @@ namespace winrt::TerminalApp::implementation } }); + if (const auto& terminal{ content.try_as() }) + { + events.RestartTerminalRequested = terminal.RestartTerminalRequested(winrt::auto_revoke, { get_weak(), &TerminalTab::_bubbleRestartTerminalRequested }); + } + if (_tabStatus.IsInputBroadcastActive()) { if (const auto& termContent{ content.try_as() }) @@ -1998,4 +2002,9 @@ namespace winrt::TerminalApp::implementation ActionAndArgs actionAndArgs{ ShortcutAction::Find, nullptr }; _dispatch.DoAction(*this, actionAndArgs); } + void TerminalTab::_bubbleRestartTerminalRequested(TerminalApp::TerminalPaneContent sender, + const winrt::Windows::Foundation::IInspectable& args) + { + RestartTerminalRequested.raise(sender, args); + } } diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index 3ff128a9e2b..221112274d9 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -97,6 +97,8 @@ namespace winrt::TerminalApp::implementation return _tabStatus; } + til::typed_event RestartTerminalRequested; + WINRT_CALLBACK(ActivePaneChanged, winrt::delegate<>); WINRT_CALLBACK(TabRaiseVisualBell, winrt::delegate<>); TYPED_EVENT(TaskbarProgressChanged, IInspectable, IInspectable); @@ -138,6 +140,8 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::Control::TermControl::KeySent_revoker KeySent; winrt::Microsoft::Terminal::Control::TermControl::CharSent_revoker CharSent; winrt::Microsoft::Terminal::Control::TermControl::StringSent_revoker StringSent; + + winrt::TerminalApp::TerminalPaneContent::RestartTerminalRequested_revoker RestartTerminalRequested; }; std::unordered_map _contentEvents; @@ -196,6 +200,8 @@ namespace winrt::TerminalApp::implementation void _moveTabToNewWindowClicked(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); void _findClicked(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); + void _bubbleRestartTerminalRequested(TerminalApp::TerminalPaneContent sender, const winrt::Windows::Foundation::IInspectable& args); + friend class ::TerminalAppLocalTests::TabTests; }; }