Repository: microsoft/terminal
File: src/host/PtySignalInputThread.cpp (C++)

Code before:
// - Refer to GH#13066 for details.
void PtySignalInputThread::CreatePseudoWindow()
{
    HWND owner = _earlyReparent.has_value() ? reinterpret_cast<HWND>((*_earlyReparent).handle) : HWND_DESKTOP;
    ServiceLocator::LocatePseudoWindow(owner);
}

// Method Description:
// - The ThreadProc for the PTY Signal Input Thread.
// Return Value:
// - S_OK if the thread runs to completion.
// - Otherwise it may cause an application termination and never return.
[[nodiscard]] HRESULT PtySignalInputThread::_InputThread() noexcept
{
    const auto shutdown = wil::scope_exit([this]() {
        _Shutdown();
    });

    for (;;)
    {
        PtySignal signalId;
        if (!_GetData(&signalId, sizeof(signalId)))
        {
            return S_OK;
        }

        switch (signalId)
        {
        case PtySignal::ShowHideWindow:
        {
            ShowHideData msg = { 0 };
            if (!_GetData(&msg, sizeof(msg)))
            {
                return S_OK;
            }

            LockConsole();
            auto Unlock = wil::scope_exit([&] { UnlockConsole(); });

            // If the client app hasn't yet connected, stash our initial
            // visibility for when we do. We default to not being visible - if a
            // terminal wants the ConPTY windows to start "visible", then they
            // should send a ShowHidePseudoConsole(..., true) to tell us to
            // initially be visible.
            //
            // Notably, if they don't, then a ShowWindow(SW_HIDE) on the ConPTY
            // HWND will initially do _nothing_, because the OS will think that
            // the window is already hidden.
            if (!_consoleConnected)
            {
                _initialShowHide = msg;

Review comment (suggestion):
I changed this in the end, so that the `_GetData` calls are all uniform and consistent. I just felt that this looks better...

Code after:
// - Refer to GH#13066 for details.
void PtySignalInputThread::CreatePseudoWindow()
{
    HWND owner = _earlyReparent.has_value() ? reinterpret_cast<HWND>((*_earlyReparent).handle) : HWND_DESKTOP;
    ServiceLocator::LocatePseudoWindow(owner);
}

// Method Description:
// - The ThreadProc for the PTY Signal Input Thread.
// Return Value:
// - S_OK if the thread runs to completion.
// - Otherwise it may cause an application termination and never return.
[[nodiscard]] HRESULT PtySignalInputThread::_InputThread() noexcept
try
{
    const auto shutdown = wil::scope_exit([this]() {
        _Shutdown();
    });

    for (;;)
    {
        PtySignal signalId;
        if (!_GetData(&signalId, sizeof(signalId)))
        {
            return S_OK;
        }

        switch (signalId)
        {
        case PtySignal::ShowHideWindow:
        {
            ShowHideData msg = { 0 };
            if (!_GetData(&msg, sizeof(msg)))
            {
                return S_OK;
            }

            LockConsole();
            auto Unlock = wil::scope_exit([&] { UnlockConsole(); });

            // If the client app hasn't yet connected, stash our initial
            // visibility for when we do. We default to not being visible - if a
            // terminal wants the ConPTY windows to start "visible", then they
            // should send a ShowHidePseudoConsole(..., true) to tell us to
            // initially be visible.
            //
            // Notably, if they don't, then a ShowWindow(SW_HIDE) on the ConPTY
            // HWND will initially do _nothing_, because the OS will think that
            // the window is already hidden.
            if (!_consoleConnected)
            {