From 43fa7efaaa6a6fe6456c008a91e00407a3f7950f Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 18 Mar 2020 18:29:42 +0100 Subject: [PATCH] tform: do not stop mouse button capture until all buttons are released We may want to consider a more elegant solution for capturing in the future. In the meantime, this fixes #843. --- panda/src/tform/mouseWatcher.cxx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index 74cb7692d3..44258bfe45 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -990,9 +990,6 @@ release(ButtonHandle button) { // Button up. Send the up event associated with the region(s) we were // over when the button went down. - // There is some danger of losing button-up events here. If more than one - // button goes down together, we won't detect both of the button-up events - // properly. if (_preferred_button_down_region != nullptr) { param.set_outside(_preferred_button_down_region != _preferred_region); _preferred_button_down_region->release(param); @@ -1000,8 +997,22 @@ release(ButtonHandle button) { _preferred_button_down_region, button); } - _button_down = false; - _preferred_button_down_region = nullptr; + // Do not stop capturing until the last mouse button has gone up. This is + // needed to prevent stopping the capture until the capturing region has + // finished processing all the releases. + bool has_button = false; + for (size_t i = 0; i < MouseButton::num_mouse_buttons; ++i) { + if (MouseButton::_buttons[i] != button && + _current_buttons_down.get_bit(MouseButton::_buttons[i].get_index())) { + has_button = true; + } + } + + if (!has_button) { + // The last mouse button went up. + _button_down = false; + _preferred_button_down_region = nullptr; + } } else { // It's a keyboard button; therefore, send the event to every region that