From 2ffe74d9e50f55abf44f63b89d8913881def3a36 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 16 Apr 2024 06:12:29 -0500 Subject: [PATCH] Also remember to persist window positions This got lost in #16598. `TerminalPage` needs to ask the window where the it actually is, so it can persist it. Closes #17010 --- src/cascadia/TerminalApp/TerminalPage.cpp | 7 +++++++ src/cascadia/TerminalApp/TerminalPage.h | 10 ++++++++++ src/cascadia/TerminalApp/TerminalPage.idl | 7 +++++++ src/cascadia/TerminalApp/TerminalWindow.h | 2 ++ src/cascadia/TerminalApp/TerminalWindow.idl | 1 + src/cascadia/WindowsTerminal/AppHost.cpp | 9 +++++++++ src/cascadia/WindowsTerminal/AppHost.h | 4 ++++ 7 files changed, 40 insertions(+) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index ff4b6743e69..1749acce26f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -8,6 +8,7 @@ #include "RenameWindowRequestedArgs.g.cpp" #include "RequestMoveContentArgs.g.cpp" #include "RequestReceiveContentArgs.g.cpp" +#include "LaunchPositionRequest.g.cpp" #include @@ -1952,6 +1953,12 @@ namespace winrt::TerminalApp::implementation layout.InitialSize(windowSize); + // We don't actually know our own position. So we have to ask the window + // layer for that. + const auto launchPosRequest{ winrt::make() }; + RequestLaunchPosition.raise(*this, launchPosRequest); + layout.InitialPosition(launchPosRequest.Position()); + ApplicationState::SharedInstance().AppendPersistedWindowLayout(layout); } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 711d9f7b7ec..0dba78abd4b 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -10,6 +10,7 @@ #include "RenameWindowRequestedArgs.g.h" #include "RequestMoveContentArgs.g.h" #include "RequestReceiveContentArgs.g.h" +#include "LaunchPositionRequest.g.h" #include "Toast.h" #define DECLARE_ACTION_HANDLER(action) void _Handle##action(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args); @@ -79,6 +80,13 @@ namespace winrt::TerminalApp::implementation _TabIndex{ tabIndex } {}; }; + struct LaunchPositionRequest : LaunchPositionRequestT + { + LaunchPositionRequest() = default; + + til::property Position; + }; + struct TerminalPage : TerminalPageT { public: @@ -186,6 +194,8 @@ namespace winrt::TerminalApp::implementation til::typed_event RequestMoveContent; til::typed_event RequestReceiveContent; + til::typed_event RequestLaunchPosition; + WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::Media::Brush, TitlebarBrush, PropertyChanged.raise, nullptr); WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::Media::Brush, FrameBrush, PropertyChanged.raise, nullptr); diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl index 8ec4fa1dc9c..667350056b8 100644 --- a/src/cascadia/TerminalApp/TerminalPage.idl +++ b/src/cascadia/TerminalApp/TerminalPage.idl @@ -51,6 +51,11 @@ namespace TerminalApp Boolean IsQuakeWindow(); }; + runtimeclass LaunchPositionRequest + { + Microsoft.Terminal.Settings.Model.LaunchPosition Position; + } + [default_interface] runtimeclass TerminalPage : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged, Microsoft.Terminal.UI.IDirectKeyListener { TerminalPage(WindowProperties properties, ContentManager manager); @@ -98,5 +103,7 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler RequestMoveContent; event Windows.Foundation.TypedEventHandler RequestReceiveContent; + + event Windows.Foundation.TypedEventHandler RequestLaunchPosition; } } diff --git a/src/cascadia/TerminalApp/TerminalWindow.h b/src/cascadia/TerminalApp/TerminalWindow.h index d48d8d4f242..b10c29a8d72 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.h +++ b/src/cascadia/TerminalApp/TerminalWindow.h @@ -231,6 +231,8 @@ namespace winrt::TerminalApp::implementation FORWARDED_TYPED_EVENT(RequestMoveContent, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMoveContentArgs, _root, RequestMoveContent); FORWARDED_TYPED_EVENT(RequestReceiveContent, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestReceiveContentArgs, _root, RequestReceiveContent); + FORWARDED_TYPED_EVENT(RequestLaunchPosition, Windows::Foundation::IInspectable, winrt::TerminalApp::LaunchPositionRequest, _root, RequestLaunchPosition); + #ifdef UNIT_TESTING friend class TerminalAppLocalTests::CommandlineTest; #endif diff --git a/src/cascadia/TerminalApp/TerminalWindow.idl b/src/cascadia/TerminalApp/TerminalWindow.idl index 1700686e1db..75c47fce8bf 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.idl +++ b/src/cascadia/TerminalApp/TerminalWindow.idl @@ -137,6 +137,7 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler RequestMoveContent; event Windows.Foundation.TypedEventHandler RequestReceiveContent; + event Windows.Foundation.TypedEventHandler RequestLaunchPosition; void AttachContent(String content, UInt32 tabIndex); void SendContentToOther(RequestReceiveContentArgs args); diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 0fe39c1cc56..5470db596f5 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -341,6 +341,7 @@ void AppHost::Initialize() _revokers.RaiseVisualBell = _windowLogic.RaiseVisualBell(winrt::auto_revoke, { this, &AppHost::_RaiseVisualBell }); _revokers.SystemMenuChangeRequested = _windowLogic.SystemMenuChangeRequested(winrt::auto_revoke, { this, &AppHost::_SystemMenuChangeRequested }); _revokers.ChangeMaximizeRequested = _windowLogic.ChangeMaximizeRequested(winrt::auto_revoke, { this, &AppHost::_ChangeMaximizeRequested }); + _revokers.RequestLaunchPosition = _windowLogic.RequestLaunchPosition(winrt::auto_revoke, { this, &AppHost::_HandleRequestLaunchPosition }); _windowCallbacks.MaximizeChanged = _window->MaximizeChanged([this](bool newMaximize) { if (_windowLogic) @@ -510,6 +511,14 @@ void AppHost::AppTitleChanged(const winrt::Windows::Foundation::IInspectable& /* _windowManager.UpdateActiveTabTitle(newTitle, _peasant); } +// The terminal page is responsible for persisting it's own state, but it does +// need to ask us where exactly on the screen the window is. +void AppHost::_HandleRequestLaunchPosition(const winrt::Windows::Foundation::IInspectable& /*sender*/, + winrt::TerminalApp::LaunchPositionRequest args) +{ + args.Position(_GetWindowLaunchPosition()); +} + LaunchPosition AppHost::_GetWindowLaunchPosition() { LaunchPosition pos{}; diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h index a22fc85a948..cc90c21c1c1 100644 --- a/src/cascadia/WindowsTerminal/AppHost.h +++ b/src/cascadia/WindowsTerminal/AppHost.h @@ -160,6 +160,9 @@ class AppHost : public std::enable_shared_from_this void _stopFrameTimer(); void _updateFrameColor(const winrt::Windows::Foundation::IInspectable&, const winrt::Windows::Foundation::IInspectable&); + void _HandleRequestLaunchPosition(const winrt::Windows::Foundation::IInspectable& sender, + winrt::TerminalApp::LaunchPositionRequest args); + // Helper struct. By putting these all into one struct, we can revoke them // all at once, by assigning _revokers to a fresh Revokers instance. That'll // cause us to dtor the old one, which will immediately call revoke on all @@ -195,6 +198,7 @@ class AppHost : public std::enable_shared_from_this winrt::TerminalApp::TerminalWindow::ShowWindowChanged_revoker ShowWindowChanged; winrt::TerminalApp::TerminalWindow::RequestMoveContent_revoker RequestMoveContent; winrt::TerminalApp::TerminalWindow::RequestReceiveContent_revoker RequestReceiveContent; + winrt::TerminalApp::TerminalWindow::RequestLaunchPosition_revoker RequestLaunchPosition; winrt::TerminalApp::TerminalWindow::PropertyChanged_revoker PropertyChanged; winrt::TerminalApp::TerminalWindow::SettingsChanged_revoker SettingsChanged;