diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index 659a8670a8..12fe7a26f6 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -177,8 +177,17 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) { } } +#ifdef VIAL_ENCODERS_ENABLE +extern uint16_t g_vial_magic_keycode_override; +#endif + // This overrides the one in quantum/keymap_common.c uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { +#ifdef VIAL_ENCODERS_ENABLE + if (key.row == 254 && key.col == 254) + return g_vial_magic_keycode_override; +#endif + if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) { return dynamic_keymap_get_keycode(layer, key.row, key.col); } else { diff --git a/quantum/vial.c b/quantum/vial.c index fd593680a3..16328eedbb 100644 --- a/quantum/vial.c +++ b/quantum/vial.c @@ -112,6 +112,19 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) { } #ifdef VIAL_ENCODERS_ENABLE +uint16_t g_vial_magic_keycode_override; + +static void exec_keycode(uint16_t keycode) { + g_vial_magic_keycode_override = keycode; + + action_exec((keyevent_t){ + .key = (keypos_t){.row = 254, .col = 254}, .pressed = 1, .time = (timer_read() | 1) /* time should not be 0 */ + }); + action_exec((keyevent_t){ + .key = (keypos_t){.row = 254, .col = 254}, .pressed = 0, .time = (timer_read() | 1) /* time should not be 0 */ + }); +} + void vial_encoder_update(uint8_t index, bool clockwise) { uint16_t code; @@ -121,13 +134,13 @@ void vial_encoder_update(uint8_t index, bool clockwise) { if (layers & (1UL << i)) { code = dynamic_keymap_get_encoder(i, index, clockwise); if (code != KC_TRNS) { - tap_code16(code); + exec_keycode(code); return; } } } /* fall back to layer 0 */ code = dynamic_keymap_get_encoder(0, index, clockwise); - tap_code16(code); + exec_keycode(code); } #endif