Also remember to persist window positions (#17066)

This got lost in #16598. `TerminalPage` needs to ask the window where
the it actually is, so it can persist it. More details in
https://github.com/microsoft/terminal/pull/16598#discussion_r1511519304

Closes #17010

(cherry picked from commit 643f7167a66428c777f1e59b03a38279a5c2b688)
Service-Card-Id: 92360686
Service-Version: 1.20
This commit is contained in:
Mike Griese 2024-04-17 10:52:29 -07:00 committed by Dustin L. Howett
parent ff99f4b7c4
commit e2a076c038
7 changed files with 40 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "RenameWindowRequestedArgs.g.cpp"
#include "RequestMoveContentArgs.g.cpp"
#include "RequestReceiveContentArgs.g.cpp"
#include "LaunchPositionRequest.g.cpp"
#include <filesystem>
@ -1951,6 +1952,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<LaunchPositionRequest>() };
RequestLaunchPosition.raise(*this, launchPosRequest);
layout.InitialPosition(launchPosRequest.Position());
ApplicationState::SharedInstance().AppendPersistedWindowLayout(layout);
}

View File

@ -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>
{
LaunchPositionRequest() = default;
til::property<winrt::Microsoft::Terminal::Settings::Model::LaunchPosition> Position;
};
struct TerminalPage : TerminalPageT<TerminalPage>
{
public:
@ -186,6 +194,8 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(RequestMoveContent, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMoveContentArgs);
TYPED_EVENT(RequestReceiveContent, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestReceiveContentArgs);
TYPED_EVENT(RequestLaunchPosition, IInspectable, winrt::TerminalApp::LaunchPositionRequest);
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::Media::Brush, TitlebarBrush, _PropertyChangedHandlers, nullptr);
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::Media::Brush, FrameBrush, _PropertyChangedHandlers, nullptr);

View File

@ -52,6 +52,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, IDirectKeyListener
{
TerminalPage(WindowProperties properties, ContentManager manager);
@ -99,5 +104,7 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, RequestMoveContentArgs> RequestMoveContent;
event Windows.Foundation.TypedEventHandler<Object, RequestReceiveContentArgs> RequestReceiveContent;
event Windows.Foundation.TypedEventHandler<Object, LaunchPositionRequest> RequestLaunchPosition;
}
}

View File

@ -234,6 +234,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

View File

@ -138,6 +138,7 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, RequestMoveContentArgs> RequestMoveContent;
event Windows.Foundation.TypedEventHandler<Object, RequestReceiveContentArgs> RequestReceiveContent;
event Windows.Foundation.TypedEventHandler<Object, LaunchPositionRequest> RequestLaunchPosition;
void AttachContent(String content, UInt32 tabIndex);
void SendContentToOther(RequestReceiveContentArgs args);

View File

@ -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{};

View File

@ -160,6 +160,9 @@ private:
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 @@ private:
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;