summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2020-09-18 20:45:59 +0200
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2020-09-18 20:45:59 +0200
commit54eaaf456fd538a73652690d6ff0b34bf7395e28 (patch)
treeffa2eed52a9fb3cb5504fb0ef17e9627eb2117fb
parent377c3bb25672fb7060cbd465a698661a93290e07 (diff)
downloadredot-engine-54eaaf456fd538a73652690d6ff0b34bf7395e28.tar.gz
Fix popup menu item selected when opening the menu
In order to allow selecting items by either holding left click, or click to open and click again to select, mouse button release was invalidated based on the amount of mouse motion. This was causing issues in some scenarios where an item could be selected while opening the menu if the mouse moved enough between button press and release. This case could happen in the language selection of the project manager, especially on linux, because of the order and timing of the mouse events on x11. This change invalidates mouse release based on a timing condition rather than moved distance to handle any case from the display server properly.
-rw-r--r--scene/gui/popup_menu.cpp20
-rw-r--r--scene/gui/popup_menu.h2
2 files changed, 8 insertions, 14 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index bc70809ad5..578d8a96e8 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -305,12 +305,14 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
during_grabbed_click = false;
initial_button_mask = 0;
- int over = _get_mouse_over(b->get_position());
-
- if (invalidated_click) {
- invalidated_click = false;
+ // 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 diff = now - popup_time_msec;
+ if (diff < 100) {
return;
}
+
+ int over = _get_mouse_over(b->get_position());
if (over < 0) {
if (!was_during_grabbed_click) {
hide();
@@ -338,13 +340,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
return;
}
- if (invalidated_click) {
- moved += m->get_relative();
- if (moved.length() > 4) {
- invalidated_click = false;
- }
- }
-
for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) {
_close_pressed();
@@ -1443,7 +1438,7 @@ void PopupMenu::_bind_methods() {
void PopupMenu::popup(const Rect2 &p_bounds) {
moved = Vector2();
- invalidated_click = true;
+ popup_time_msec = OS::get_singleton()->get_ticks_msec();
set_as_minsize();
Popup::popup(p_bounds);
}
@@ -1475,7 +1470,6 @@ PopupMenu::PopupMenu() {
submenu_over = -1;
initial_button_mask = 0;
during_grabbed_click = false;
- invalidated_click = false;
allow_search = true;
search_time_msec = 0;
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 9535fd07d7..e8f82ba869 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -105,7 +105,7 @@ class PopupMenu : public Popup {
void _activate_submenu(int over);
void _submenu_timeout();
- bool invalidated_click;
+ uint64_t popup_time_msec = 0;
bool hide_on_item_selection;
bool hide_on_checkable_item_selection;
bool hide_on_multistate_item_selection;