Repository: microsoft/terminal
File: src/cascadia/WindowsTerminal/IslandWindow.cpp (C++)

Code before:
    // different API surface for enabling Mica on Windows 11 22000.0.
    //
    // This API was only publicly supported as of Windows 11 SV2, 22621. Before
    // that version, this API will just return an error and do nothing silently.

    const int attribute = newValue ? DWMSBT_MAINWINDOW : DWMSBT_NONE;
    LOG_IF_FAILED(DwmSetWindowAttribute(GetHandle(), DWMWA_SYSTEMBACKDROP_TYPE, &attribute, sizeof(attribute)));
}

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
[[nodiscard]] LRESULT IslandWindow::OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
    const auto ret = BaseWindow::OnNcCreate(wParam, lParam);
    if (!ret)
    {
        return FALSE;
    }

    // This is a hack to make the window borders dark instead of light.
    // It must be done before WM_NCPAINT so that the borders are rendered with
    // the correct theme.
    // For more information, see GH#6620.
    LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true));

    return TRUE;
}


Review comment (refactor):
Can we guarantee that we'll always call `_updateTheme()`? If so, we could probably remove this.

Also, why do we pass in `true` for the second param here? I get that we should normally pass in the value from the theme and that's not ready yet, but should we even bother calling this function here then if we're waiting for the theme to load anyways?

Code after:
}

void IslandWindow::UseMica(const bool newValue, const double /*titlebarOpacity*/)
{
    // This block of code enables Mica for our window. By all accounts, this
    // version of the code will only work on Windows 11, SV2. There's a slightly
    // different API surface for enabling Mica on Windows 11 22000.0.
    //
    // This API was only publicly supported as of Windows 11 SV2, 22621. Before
    // that version, this API will just return an error and do nothing silently.

    const int attribute = newValue ? DWMSBT_MAINWINDOW : DWMSBT_NONE;
    std::ignore = DwmSetWindowAttribute(GetHandle(), DWMWA_SYSTEMBACKDROP_TYPE, &attribute, sizeof(attribute));
}

// Method Description:
// - This method is called when the window receives the WM_NCCREATE message.
// Return Value:
// - The value returned from the window proc.
[[nodiscard]] LRESULT IslandWindow::OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept
{
    const auto ret = BaseWindow::OnNcCreate(wParam, lParam);
    if (!ret)
    {
        return FALSE;
    }

    // This is a hack to make the window borders dark instead of light.
    // It must be done before WM_NCPAINT so that the borders are rendered with
    // the correct theme.
    // For more information, see GH#6620.
    //
    // Theoretically, we don't need this anymore, since _updateTheme will update
    // the darkness of our window. However, we're keeping this call to prevent
    // the window from appearing as a white rectangle for a frame before we load
    // the rest of the settings.
    LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true));

    return TRUE;
}