fix(keymaps): fix keypresses that are not in the transform
Before this change, if a matrix position was not present in the transform, various incorrect behaviors would happen: 1) In some cases out-of-bounds accesses: Note that the size of the`transform[]` array does not necessarily match the size of the matrix. So for example if key position (ZMK_MATRIX_COLS-1, ZMK_MATRIX_ROWS-1) is not present in the transform, but ends up being pressed, then the array will be accessed beyond its size, and any data could be returned. 2) In other cases the 0th position in the keymap will be used because the `transform[]` array is initialized to all zeros.
This commit is contained in:
parent
ee9fcec3c9
commit
309359b32f
3 changed files with 43 additions and 11 deletions
|
|
@ -47,7 +47,14 @@ void zmk_kscan_process_msgq(struct k_work *item) {
|
|||
|
||||
while (k_msgq_get(&zmk_kscan_msgq, &ev, K_NO_WAIT) == 0) {
|
||||
bool pressed = (ev.state == ZMK_KSCAN_EVENT_STATE_PRESSED);
|
||||
uint32_t position = zmk_matrix_transform_row_column_to_position(ev.row, ev.column);
|
||||
int32_t position = zmk_matrix_transform_row_column_to_position(ev.row, ev.column);
|
||||
|
||||
if (position < 0) {
|
||||
LOG_WRN("Not found in transform: row: %d, col: %d, pressed: %s", ev.row, ev.column,
|
||||
(pressed ? "true" : "false"));
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG_DBG("Row: %d, col: %d, position: %d, pressed: %s", ev.row, ev.column, position,
|
||||
(pressed ? "true" : "false"));
|
||||
ZMK_EVENT_RAISE(new_zmk_position_state_changed(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue