Skip to content

Commit

Permalink
fix(core): update core to handle reset context
Browse files Browse the repository at this point in the history
- range check vk
- split modifier test out to separate function
  • Loading branch information
srl295 committed Apr 15, 2024
1 parent 699d576 commit 4f8c9eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 1 addition & 4 deletions core/src/km_core_state_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,7 @@ state_should_invalidate_context(km_core_state *state,
if (vk == KM_CORE_VKEY_BKSP && state->context().empty()) {
return true; // context is empty - so pass back
} else if (is_key_down &&
// either a ctrl or alt modifier
((modifier_state & (K_CTRLFLAG | K_ALTFLAG | LCTRLFLAG | RCTRLFLAG | LALTFLAG | RALTFLAG))
// or a frame key
|| vkey_to_contextreset[vk])) {
(modifier_should_contextreset(modifier_state) || vkey_should_contextreset(vk))) {
return true;
}
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/vkey_to_contextreset.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#pragma once

#include <iterator>
#include <keyman/keyman_core_api.h>
#include "kmx_file.h"

namespace km {
namespace core {

/** true for any vkeys which require a context reset (such as frame keys) */
extern bool vkey_to_contextreset[256];

/** @return true for any vkeys which require a context reset (such as frame keys) */
inline bool vkey_should_contextreset(km_core_virtual_key vk) {
return ((vk < std::size(vkey_to_contextreset)) && vkey_to_contextreset[vk]);
}

/** @return true for modifier states that are involved with context reset */
inline bool modifier_should_contextreset(uint16_t modifier_state) {
// ctrl or alt
return (modifier_state & (K_CTRLFLAG | K_ALTFLAG | LCTRLFLAG | RCTRLFLAG | LALTFLAG | RALTFLAG));
}


}
}

0 comments on commit 4f8c9eb

Please sign in to comment.