RebindingOperation.WithMatchingEventsBeingSuppressed allows for events to be suppressed during rebinding operations, or passed-through to any Actions (usually to allow UI). Currently it only supports a flag set prior to the operation - used to set InputEventPtr.handled.
private unsafe void OnEvent(InputEventPtr eventPtr, InputDevice device) {
[...]
if (suppressEvent && (m_Flags & Flags.SuppressMatchingEvents) != 0)
eventPtr.handled = true;
This doesn’t allow for any dynamic logic during the operation - like whether a valid UI selection/hover exists, or whether an accessibility-modifier needs to be ignored.
The only public callback right now that provides access to the event-pointer is ComputeScore, which has its own issues, as it doesn’t provide the Operation object, default score, or any other access to the magnitude array. You also can’t add/remove candidates at that stage.
Would love to see a callback option instead (below), that returns a suppression/event-handled flag, and provides the Operation context and current InputControl. Leaves the option of whether to keep it as a candidate, cancel, etc.
private Func<RebindingOperation, InputControl, bool> m_OnSuppressEvent;
public RebindingOperation OnSuppressMatchingEvent(Func<RebindingOperation, InputControl, bool> callback) {
ThrowIfRebindInProgress();
m_OnSuppressEvent = callback;
return this;
}
private OnEvent {
bool suppressEvent; // existing local var
// In OnEvent, after scoring, and before OnPotentialMatch or OnComplete are called
foreach (var control in eventPtr.EnumerateControls...) {
[...]
if (m_OnSuppressEvent != null) {
suppressEvent = suppressEvent && m_OnSuppressEvent(this, control);
}
}
// Edited: handler can just modify the existing 'suppressEvent' var
if (suppressEvent && (m_Flags & Flags.SuppressMatchingEvents) != 0)
eventPtr.handled = true;
}