Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4681 - Fix for processing mouse bindings for next / previous history

dragonmacherff15ec0ed6b1
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/MouseBindingMouseEventDispatcher.java b/Ghidra/Framework/Docking/src/main/java/docking/MouseBindingMouseEventDispatcher.java
index 8be74a3a01..57a9629d4a 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/MouseBindingMouseEventDispatcher.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/MouseBindingMouseEventDispatcher.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -70,6 +70,17 @@ public class MouseBindingMouseEventDispatcher {
toolkit.addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK);
}
+ private boolean isSettingMouseBinding(MouseEvent e) {
+ Component destination = e.getComponent();
+ if (destination == null) {
+ Component focusOwner = focusProvider.getFocusOwner();
+ destination = focusOwner;
+ }
+
+ // This is the class we use to set mouse bindings
+ return destination instanceof MouseEntryTextField;
+ }
+
private void process(MouseEvent e) {
int id = e.getID();
@@ -77,6 +88,10 @@ public class MouseBindingMouseEventDispatcher {
return;
}
+ if (isSettingMouseBinding(e)) {
+ return; // the user is setting the binding; do not process system actions
+ }
+
// always let the application finish processing key events that it started
if (actionInProgress(e)) {
return;
@@ -126,6 +141,16 @@ public class MouseBindingMouseEventDispatcher {
new ActionEvent(source, ActionEvent.ACTION_PERFORMED, command, when, modifiers));
}
+ int eventButton = e.getButton();
+ int bindingButton = mouseBinding.getButton();
+ if (eventButton != bindingButton) {
+ // We may have missed an event or the user pressed multiple mouse buttons in an
+ // unexpected sequence. Clear the in-progress action here so we do not consume all
+ // mouse events indefinitely.
+ inProgressAction = null;
+ return false;
+ }
+
e.consume();
return true;
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/MouseEntryTextField.java b/Ghidra/Framework/Docking/src/main/java/docking/MouseEntryTextField.java
index a7b23f78f2..5ee2e14722 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/MouseEntryTextField.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/MouseEntryTextField.java
@@ -92,6 +92,15 @@ public class MouseEntryTextField extends HintTextField {
int modifiersEx = e.getModifiersEx();
int button = e.getButton();
+
+ int buttonDownMask = InputEvent.getMaskForButton(button);
+ if (button == MouseEvent.BUTTON1 && buttonDownMask == modifiersEx) {
+ // Don't allow the user to bind an unmodified left-click, as odd behavior can ensue.
+ // We can revisit this if a valid use case is found.
+ e.consume();
+ return;
+ }
+
processMouseBinding(new MouseBinding(button, modifiersEx), true);
e.consume();
}