Merge pull request #88588 from akien-mga/revert-86952-fix-selecting-popup-menu-items-on-mouse-release

Revert "Fix selecting popup menu items on mouse release"
This commit is contained in:
Rémi Verschelde 2024-02-20 10:31:09 +01:00
commit 9f4499c109
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 48 additions and 53 deletions

View file

@ -456,9 +456,6 @@ void PopupMenu::_input_from_window(const Ref<InputEvent> &p_event) {
} }
void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) { void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
Ref<InputEventMouseMotion> m = p_event;
if (!items.is_empty()) { if (!items.is_empty()) {
Input *input = Input::get_singleton(); Input *input = Input::get_singleton();
Ref<InputEventJoypadMotion> joypadmotion_event = p_event; Ref<InputEventJoypadMotion> joypadmotion_event = p_event;
@ -587,44 +584,35 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
} }
} }
if (m.is_valid() && drag_to_press) { Ref<InputEventMouseButton> b = p_event;
BitField<MouseButtonMask> initial_button_mask = m->get_button_mask();
if (!initial_button_mask.has_flag(mouse_button_to_mask(MouseButton::LEFT)) && !initial_button_mask.has_flag(mouse_button_to_mask(MouseButton::RIGHT))) {
mouse_is_pressed = false;
}
if (!item_clickable_area.has_point(m->get_position()) && !mouse_is_pressed) {
drag_to_press = false;
}
}
if ((b.is_valid() && b->is_pressed()) || (!mouse_is_pressed && drag_to_press)) {
if (b.is_valid()) { if (b.is_valid()) {
MouseButton button_idx = b->get_button_index(); if (!item_clickable_area.has_point(b->get_position())) {
if (button_idx != MouseButton::LEFT && button_idx != MouseButton::RIGHT) {
return; return;
} }
} else {
MouseButton button_idx = b->get_button_index();
if (!b->is_pressed()) {
// Activate the item on release of either the left mouse button or
// any mouse button held down when the popup was opened.
// This allows for opening the popup and triggering an action in a single mouse click.
if (button_idx == MouseButton::LEFT || initial_button_mask.has_flag(mouse_button_to_mask(button_idx))) {
bool was_during_grabbed_click = during_grabbed_click;
during_grabbed_click = false;
initial_button_mask.clear();
// Disable clicks under a time threshold to avoid selection right when opening the popup.
uint64_t now = OS::get_singleton()->get_ticks_msec(); uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - popup_time_msec; uint64_t diff = now - popup_time_msec;
if (diff < 250) { if (diff < 150) {
drag_to_press = false;
return; return;
} }
}
drag_to_press = false;
int over = -1;
if (m.is_valid()) {
over = _get_mouse_over(m->get_position());
} else if (b.is_valid()) {
over = _get_mouse_over(b->get_position());
}
int over = _get_mouse_over(b->get_position());
if (over < 0) { if (over < 0) {
if (!was_during_grabbed_click) {
hide(); hide();
}
return; return;
} }
@ -638,6 +626,10 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
} }
activate_item(over); activate_item(over);
} }
}
}
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) { if (m.is_valid()) {
if (m->get_velocity().is_zero_approx()) { if (m->get_velocity().is_zero_approx()) {
@ -1070,6 +1062,11 @@ void PopupMenu::_notification(int p_what) {
} }
} break; } break;
case NOTIFICATION_POST_POPUP: {
initial_button_mask = Input::get_singleton()->get_mouse_button_mask();
during_grabbed_click = (bool)initial_button_mask;
} break;
case NOTIFICATION_INTERNAL_PROCESS: { case NOTIFICATION_INTERNAL_PROCESS: {
Input *input = Input::get_singleton(); Input *input = Input::get_singleton();
@ -2805,8 +2802,6 @@ void PopupMenu::popup(const Rect2i &p_bounds) {
moved = Vector2(); moved = Vector2();
popup_time_msec = OS::get_singleton()->get_ticks_msec(); popup_time_msec = OS::get_singleton()->get_ticks_msec();
Popup::popup(p_bounds); Popup::popup(p_bounds);
drag_to_press = true;
mouse_is_pressed = true;
} }
PopupMenu::PopupMenu() { PopupMenu::PopupMenu() {

View file

@ -107,8 +107,8 @@ class PopupMenu : public Popup {
Timer *submenu_timer = nullptr; Timer *submenu_timer = nullptr;
List<Rect2> autohide_areas; List<Rect2> autohide_areas;
Vector<Item> items; Vector<Item> items;
bool mouse_is_pressed = true; BitField<MouseButtonMask> initial_button_mask;
bool drag_to_press = true; bool during_grabbed_click = false;
int mouse_over = -1; int mouse_over = -1;
int submenu_over = -1; int submenu_over = -1;
String _get_accel_text(const Item &p_item) const; String _get_accel_text(const Item &p_item) const;