-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persist window layout on window close #10972
Changes from 33 commits
405c853
6297417
a265e81
48cde20
4b897d0
773cc79
37e5bd4
1b6dfc5
c1722c7
d6997f9
8c64dd5
97bce32
ec79c93
d7ce2de
91c3d69
ef80c66
0a3ccd1
8d6a7ee
0a6d4f7
c0f7eaa
2062eb3
464ca59
3b02719
d204f00
1cd14b3
cfe3583
072822a
b8b7d48
4b1bbbd
50cf7fb
81af065
ef21ca6
ba56ded
6aeabb1
7f14c7d
8e22231
2f39ed9
735de10
230a1ab
8f38e1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
// monarch! | ||
CoRevokeClassObject(_registrationHostClass); | ||
_registrationHostClass = 0; | ||
SignalClose(); | ||
_monarchWaitInterrupt.SetEvent(); | ||
|
||
// A thread is joinable once it's been started. Basically this just | ||
|
@@ -64,6 +65,18 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
} | ||
} | ||
|
||
void WindowManager::SignalClose() | ||
{ | ||
if (_monarch) | ||
{ | ||
try | ||
{ | ||
_monarch.SignalClose(_peasant.GetID()); | ||
} | ||
CATCH_LOG() | ||
} | ||
} | ||
|
||
void WindowManager::ProposeCommandline(const Remoting::CommandlineArgs& args) | ||
{ | ||
// If we're the king, we _definitely_ want to process the arguments, we were | ||
|
@@ -250,9 +263,13 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
// Here, we're the king! | ||
// | ||
// This is where you should do any additional setup that might need to be | ||
// done when we become the king. THis will be called both for the first | ||
// done when we become the king. This will be called both for the first | ||
// window, and when the current monarch dies. | ||
|
||
auto weakThis{ get_weak() }; | ||
|
||
_monarch.WindowCreated({ get_weak(), &WindowManager::_WindowCreatedHandlers }); | ||
_monarch.WindowClosed({ get_weak(), &WindowManager::_WindowClosedHandlers }); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_monarch.FindTargetWindowRequested({ this, &WindowManager::_raiseFindTargetWindowRequested }); | ||
_monarch.ShowTrayIconRequested([this](auto&&, auto&&) { _ShowTrayIconRequestedHandlers(*this, nullptr); }); | ||
_monarch.HideTrayIconRequested([this](auto&&, auto&&) { _HideTrayIconRequestedHandlers(*this, nullptr); }); | ||
|
@@ -526,6 +543,19 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
return _monarch.GetPeasantNames(); | ||
} | ||
|
||
uint64_t WindowManager::GetNumberOfPeasants() | ||
{ | ||
if (_monarch) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same deal here with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea which is why I was just cautious. |
||
{ | ||
try | ||
{ | ||
return _monarch.GetNumberOfPeasants(); | ||
} | ||
CATCH_LOG() | ||
} | ||
return 0; | ||
} | ||
|
||
// Method Description: | ||
// - Ask the monarch to show a tray icon. | ||
// Arguments: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,12 +596,30 @@ namespace winrt::TerminalApp::implementation | |
LoadSettings(); | ||
} | ||
|
||
// Use the default profile to determine how big of a window we need. | ||
const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, nullptr, nullptr) }; | ||
|
||
auto proposedSize = TermControl::GetProposedDimensions(settings.DefaultSettings(), dpi); | ||
winrt::Windows::Foundation::Size proposedSize{}; | ||
|
||
const float scale = static_cast<float>(dpi) / static_cast<float>(USER_DEFAULT_SCREEN_DPI); | ||
if (_root->ShouldUsePersistedLayout(_settings)) | ||
{ | ||
auto layouts = ApplicationState::SharedInstance().PersistedWindowLayouts(); | ||
Rosefield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (layouts && layouts.Size() > 0 && layouts.GetAt(0).InitialSize()) | ||
{ | ||
proposedSize = layouts.GetAt(0).InitialSize().Value(); | ||
// The size is saved as a non-scaled real pixel size, | ||
// so we need to scale it appropriately. | ||
proposedSize.Height = proposedSize.Height * scale; | ||
proposedSize.Width = proposedSize.Width * scale; | ||
Comment on lines
+609
to
+612
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may cause an issue when you restore your window on the wrong DPI screen; worth worrying about? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we save we save the "actual" pixel size instead of the visual size(i.e. without any scaling). So if you save on a screen at 150% scaling, and reopen on a screen at 100% scaling, then it will appear smaller (assuming both screens have the same dpi). Whereas if you save on a 150% screen and open on a 150% screen it will appear the same size because we scale it on load. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me! Thanks |
||
} | ||
} | ||
|
||
if (proposedSize.Width == 0 && proposedSize.Height == 0) | ||
{ | ||
// Use the default profile to determine how big of a window we need. | ||
const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, nullptr, nullptr) }; | ||
|
||
proposedSize = TermControl::GetProposedDimensions(settings.DefaultSettings(), dpi); | ||
} | ||
zadjii-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// GH#2061 - If the global setting "Always show tab bar" is | ||
// set or if "Show tabs in title bar" is set, then we'll need to add | ||
|
@@ -683,7 +701,18 @@ namespace winrt::TerminalApp::implementation | |
LoadSettings(); | ||
} | ||
|
||
const auto initialPosition{ _settings.GlobalSettings().InitialPosition() }; | ||
auto initialPosition{ _settings.GlobalSettings().InitialPosition() }; | ||
|
||
if (_root->ShouldUsePersistedLayout(_settings)) | ||
{ | ||
auto layouts = ApplicationState::SharedInstance().PersistedWindowLayouts(); | ||
Rosefield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (layouts && layouts.Size() > 0 && layouts.GetAt(0).InitialPosition()) | ||
{ | ||
initialPosition = layouts.GetAt(0).InitialPosition().Value(); | ||
} | ||
} | ||
|
||
return { | ||
initialPosition.X ? initialPosition.X.Value() : defaultInitialX, | ||
initialPosition.Y ? initialPosition.Y.Value() : defaultInitialY | ||
|
@@ -1429,6 +1458,14 @@ namespace winrt::TerminalApp::implementation | |
} | ||
} | ||
|
||
void AppLogic::SetNumberOfOpenWindows(const uint64_t num) | ||
{ | ||
if (_root) | ||
{ | ||
_root->SetNumberOfOpenWindows(num); | ||
} | ||
} | ||
|
||
void AppLogic::RenameFailed() | ||
{ | ||
if (_root) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy this sure is a mouthful, but hey it works great in the SUI so who cares