-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Hide the window from DWM until we're finished with initialization #12979
Changes from all commits
0fc4bdc
5dee29c
abb3549
d5cab53
ea51947
492db5c
0b5d636
75d3065
4a7a876
bb32b88
bc305de
6426bc9
dcee5a3
04aaaa7
4ceeace
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 |
---|---|---|
|
@@ -73,8 +73,7 @@ AppHost::AppHost() noexcept : | |
auto pfn = std::bind(&AppHost::_HandleCreateWindow, | ||
this, | ||
std::placeholders::_1, | ||
std::placeholders::_2, | ||
std::placeholders::_3); | ||
std::placeholders::_2); | ||
_window->SetCreateCallback(pfn); | ||
|
||
_window->SetSnapDimensionCallback(std::bind(&winrt::TerminalApp::AppLogic::CalcSnappedDimension, | ||
|
@@ -379,6 +378,7 @@ void AppHost::Initialize() | |
_revokers.FullscreenChanged = _logic.FullscreenChanged(winrt::auto_revoke, { this, &AppHost::_FullscreenChanged }); | ||
_revokers.FocusModeChanged = _logic.FocusModeChanged(winrt::auto_revoke, { this, &AppHost::_FocusModeChanged }); | ||
_revokers.AlwaysOnTopChanged = _logic.AlwaysOnTopChanged(winrt::auto_revoke, { this, &AppHost::_AlwaysOnTopChanged }); | ||
_revokers.Initialized = _logic.Initialized(winrt::auto_revoke, { this, &AppHost::_AppInitializedHandler }); | ||
_revokers.RaiseVisualBell = _logic.RaiseVisualBell(winrt::auto_revoke, { this, &AppHost::_RaiseVisualBell }); | ||
_revokers.SystemMenuChangeRequested = _logic.SystemMenuChangeRequested(winrt::auto_revoke, { this, &AppHost::_SystemMenuChangeRequested }); | ||
_revokers.ChangeMaximizeRequested = _logic.ChangeMaximizeRequested(winrt::auto_revoke, { this, &AppHost::_ChangeMaximizeRequested }); | ||
|
@@ -520,12 +520,31 @@ LaunchPosition AppHost::_GetWindowLaunchPosition() | |
return pos; | ||
} | ||
|
||
// Method Description: | ||
// - Callback for when the window is first being created (during WM_CREATE). | ||
// Stash the proposed size for later. We'll need that once we're totally | ||
// initialized, so that we can show the window in the right position *when we | ||
// want to show it*. If we did the _initialResizeAndRepositionWindow work now, | ||
// it would have no effect, because the window is not yet visible. | ||
// Arguments: | ||
// - hwnd: The HWND of the window we're about to create. | ||
// - proposedRect: The location and size of the window that we're about to | ||
// create. We'll use this rect to determine which monitor the window is about | ||
// to appear on. | ||
void AppHost::_HandleCreateWindow(const HWND /* hwnd */, RECT proposedRect) | ||
{ | ||
// GH#11561: Hide the window until we're totally done being initialized. | ||
// More commentary in TerminalPage::_CompleteInitialization | ||
_proposedRect = proposedRect; | ||
} | ||
|
||
// Method Description: | ||
// - Resize the window we're about to create to the appropriate dimensions, as | ||
// specified in the settings. This will be called during the handling of | ||
// WM_CREATE. We'll load the settings for the app, then get the proposed size | ||
// of the terminal from the app. Using that proposed size, we'll resize the | ||
// window we're creating, so that it'll match the values in the settings. | ||
// specified in the settings. This is called once the app has finished it's | ||
// initial setup, once we have created all the tabs, panes, etc. We'll load | ||
// the settings for the app, then get the proposed size of the terminal from | ||
// the app. Using that proposed size, we'll resize the window we're creating, | ||
// so that it'll match the values in the settings. | ||
// Arguments: | ||
// - hwnd: The HWND of the window we're about to create. | ||
// - proposedRect: The location and size of the window that we're about to | ||
|
@@ -534,7 +553,7 @@ LaunchPosition AppHost::_GetWindowLaunchPosition() | |
// - launchMode: A LaunchMode enum reference that indicates the launch mode | ||
// Return Value: | ||
// - None | ||
void AppHost::_HandleCreateWindow(const HWND hwnd, RECT proposedRect, LaunchMode& launchMode) | ||
void AppHost::_initialResizeAndRepositionWindow(const HWND hwnd, RECT proposedRect, LaunchMode& launchMode) | ||
{ | ||
launchMode = _logic.GetLaunchMode(); | ||
|
||
|
@@ -1556,3 +1575,22 @@ void AppHost::_CloseRequested(const winrt::Windows::Foundation::IInspectable& /* | |
const auto pos = _GetWindowLaunchPosition(); | ||
_logic.CloseWindow(pos); | ||
} | ||
|
||
void AppHost::_AppInitializedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/, | ||
const winrt::Windows::Foundation::IInspectable& /*arg*/) | ||
{ | ||
// GH#11561: We're totally done being initialized. Resize the window to | ||
// match the initial settings, and then call ShowWindow to finally make us | ||
// visible. | ||
|
||
LaunchMode launchMode{}; | ||
_initialResizeAndRepositionWindow(_window->GetHandle(), _proposedRect, launchMode); | ||
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. Worried a bit about the resize - how often will we start up at the wrong size? 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 never saw it? 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. lmao well this was the issue now 😑 |
||
|
||
auto nCmdShow = SW_SHOWDEFAULT; | ||
if (WI_IsFlagSet(launchMode, LaunchMode::MaximizedMode)) | ||
{ | ||
nCmdShow = SW_MAXIMIZE; | ||
} | ||
|
||
ShowWindow(_window->GetHandle(), nCmdShow); | ||
} |
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.
I'd suggest just storing the dispatcher in the beginning as
Seems like a more hassle free solution to me.
Also: Do you mind removing the
winrt::apartment_context
instantiation?Finally there's the option to drop all of the coroutine stuff and write this:
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.
frick deleted locally, forgot to save
I thought it best to not stash an owning reference to the dispatcher, as to decrease the chances that the coroutine kept the Dispatcher alive despite the Page getting deref'ed.