Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Monarch/Peasant & Make UI single-threaded #18215

Merged
merged 29 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7853853
List of monarchs who lost their thrones in the 21st century
lhecker Nov 19, 2024
3dee5c0
Revert WindowsTerminal.vcxproj
lhecker Nov 19, 2024
16900fd
Fix window singleton for unpackaged builds
lhecker Nov 19, 2024
25d1c71
Dismiss tray icon on exit
lhecker Nov 19, 2024
c7d1393
Fix _quake summoning
lhecker Nov 19, 2024
5faf0f6
Fix formatting
lhecker Nov 19, 2024
82902f2
Merge remote-tracking branch 'origin/main' into dev/lhecker/dethronement
lhecker Nov 22, 2024
06066d5
Fix wt /?
lhecker Nov 22, 2024
1aafccb
Fix tab dragging between windows
lhecker Nov 22, 2024
0862e90
Address feedback
lhecker Nov 22, 2024
c66ad24
Don't include the pch in header files
lhecker Nov 26, 2024
f0449d7
Remove unused code
lhecker Nov 26, 2024
f665c2f
Prevent the CoreWindow from getting destroyed
lhecker Nov 26, 2024
88a5302
Fix the touch input panel
lhecker Nov 26, 2024
8682ae1
A more sensible timeout
lhecker Nov 26, 2024
d84aa79
Fix tab drag window position
lhecker Nov 26, 2024
b353d41
Fix spelling
lhecker Dec 2, 2024
26c407b
Merge remote-tracking branch 'origin/main' into dev/lhecker/dethronement
lhecker Dec 2, 2024
d7e2a3c
Lazy-init IVirtualDesktopManager
lhecker Dec 5, 2024
0beb916
Address feedback
lhecker Dec 5, 2024
84eb929
Const-correctness
lhecker Dec 5, 2024
717c4c2
Some subjective cleanup
lhecker Dec 5, 2024
c9151e1
Fix WindowEmperor not reacing HWND_BROADCAST messages
lhecker Dec 5, 2024
53ec62d
Merge remote-tracking branch 'origin/main' into dev/lhecker/dethronement
lhecker Dec 5, 2024
314d8c2
Merge remote-tracking branch 'origin/main' into dev/lhecker/dethronement
lhecker Dec 10, 2024
5ca8264
Address feedback
lhecker Dec 11, 2024
26877d4
Reduce nesting in the window message handler
lhecker Dec 11, 2024
90cbe94
Fix typo
lhecker Dec 11, 2024
fea2660
Fix the message box
lhecker Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,22 +687,30 @@ void WindowEmperor::_createMessageWindow(const wchar_t* className)

void WindowEmperor::_postQuitMessageIfNeeded() const
{
if (_windows.empty() && !_app.Logic().Settings().GlobalSettings().AllowHeadless())
if (_messageBoxCount <= 0 && _windows.empty() && !_app.Logic().Settings().GlobalSettings().AllowHeadless())
{
PostQuitMessage(0);
}
}

safe_void_coroutine WindowEmperor::_showMessageBox(winrt::hstring message, bool error) const
safe_void_coroutine WindowEmperor::_showMessageBox(winrt::hstring message, bool error)
{
const auto hwnd = _window.get();
// Prevent the main loop from exiting until the message box is closed.
// Once the loop exits, the app exits, and the message box will be closed.
_messageBoxCount += 1;
const auto decrement = wil::scope_exit([hwnd = _window.get()]() noexcept {
PostMessageW(hwnd, WM_MESSAGE_BOX_CLOSED, 0, 0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the reason I went with PostMessageW instead of resume_foreground is because I think it's crucial that this does not fail so that the ref-count does not go out of sync. I think PostMessageW is fundamentally more robust in that regard.

});

// We must yield to a background thread, because MessageBoxW() is a blocking call, and we can't
// block the main thread. That would prevent us from servicing WM_COPYDATA messages and similar.
co_await winrt::resume_background();

const auto messageTitle = error ? IDS_ERROR_DIALOG_TITLE : IDS_HELP_DIALOG_TITLE;
const auto messageIcon = error ? MB_ICONERROR : MB_ICONWARNING;
// The dialog cannot have our _window as the parent, because that one is always hidden/invisible.
// TODO:GH#4134: polish this dialog more, to make the text more like msiexec /?
MessageBoxW(hwnd, message.c_str(), GetStringResource(messageTitle).data(), MB_OK | messageIcon);
MessageBoxW(nullptr, message.c_str(), GetStringResource(messageTitle).c_str(), MB_OK | messageIcon);
}

LRESULT WindowEmperor::_messageHandler(HWND window, UINT const message, WPARAM const wParam, LPARAM const lParam) noexcept
Expand Down Expand Up @@ -730,6 +738,11 @@ LRESULT WindowEmperor::_messageHandler(HWND window, UINT const message, WPARAM c
_postQuitMessageIfNeeded();
return 0;
}
case WM_MESSAGE_BOX_CLOSED:
// Counterpart specific to _showMessageBox().
_messageBoxCount -= 1;
_postQuitMessageIfNeeded();
return 0;
case WM_IDENTIFY_ALL_WINDOWS:
for (const auto& host : _windows)
{
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/WindowEmperor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WindowEmperor
enum UserMessages : UINT
{
WM_CLOSE_TERMINAL_WINDOW = WM_USER,
WM_MESSAGE_BOX_CLOSED,
WM_IDENTIFY_ALL_WINDOWS,
WM_NOTIFY_FROM_NOTIFICATION_AREA,
};
Expand Down Expand Up @@ -54,6 +55,7 @@ class WindowEmperor
LRESULT _messageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam) noexcept;
void _createMessageWindow(const wchar_t* className);
void _postQuitMessageIfNeeded() const;
safe_void_coroutine _showMessageBox(winrt::hstring message, bool error);
void _notificationAreaMenuRequested(WPARAM wParam);
void _notificationAreaMenuClicked(WPARAM wParam, LPARAM lParam) const;
void _hotkeyPressed(long hotkeyIndex);
Expand All @@ -74,6 +76,7 @@ class WindowEmperor
bool _forcePersistence = false;
bool _needsPersistenceCleanup = false;
std::optional<bool> _currentSystemThemeIsDark;
int32_t _messageBoxCount = 0;

#ifdef NDEBUG
static constexpr void _assertIsMainThread() noexcept
Expand Down
Loading