Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the layer-dependent modifiers handling #182

Merged
merged 25 commits into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void action_exec(keyevent_t event)

#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
bool disable_action_cache = false;
int8_t pressed_actions_cache[MATRIX_ROWS][MATRIX_COLS];
uint8_t source_layers_cache[5][(MATRIX_ROWS * MATRIX_COLS + 7) / 8] = {0};

void process_action_nocache(keyrecord_t *record)
{
Expand All @@ -82,11 +82,23 @@ action_t store_or_get_action(bool pressed, keypos_t key)
if (disable_action_cache) {
return layer_switch_get_action(key);
}

uint8_t key_number = key.col + (key.row * MATRIX_COLS);
uint8_t storage_row = key_number / 8;
uint8_t storage_bit = key_number % 8;
uint8_t layer;
if (pressed) {
pressed_actions_cache[key.row][key.col] = layer_switch_get_layer(key);
layer = layer_switch_get_layer(key);
for (uint8_t bit_number = 0; bit_number <= 4; bit_number++) {
source_layers_cache[bit_number][storage_row] ^= (-(bool)((layer & (1U << bit_number)) != 0) ^ source_layers_cache[bit_number][storage_row])) & (1U << storage_bit);
}
}
else {
layer = 0;
for (uint8_t bit_number = 0; bit_number <= 4; bit_number++) {
layer |= (uint8_t)((source_layers_cache[bit_number][storage_row] & (1U << storage_bit)) != 0) << bit_number;
}
}
return action_for_key(pressed_actions_cache[key.row][key.col], key);
return action_for_key(layer, key);
#else
return layer_switch_get_action(key);
#endif
Expand Down
1 change: 0 additions & 1 deletion tmk_core/common/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
/* Utilities for actions. */
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
extern bool disable_action_cache;
extern int8_t pressed_actions_cache[MATRIX_ROWS][MATRIX_COLS];
#endif
void process_action_nocache(keyrecord_t *record);
void process_action(keyrecord_t *record);
Expand Down