Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalWindow.cpp (C++)

Code before:
    //   the actions async using the XAML dispatcher (which doesn't exist yet)
    // - DON'T CALL THIS if you haven't already checked
    //   ShouldImmediatelyHandoffToElevated. If you're thinking about calling
    //   this outside of the one place it's used, that's probably the wrong
    //   solution.
    // Arguments:
    // - settings: the settings we should use for dispatching these actions. At
    //   this point in startup, we hadn't otherwise been initialized with these,
    //   so use them now.
    // Return Value:
    // - <none>
    void TerminalWindow::HandoffToElevated()
    {
        if (_root)
        {
            _root->HandoffToElevated(_settings);
            return;
        }
    }

    void TerminalWindow::_WindowSizeChanged(const IInspectable&, winrt::Microsoft::Terminal::Control::WindowSizeChangedEventArgs args)
    {
        til::size cellCount{ args.Width(), args.Height() };
        const auto dpi = GetDpiForWindow(_hwnd);
        const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, nullptr, nullptr) };
        auto pixelSize = TermControl::GetProposedDimensions(settings.DefaultSettings(), dpi, cellCount.width, cellCount.height);
        const auto scale = static_cast<float>(dpi) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);

        if (!FocusMode())
        {
            if (!_settings.GlobalSettings().AlwaysShowTabs())
            {
                // Hide the title bar = off, Always show tabs = off.
                static constexpr auto titlebarHeight = 10;
                pixelSize.Height += (titlebarHeight)*scale;
            }
            else if (!_settings.GlobalSettings().ShowTabsInTitlebar())
            {
                // Hide the title bar = off, Always show tabs = on.
                static constexpr auto titlebarAndTabBarHeight = 40;
                pixelSize.Height += (titlebarAndTabBarHeight)*scale;
            }
            // Hide the title bar = on, Always show tabs = on.
            // In this case, we don't add any height because
            // NonClientIslandWindow::GetTotalNonClientExclusiveSize() gets
            // called in AppHost::_resizeWindow and it already takes title bar
            // height into account.  In other cases above
            // IslandWindow::GetTotalNonClientExclusiveSize() is called, and it
            // doesn't take the title bar height into account, so we have to do
            // the calculation manually.
        }

Review comment (suggestion):
This might be problematic. The default settings for the default profile might not be what's currently active in that terminal window. Consider the scenario where you ctrl+mouse to increase the font size. The settings object doesn't actually know about that change, only the `TermControl` raising the event does.

I bet this could be solved by having the TermControl itself handle the `WindowSizeChanged` from the `ControlCore` (instead of straight bubbling it). The TermControl would get the size in chars, use that to figure out how big it wants to be in DIPs, then raise the size in DIPs up to the `TerminalPage`

Code after:
    {
        return _root != nullptr ? _root->ShouldImmediatelyHandoffToElevated(_settings) : false;
    }

    // Method Description:
    // - Escape hatch for immediately dispatching requests to elevated windows
    //   when first launched. At this point in startup, the window doesn't exist
    //   yet, XAML hasn't been started, but we need to dispatch these actions.
    //   We can't just go through ProcessStartupActions, because that processes
    //   the actions async using the XAML dispatcher (which doesn't exist yet)
    // - DON'T CALL THIS if you haven't already checked
    //   ShouldImmediatelyHandoffToElevated. If you're thinking about calling
    //   this outside of the one place it's used, that's probably the wrong
    //   solution.
    // Arguments:
    // - settings: the settings we should use for dispatching these actions. At
    //   this point in startup, we hadn't otherwise been initialized with these,
    //   so use them now.
    // Return Value:
    // - <none>
    void TerminalWindow::HandoffToElevated()
    {
        if (_root)
        {
            _root->HandoffToElevated(_settings);
            return;
        }
    }

    void TerminalWindow::_WindowSizeChanged(const IInspectable&, winrt::Microsoft::Terminal::Control::WindowSizeChangedEventArgs args)
    {
        winrt::Windows::Foundation::Size pixelSize = { static_cast<float>(args.Width()), static_cast<float>(args.Height()) };
        const auto scale = static_cast<float>(DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel());

        if (!FocusMode())
        {
            if (!_settings.GlobalSettings().AlwaysShowTabs())
            {
                // Hide the title bar = off, Always show tabs = off.
                static constexpr auto titlebarHeight = 10;
                pixelSize.Height += (titlebarHeight)*scale;
            }
            else if (!_settings.GlobalSettings().ShowTabsInTitlebar())
            {
                // Hide the title bar = off, Always show tabs = on.
                static constexpr auto titlebarAndTabBarHeight = 40;
                pixelSize.Height += (titlebarAndTabBarHeight)*scale;
            }
            // Hide the title bar = on, Always show tabs = on.
            // In this case, we don't add any height because
            // NonClientIslandWindow::GetTotalNonClientExclusiveSize() gets