Skip to content

Commit

Permalink
Also remember to persist window positions (#17066)
Browse files Browse the repository at this point in the history
This got lost in #16598. `TerminalPage` needs to ask the window where
the it actually is, so it can persist it. More details in
#16598 (comment)

Closes #17010
  • Loading branch information
zadjii-msft authored Apr 17, 2024
1 parent 90b8bb7 commit 643f716
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RenameWindowRequestedArgs.g.cpp"
#include "RequestMoveContentArgs.g.cpp"
#include "RequestReceiveContentArgs.g.cpp"
#include "LaunchPositionRequest.g.cpp"

#include <filesystem>

Expand Down Expand Up @@ -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<LaunchPositionRequest>() };
RequestLaunchPosition.raise(*this, launchPosRequest);
layout.InitialPosition(launchPosRequest.Position());

ApplicationState::SharedInstance().AppendPersistedWindowLayout(layout);
}

Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -186,6 +194,8 @@ namespace winrt::TerminalApp::implementation
til::typed_event<Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMoveContentArgs> RequestMoveContent;
til::typed_event<Windows::Foundation::IInspectable, winrt::TerminalApp::RequestReceiveContentArgs> RequestReceiveContent;

til::typed_event<IInspectable, winrt::TerminalApp::LaunchPositionRequest> 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);

Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -98,5 +103,7 @@ namespace TerminalApp

event Windows.Foundation.TypedEventHandler<Object, RequestMoveContentArgs> RequestMoveContent;
event Windows.Foundation.TypedEventHandler<Object, RequestReceiveContentArgs> RequestReceiveContent;

event Windows.Foundation.TypedEventHandler<Object, LaunchPositionRequest> RequestLaunchPosition;
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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);
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{};
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class AppHost : public std::enable_shared_from_this<AppHost>
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
Expand Down Expand Up @@ -195,6 +198,7 @@ class AppHost : public std::enable_shared_from_this<AppHost>
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;

Expand Down

0 comments on commit 643f716

Please sign in to comment.