Add `afterReportingState()` event handler function

This event handler is useful for plugins that need to react to events, but
should wait until after those events are fully processed before doing so.  This
is useful for OneShot, which needs to keep keys active until after events that
trigger their release.  The `afterEachCycle()` hook is unfortunately
insufficient for this purpose, because the same event could trigger multiple
plugins (e.g. TapDance & OneShot) to resolve events, and the OneShot should
apply only to the first ensuing report.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1035/head
Michael Richters 4 years ago
parent c9a98ecb26
commit 92f2f582f1
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -183,6 +183,14 @@ abortable. That is, if it returns a result other than `OK` it will stop the
subsequent handlers from getting called, and if it returns `ABORT`, it will also subsequent handlers from getting called, and if it returns `ABORT`, it will also
stop the report from being sent.] stop the report from being sent.]
### `afterReportingState(const KeyEvent &event)`
This gets called after the HID report is sent. This handler allows a plugin to
react to an event, but wait until after that event has been fully processed to
do so. For example, the OneShot plugin releases keys that are in the "one-shot"
state in response to key press events, but it does so after those triggering
press events take place.
## Other events ## Other events
### `onLayerChange()` ### `onLayerChange()`

@ -219,6 +219,11 @@ Runtime_::handleKeyEvent(KeyEvent event) {
// Finally, send the new keyboard report // Finally, send the new keyboard report
sendKeyboardReport(event); sendKeyboardReport(event);
// Now that the report has been sent, let plugins act on it after the fact.
// This is useful for plugins that need to react to an event, but must wait
// until after that event is processed to do so.
Hooks::afterReportingState(event);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

@ -264,6 +264,19 @@ class SignatureCheckDummy {};
(const KeyEvent &event), __NL__ \ (const KeyEvent &event), __NL__ \
(event), ##__VA_ARGS__) __NL__ \ (event), ##__VA_ARGS__) __NL__ \
__NL__ \ __NL__ \
/* Called after reporting our state to the host. This is the last */ __NL__ \
/* point at which a plugin can do something in response to an event */ __NL__ \
/* before the next event is processed, if multiple events occur in */ __NL__ \
/* and are processed in a single cycle (usually due to delayed */ __NL__ \
/* events or generated events). */ __NL__ \
OPERATION(afterReportingState, __NL__ \
1, __NL__ \
_CURRENT_IMPLEMENTATION, __NL__ \
_NOT_ABORTABLE, __NL__ \
(),(),(), /* non template */ __NL__ \
(const KeyEvent &event), __NL__ \
(event), ##__VA_ARGS__) __NL__ \
__NL__ \
/* Called at the very end of a cycle, after everything's */ __NL__ \ /* Called at the very end of a cycle, after everything's */ __NL__ \
/* said and done. */ __NL__ \ /* said and done. */ __NL__ \
OPERATION(afterEachCycle, __NL__ \ OPERATION(afterEachCycle, __NL__ \
@ -351,6 +364,10 @@ class SignatureCheckDummy {};
OP(beforeReportingState, 2) __NL__ \ OP(beforeReportingState, 2) __NL__ \
END(beforeReportingState, 1, 2) __NL__ \ END(beforeReportingState, 1, 2) __NL__ \
__NL__ \ __NL__ \
START(afterReportingState, 1) __NL__ \
OP(afterReportingState, 1) __NL__ \
END(afterReportingState, 1) __NL__ \
__NL__ \
START(afterEachCycle, 1) __NL__ \ START(afterEachCycle, 1) __NL__ \
OP(afterEachCycle, 1) __NL__ \ OP(afterEachCycle, 1) __NL__ \
END(afterEachCycle, 1) __NL__ \ END(afterEachCycle, 1) __NL__ \

Loading…
Cancel
Save