diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 1a047dfa276..06724b461fa 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1742,6 +1742,11 @@ void Viewport::_gui_input_event(Ref p_event) { if (mb.is_valid()) { Point2 mpos = mb->get_position(); if (mb->is_pressed()) { + if (gui.dragging && mb->get_button_index() == MouseButton::RIGHT) { + _perform_drop(); + set_input_as_handled(); + return; + } MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index()); if (!gui.mouse_focus_mask.is_empty() && !gui.mouse_focus_mask.has_flag(button_mask)) { // Do not steal mouse focus and stuff while a focus mask without the current mouse button exists. diff --git a/tests/scene/test_viewport.h b/tests/scene/test_viewport.h index 06a38f234b0..dbf348ba962 100644 --- a/tests/scene/test_viewport.h +++ b/tests/scene/test_viewport.h @@ -1341,8 +1341,8 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE); // Force Drop doesn't get triggered by mouse Buttons other than LMB. - SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE); - SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE); + SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::MIDDLE, MouseButtonMask::MIDDLE, Key::NONE); + SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::MIDDLE, MouseButtonMask::NONE, Key::NONE); CHECK(root->gui_is_dragging()); // Force Drop with LMB-Down. @@ -1351,6 +1351,15 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") { CHECK(root->gui_is_drag_successful()); SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE); + + node_a->force_drag(SNAME("Drag Data"), nullptr); + CHECK(root->gui_is_dragging()); + + // Cancel with RMB. + SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE); + CHECK_FALSE(root->gui_is_dragging()); + CHECK_FALSE(root->gui_is_drag_successful()); + SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE); } }