Browse Source

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.
rdb 5 years ago
parent
commit
43fa7efaaa
1 changed files with 16 additions and 5 deletions
  1. 16 5
      panda/src/tform/mouseWatcher.cxx

+ 16 - 5
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
     // Button up.  Send the up event associated with the region(s) we were
     // over when the button went down.
     // 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) {
     if (_preferred_button_down_region != nullptr) {
       param.set_outside(_preferred_button_down_region != _preferred_region);
       param.set_outside(_preferred_button_down_region != _preferred_region);
       _preferred_button_down_region->release(param);
       _preferred_button_down_region->release(param);
@@ -1000,8 +997,22 @@ release(ButtonHandle button) {
                           _preferred_button_down_region, 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 {
   } else {
     // It's a keyboard button; therefore, send the event to every region that
     // It's a keyboard button; therefore, send the event to every region that