diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 25c3ced3da6..1c1a479b0bd 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2496,6 +2496,17 @@ void Viewport::_gui_input_event(Ref p_event) { } } +void Viewport::_gui_cleanup_internal_state(Ref p_event) { + ERR_FAIL_COND(p_event.is_null()); + + Ref mb = p_event; + if (mb.is_valid()) { + if (!mb->is_pressed()) { + gui.mouse_focus_mask &= ~(1 << (mb->get_button_index() - 1)); // Remove from mask. + } + } +} + List::Element *Viewport::_gui_add_root_control(Control *p_control) { gui.roots_order_dirty = true; return gui.roots.push_back(p_control); @@ -2851,6 +2862,8 @@ void Viewport::input(const Ref &p_event) { if (!is_input_handled()) { _gui_input_event(p_event); + } else { + _gui_cleanup_internal_state(p_event); } //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index c7ef4834d83..a4d22805981 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -340,6 +340,7 @@ private: Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform); void _gui_input_event(Ref p_event); + void _gui_cleanup_internal_state(Ref p_event); void update_worlds();