Don't send paint messages when we are closing the app

This commit is contained in:
David Capello 2021-03-03 09:53:52 -03:00
parent d7e154b726
commit 777a0f132a

View File

@ -60,6 +60,7 @@ enum class RedrawState {
Normal,
AWindowHasJustBeenClosed,
RedrawDelayed,
ClosingApp,
};
RedrawState redrawState = RedrawState::Normal;
@ -807,11 +808,14 @@ void Manager::dispatchMessages()
// returns a number greater than 0, it means that we've processed
// some messages, so we've to redraw the screen.
if (pumpQueue() > 0 || redrawState == RedrawState::RedrawDelayed) {
if (redrawState == RedrawState::ClosingApp) {
// Do nothing, we don't flush nor process paint messages
}
// If a window has just been closed with Manager::_closeWindow()
// after processing messages, we'll wait the next event generation
// to process painting events (so the manager doesn't lost the
// DIRTY flag right now).
if (redrawState == RedrawState::AWindowHasJustBeenClosed) {
else if (redrawState == RedrawState::AWindowHasJustBeenClosed) {
redrawState = RedrawState::RedrawDelayed;
}
else {
@ -1243,6 +1247,10 @@ void Manager::_openWindow(Window* window, bool center)
Display* parentDisplay = getForegroundDisplay();
ASSERT(parentDisplay);
// Opening other window in the "close app" state, ok, let's back to normal.
if (redrawState == RedrawState::ClosingApp)
redrawState = RedrawState::Normal;
// Free all widgets of special states.
if (window->isWantFocus()) {
freeCapture();
@ -1441,7 +1449,13 @@ void Manager::_closeWindow(Window* window, bool redraw_background)
// recently closed window).
updateMouseWidgets(ui::get_mouse_position(), nullptr);
if (children().empty()) {
// All windows were closed...
redrawState = RedrawState::ClosingApp;
}
else {
redrawState = RedrawState::AWindowHasJustBeenClosed;
}
}
void Manager::_runModalWindow(Window* window)
@ -1782,6 +1796,10 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
if (widget->hasFlags(HIDDEN))
return false;
// Ignore all paint messages when we are closing the app
if (redrawState == RedrawState::ClosingApp)
return false;
PaintMessage* paintMsg = static_cast<PaintMessage*>(msg);
// TODO use paintMsg->display() here