Fix opening several times the "save changes" alert (fix #2467)

This could happen if we clicked the cross icon in tabs without moving
the mouse.
This commit is contained in:
David Capello 2020-08-04 15:09:33 -03:00
parent 819517b941
commit 6862bb8ab0
2 changed files with 32 additions and 30 deletions

View File

@ -518,30 +518,7 @@ void Manager::handleMouseMove(const gfx::Point& mousePos,
const PointerType pointerType, const PointerType pointerType,
const float pressure) const float pressure)
{ {
// Get the list of widgets to send mouse messages. updateMouseWidgets(mousePos);
mouse_widgets_list.clear();
broadcastMouseMessage(mouse_widgets_list);
// Get the widget under the mouse
Widget* widget = nullptr;
for (auto mouseWidget : mouse_widgets_list) {
widget = mouseWidget->pick(mousePos);
if (widget) {
// Get the first ancestor of the picked widget that doesn't
// ignore mouse events.
while (widget && widget->hasFlags(IGNORE_MOUSE))
widget = widget->parent();
break;
}
}
// Fixup "mouse" flag
if (widget != mouse_widget) {
if (!widget)
freeMouse();
else
setMouse(widget);
}
// Send the mouse movement message // Send the mouse movement message
Widget* dst = (capture_widget ? capture_widget: mouse_widget); Widget* dst = (capture_widget ? capture_widget: mouse_widget);
@ -683,6 +660,34 @@ void Manager::handleWindowZOrder()
setFocus(mouse_widget); setFocus(mouse_widget);
} }
void Manager::updateMouseWidgets(const gfx::Point& mousePos)
{
// Get the list of widgets to send mouse messages.
mouse_widgets_list.clear();
broadcastMouseMessage(mouse_widgets_list);
// Get the widget under the mouse
Widget* widget = nullptr;
for (auto mouseWidget : mouse_widgets_list) {
widget = mouseWidget->pick(mousePos);
if (widget) {
// Get the first ancestor of the picked widget that doesn't
// ignore mouse events.
while (widget && widget->hasFlags(IGNORE_MOUSE))
widget = widget->parent();
break;
}
}
// Fixup "mouse" flag
if (widget != mouse_widget) {
if (!widget)
freeMouse();
else
setMouse(widget);
}
}
void Manager::dispatchMessages() void Manager::dispatchMessages()
{ {
// Send messages in the queue (mouse/key/timer/etc. events) This // Send messages in the queue (mouse/key/timer/etc. events) This
@ -1103,9 +1108,7 @@ void Manager::_openWindow(Window* window)
// Update mouse widget (as it can be a widget below the // Update mouse widget (as it can be a widget below the
// recently opened window). // recently opened window).
Widget* widget = pick(ui::get_mouse_position()); updateMouseWidgets(ui::get_mouse_position());
if (widget)
setMouse(widget);
} }
void Manager::_closeWindow(Window* window, bool redraw_background) void Manager::_closeWindow(Window* window, bool redraw_background)
@ -1160,9 +1163,7 @@ void Manager::_closeWindow(Window* window, bool redraw_background)
// Update mouse widget (as it can be a widget below the // Update mouse widget (as it can be a widget below the
// recently closed window). // recently closed window).
Widget* widget = pick(ui::get_mouse_position()); updateMouseWidgets(ui::get_mouse_position());
if (widget)
setMouse(widget);
redrawState = RedrawState::AWindowHasJustBeenClosed; redrawState = RedrawState::AWindowHasJustBeenClosed;
} }

View File

@ -145,6 +145,7 @@ namespace ui {
const KeyModifiers modifiers, const KeyModifiers modifiers,
const double magnification); const double magnification);
void handleWindowZOrder(); void handleWindowZOrder();
void updateMouseWidgets(const gfx::Point& mousePos);
int pumpQueue(); int pumpQueue();
bool sendMessageToWidget(Message* msg, Widget* widget); bool sendMessageToWidget(Message* msg, Widget* widget);