Skip to content

Commit

Permalink
This actually seems to make the lifetime management worse - we just d…
Browse files Browse the repository at this point in the history
…tor the WindowEmperor randomly now, which is no good
  • Loading branch information
zadjii-msft committed Feb 9, 2023
1 parent c69f0bc commit 7e91bdb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,27 @@ void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args, co
co_await wil::resume_foreground(this->_dispatcher);
this->_checkWindowsForNotificationIcon();
});

return window->WindowProc();
window->Exited([this, peasant]() {
// find the window in _windows who's peasant's Id matches the peasant's Id
// and remove it
_windows.erase(std::remove_if(_windows.begin(), _windows.end(), [&](const auto& w) {
return w->Peasant().GetID() == peasant.GetID();
}),
_windows.end());
if (_windows.size() == 0)
{
_close();
}
});
auto result = window->WindowProc();
return result;
};
// _threads.emplace_back(func);
// LOG_IF_FAILED(SetThreadDescription(_threads.back().native_handle(), L"Window Thread"));

_threads.emplace_back(func);

LOG_IF_FAILED(SetThreadDescription(_threads.back().native_handle(), L"Window Thread"));
std::thread myWindowThread{ func };
LOG_IF_FAILED(SetThreadDescription(myWindowThread.native_handle(), L"Window Thread"));
myWindowThread.detach();
}

void WindowEmperor::_becomeMonarch()
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/WindowsTerminal/WindowThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,12 @@ int WindowThread::WindowProc()
TranslateMessage(&message);
DispatchMessage(&message);
}

_ExitedHandlers();
return 0;
}

winrt::Microsoft::Terminal::Remoting::Peasant WindowThread::Peasant()
{
return _peasant;
}
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/WindowThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class WindowThread
int WindowProc();

winrt::TerminalApp::TerminalWindow Logic();
winrt::Microsoft::Terminal::Remoting::Peasant Peasant();

WINRT_CALLBACK(Exited, winrt::delegate<>);

private:
::AppHost _host;
Expand Down

0 comments on commit 7e91bdb

Please sign in to comment.