@@ -239,61 +239,59 @@ void AppHost::_HandleCreateWindow(const HWND hwnd, RECT proposedRect, winrt::Ter
239239
240240 long adjustedHeight = 0 ;
241241 long adjustedWidth = 0 ;
242- if (launchMode == winrt::TerminalApp::LaunchMode::DefaultMode)
242+
243+ // Find nearest monitor.
244+ HMONITOR hmon = MonitorFromRect (&proposedRect, MONITOR_DEFAULTTONEAREST);
245+
246+ // Get nearest monitor information
247+ MONITORINFO monitorInfo;
248+ monitorInfo.cbSize = sizeof (MONITORINFO);
249+ GetMonitorInfo (hmon, &monitorInfo);
250+
251+ // This API guarantees that dpix and dpiy will be equal, but neither is an
252+ // optional parameter so give two UINTs.
253+ UINT dpix = USER_DEFAULT_SCREEN_DPI;
254+ UINT dpiy = USER_DEFAULT_SCREEN_DPI;
255+ // If this fails, we'll use the default of 96.
256+ GetDpiForMonitor (hmon, MDT_EFFECTIVE_DPI, &dpix, &dpiy);
257+
258+ // We need to check if the top left point of the titlebar of the window is within any screen
259+ RECT offScreenTestRect;
260+ offScreenTestRect.left = proposedRect.left ;
261+ offScreenTestRect.top = proposedRect.top ;
262+ offScreenTestRect.right = offScreenTestRect.left + 1 ;
263+ offScreenTestRect.bottom = offScreenTestRect.top + 1 ;
264+
265+ bool isTitlebarIntersectWithMonitors = false ;
266+ EnumDisplayMonitors (
267+ nullptr , &offScreenTestRect, [](HMONITOR, HDC, LPRECT, LPARAM lParam) -> BOOL {
268+ auto intersectWithMonitor = reinterpret_cast <bool *>(lParam);
269+ *intersectWithMonitor = true ;
270+ // Continue the enumeration
271+ return FALSE ;
272+ },
273+ reinterpret_cast <LPARAM>(&isTitlebarIntersectWithMonitors));
274+
275+ if (!isTitlebarIntersectWithMonitors)
243276 {
244- // Find nearest monitor.
245- HMONITOR hmon = MonitorFromRect (&proposedRect, MONITOR_DEFAULTTONEAREST);
246-
247- // Get nearest monitor information
248- MONITORINFO monitorInfo;
249- monitorInfo.cbSize = sizeof (MONITORINFO);
250- GetMonitorInfo (hmon, &monitorInfo);
251-
252- // This API guarantees that dpix and dpiy will be equal, but neither is an
253- // optional parameter so give two UINTs.
254- UINT dpix = USER_DEFAULT_SCREEN_DPI;
255- UINT dpiy = USER_DEFAULT_SCREEN_DPI;
256- // If this fails, we'll use the default of 96.
257- GetDpiForMonitor (hmon, MDT_EFFECTIVE_DPI, &dpix, &dpiy);
258-
259- // We need to check if the top left point of the titlebar of the window is within any screen
260- RECT offScreenTestRect;
261- offScreenTestRect.left = proposedRect.left ;
262- offScreenTestRect.top = proposedRect.top ;
263- offScreenTestRect.right = offScreenTestRect.left + 1 ;
264- offScreenTestRect.bottom = offScreenTestRect.top + 1 ;
265-
266- bool isTitlebarIntersectWithMonitors = false ;
267- EnumDisplayMonitors (
268- nullptr , &offScreenTestRect, [](HMONITOR, HDC, LPRECT, LPARAM lParam) -> BOOL {
269- auto intersectWithMonitor = reinterpret_cast <bool *>(lParam);
270- *intersectWithMonitor = true ;
271- // Continue the enumeration
272- return FALSE ;
273- },
274- reinterpret_cast <LPARAM>(&isTitlebarIntersectWithMonitors));
275-
276- if (!isTitlebarIntersectWithMonitors)
277- {
278- // If the title bar is out-of-screen, we set the initial position to
279- // the top left corner of the nearest monitor
280- proposedRect.left = monitorInfo.rcWork .left ;
281- proposedRect.top = monitorInfo.rcWork .top ;
282- }
277+ // If the title bar is out-of-screen, we set the initial position to
278+ // the top left corner of the nearest monitor
279+ proposedRect.left = monitorInfo.rcWork .left ;
280+ proposedRect.top = monitorInfo.rcWork .top ;
281+ }
283282
284- auto initialSize = _logic.GetLaunchDimensions (dpix);
283+ auto initialSize = _logic.GetLaunchDimensions (dpix);
285284
286- const short islandWidth = Utils::ClampToShortMax (
287- static_cast <long >(ceil (initialSize.X )), 1 );
288- const short islandHeight = Utils::ClampToShortMax (
289- static_cast <long >(ceil (initialSize.Y )), 1 );
285+ const short islandWidth = Utils::ClampToShortMax (
286+ static_cast <long >(ceil (initialSize.X )), 1 );
287+ const short islandHeight = Utils::ClampToShortMax (
288+ static_cast <long >(ceil (initialSize.Y )), 1 );
290289
291- // Get the size of a window we'd need to host that client rect. This will
292- // add the titlebar space.
293- const auto nonClientSize = _window->GetTotalNonClientExclusiveSize (dpix);
294- adjustedWidth = islandWidth + nonClientSize.cx ;
295- adjustedHeight = islandHeight + nonClientSize.cy ;
296- }
290+ // Get the size of a window we'd need to host that client rect. This will
291+ // add the titlebar space.
292+ const auto nonClientSize = _window->GetTotalNonClientExclusiveSize (dpix);
293+ adjustedWidth = islandWidth + nonClientSize.cx ;
294+ adjustedHeight = islandHeight + nonClientSize.cy ;
297295
298296 const COORD origin{ gsl::narrow<short >(proposedRect.left ),
299297 gsl::narrow<short >(proposedRect.top ) };
0 commit comments