Merge pull request #1082 from The-Compiler/key-injected-helper

Add keyIsInjected helper
pull/1085/head
Jesse Vincent 3 years ago committed by GitHub
commit e56e4e4ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -127,7 +127,7 @@ EventHandlerResult AutoShift::onKeyswitchEvent(KeyEvent &event) {
// If event.addr is not a physical key, ignore it; some other plugin injected // If event.addr is not a physical key, ignore it; some other plugin injected
// it. This check should be unnecessary. // it. This check should be unnecessary.
if (!event.addr.isValid() || (event.state & INJECTED) != 0) { if (!event.addr.isValid() || keyIsInjected(event.state)) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -56,7 +56,7 @@ EventHandlerResult Cycle::onNameQuery() {
} }
EventHandlerResult Cycle::onKeyEvent(KeyEvent &event) { EventHandlerResult Cycle::onKeyEvent(KeyEvent &event) {
if (event.state & INJECTED) if (keyIsInjected(event.state))
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (!isCycle(event.key)) { if (!isCycle(event.key)) {

@ -33,7 +33,7 @@ EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) {
// sticky. Last, only if there are no OneShot keys currently being held. // sticky. Last, only if there are no OneShot keys currently being held.
if (event.key == cancel_oneshot_key_ && if (event.key == cancel_oneshot_key_ &&
keyToggledOn(event.state) && keyToggledOn(event.state) &&
(event.state & INJECTED) == 0 && !keyIsInjected(event.state) &&
::OneShot.isActive()) { ::OneShot.isActive()) {
// Cancel all OneShot keys // Cancel all OneShot keys
::OneShot.cancel(true); ::OneShot.cancel(true);

@ -144,7 +144,7 @@ EventHandlerResult Heatmap::onKeyEvent(KeyEvent &event) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
// if it is a synthetic key, skip it // if it is a synthetic key, skip it
if (event.state & INJECTED) if (keyIsInjected(event.state))
return EventHandlerResult::OK; return EventHandlerResult::OK;
// if the key is not toggled on, skip it // if the key is not toggled on, skip it

@ -68,7 +68,7 @@ EventHandlerResult AlphaSquareEffect::onKeyEvent(KeyEvent &event) {
if (::LEDControl.get_mode_index() != led_mode_id_) if (::LEDControl.get_mode_index() != led_mode_id_)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (event.state & INJECTED) if (keyIsInjected(event.state))
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (event.key < Key_A || event.key > Key_0) if (event.key < Key_A || event.key > Key_0)

@ -215,7 +215,7 @@ EventHandlerResult OneShot::onKeyEvent(KeyEvent& event) {
// hook functions generate (by calling `injectNormalKey()` via one of the // hook functions generate (by calling `injectNormalKey()` via one of the
// `*OneShot()` functions). There are more robust ways to do this, but since // `*OneShot()` functions). There are more robust ways to do this, but since
// OneShot is intended to react to only physical keypresses, this is adequate. // OneShot is intended to react to only physical keypresses, this is adequate.
if (event.state & INJECTED) if (keyIsInjected(event.state))
return EventHandlerResult::OK; return EventHandlerResult::OK;
bool temp = temp_addrs_.read(event.addr); bool temp = temp_addrs_.read(event.addr);

@ -48,7 +48,7 @@ EventHandlerResult Qukeys::onKeyswitchEvent(KeyEvent &event) {
} }
// If event.addr is not a physical key, ignore it; some other plugin injected it. // If event.addr is not a physical key, ignore it; some other plugin injected it.
if (! event.addr.isValid() || (event.state & INJECTED) != 0) { if (! event.addr.isValid() || keyIsInjected(event.state)) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -100,7 +100,7 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(KeyEvent &event) {
// If event.addr is not a physical key, ignore it; some other plugin injected // If event.addr is not a physical key, ignore it; some other plugin injected
// it. This check should be unnecessary. // it. This check should be unnecessary.
if (!event.addr.isValid() || (event.state & INJECTED) != 0) { if (!event.addr.isValid() || keyIsInjected(event.state)) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -68,7 +68,7 @@ EventHandlerResult Syster::onKeyEvent(KeyEvent &event) {
// Always ignore events marked as artificially injected (it might actually be // Always ignore events marked as artificially injected (it might actually be
// better to drop this, but it's not really clear). // better to drop this, but it's not really clear).
if (event.state & INJECTED) if (keyIsInjected(event.state))
return EventHandlerResult::OK; return EventHandlerResult::OK;
// If a Syster key gets pressed while we're reading an input sequence, ignore // If a Syster key gets pressed while we're reading an input sequence, ignore

@ -83,7 +83,7 @@ EventHandlerResult TapDance::onKeyswitchEvent(KeyEvent &event) {
} }
// If event.addr is not a physical key, ignore it; some other plugin injected it. // If event.addr is not a physical key, ignore it; some other plugin injected it.
if (! event.addr.isValid() || (event.state & INJECTED) != 0) { if (! event.addr.isValid() || keyIsInjected(event.state)) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -50,3 +50,9 @@
* "key-up" event. * "key-up" event.
*/ */
#define keyToggledOff(keyState) (keyWasPressed(keyState) && ! keyIsPressed(keyState)) #define keyToggledOff(keyState) (keyWasPressed(keyState) && ! keyIsPressed(keyState))
/* keyIsInjected(): This is true if the key was marked as injected by another
* plugin, i.e. it was generated artificially instead of corresponding to a
* "real" keypress.
*/
#define keyIsInjected(keyState) ((keyState) & INJECTED)

@ -44,7 +44,7 @@ namespace plugin {
class OneShotInsert : public Plugin { class OneShotInsert : public Plugin {
public: public:
EventHandlerResult onKeyEvent(KeyEvent &event) { EventHandlerResult onKeyEvent(KeyEvent &event) {
if (keyToggledOn(event.state) && (event.state & INJECTED) == 0 && if (keyToggledOn(event.state) && !keyIsInjected(event.state) &&
event.key == Key_Insert && live_keys[event.addr] != event.key) event.key == Key_Insert && live_keys[event.addr] != event.key)
::OneShot.setPending(event.addr); ::OneShot.setPending(event.addr);
return EventHandlerResult::OK; return EventHandlerResult::OK;

Loading…
Cancel
Save