sticky modifier keys!
parent
e293f31c04
commit
270feb968a
|
@ -337,8 +337,8 @@ keys = [
|
|||
# thumb-home
|
||||
# letter type punc type nav type func type
|
||||
%w{ space }, %w{ }, %w{ }, %w{ },
|
||||
%w{ control mod }, %w{ }, %w{ }, %w{ },
|
||||
%w{ alt mod }, %w{ }, %w{ }, %w{ },
|
||||
%w{ control sticky_mod }, %w{ }, %w{ }, %w{ },
|
||||
%w{ alt sticky_mod }, %w{ }, %w{ }, %w{ },
|
||||
#
|
||||
# right hand
|
||||
#
|
||||
|
|
|
@ -375,8 +375,8 @@ static const keyfunc PROGMEM _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS]
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -458,8 +458,8 @@ KB_MATRIX_LAYER(
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -541,8 +541,8 @@ KB_MATRIX_LAYER(
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -624,8 +624,8 @@ KB_MATRIX_LAYER(
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -707,8 +707,8 @@ static const keyfunc PROGMEM _kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS]
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -790,8 +790,8 @@ KB_MATRIX_LAYER(
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -873,8 +873,8 @@ KB_MATRIX_LAYER(
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
@ -956,8 +956,8 @@ KB_MATRIX_LAYER(
|
|||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_press_release,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_modifier_sticky,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
(keyfunc) &kbfun_normal_press_release,
|
||||
|
|
58
src/main.c
58
src/main.c
|
@ -68,7 +68,7 @@ static layer layers_top = 0;
|
|||
static bool sticky_on;
|
||||
static bool sticky_done;
|
||||
static bool layer_sticky[KB_LAYERS];
|
||||
static bool modifier_sticky[MODIFIERS];
|
||||
static u8 modifier_sticky;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
@ -126,6 +126,12 @@ void main_key_loop() {
|
|||
usb_keyboard_send();
|
||||
usb_extra_consumer_send();
|
||||
|
||||
// unset sticky keys if necessary
|
||||
if (sticky_on && sticky_done) {
|
||||
sticky_disable();
|
||||
usb_keyboard_send();
|
||||
}
|
||||
|
||||
// debounce in ms; see keyswitch spec for necessary value
|
||||
_delay_ms(5);
|
||||
}
|
||||
|
@ -227,25 +233,12 @@ void init_sticky() {
|
|||
layer_sticky[l] = false;
|
||||
}
|
||||
for (keycode mod=0; mod < MODIFIERS; mod++) {
|
||||
modifier_sticky[mod] = false;
|
||||
modifier_sticky = 0;
|
||||
}
|
||||
sticky_on = false;
|
||||
sticky_done = true;
|
||||
}
|
||||
|
||||
// return if highest active layer is sticky
|
||||
bool layer_top_is_sticky() {
|
||||
return layer_is_sticky(layers_top);
|
||||
}
|
||||
|
||||
// return if layer is sticky
|
||||
bool layer_is_sticky(layer l) {
|
||||
if (l < KB_LAYERS) {
|
||||
return layer_sticky[l];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void sticky_disable() {
|
||||
for (layer l = 1; l < KB_LAYERS; l++) {
|
||||
if (layer_sticky[l]) {
|
||||
|
@ -255,6 +248,12 @@ void sticky_disable() {
|
|||
}
|
||||
}
|
||||
|
||||
if (modifier_sticky) {
|
||||
debug_printf("mod %d up\n", modifier_sticky);
|
||||
keyboard_modifier_keys &= ~modifier_sticky;
|
||||
modifier_sticky = 0;
|
||||
}
|
||||
|
||||
sticky_on = false;
|
||||
sticky_done = false;
|
||||
}
|
||||
|
@ -342,10 +341,6 @@ void exec_key() {
|
|||
: kb_keyfunc_release(current_layer, current_row, current_col) );
|
||||
|
||||
if (key_function) { (*key_function)(); }
|
||||
|
||||
if (sticky_on && sticky_done) {
|
||||
sticky_disable();
|
||||
}
|
||||
}
|
||||
|
||||
// normal key
|
||||
|
@ -399,7 +394,7 @@ void kbfun_layer_sticky() {
|
|||
} else {
|
||||
if (sticky_done) {
|
||||
layer_disable(l);
|
||||
debug_printf("sticky %d up\n", l);
|
||||
debug_printf("sticky %d up and done\n", l);
|
||||
} else {
|
||||
layer_sticky[l] = true;
|
||||
sticky_on = true;
|
||||
|
@ -409,6 +404,29 @@ void kbfun_layer_sticky() {
|
|||
}
|
||||
}
|
||||
|
||||
// sticky modifier key
|
||||
void kbfun_modifier_sticky() {
|
||||
// TODO handle: sticky, then same modifier
|
||||
// TODO split sticky_on/done layer vs modifier so we can fine-tune it more?
|
||||
keycode mod = current_keycode;
|
||||
|
||||
if (current_is_pressed) {
|
||||
kbfun_modifier_press_release();
|
||||
sticky_done = false;
|
||||
debug_printf("mod %d down\n", mod);
|
||||
} else {
|
||||
if (sticky_done) {
|
||||
kbfun_modifier_press_release();
|
||||
debug_printf("mod %d up and done\n", mod);
|
||||
} else {
|
||||
modifier_sticky |= 1<<mod;
|
||||
sticky_on = true;
|
||||
sticky_done = false;
|
||||
debug_printf("mod %d up, but still on\n", mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// combo keyfuncs
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -5,6 +5,7 @@ void kbfun_alt_press_release();
|
|||
void kbfun_control_press_release();
|
||||
void kbfun_shift_press_release();
|
||||
void _kbfun_combo_press_release(keycode combo_key);
|
||||
void kbfun_modifier_sticky();
|
||||
void kbfun_modifier_press_release();
|
||||
void kbfun_mediakey_press_release();
|
||||
void kbfun_normal_press_release();
|
||||
|
@ -15,9 +16,6 @@ void _kbfun_modifier_press_release(bool press,keycode key);
|
|||
void _kbfun_mediakey_press_release(bool press,keycode key);
|
||||
void _kbfun_normal_press_release(bool press,keycode key);
|
||||
keyfunc kb_keyfunc_release(layer l,u8 row,u8 col);
|
||||
void sticky_disable();
|
||||
bool layer_is_sticky(layer l);
|
||||
bool layer_top_is_sticky();
|
||||
keyfunc kb_keyfunc_press(layer l,u8 row,u8 col);
|
||||
void layer_enable_upto(layer max_layer);
|
||||
void kbfun_layer_disable();
|
||||
|
@ -30,6 +28,7 @@ void layer_disable_top();
|
|||
void layer_disable(layer l);
|
||||
void layer_enable(layer l);
|
||||
layer highest_active_layer(layer offset);
|
||||
void sticky_disable();
|
||||
void exec_key();
|
||||
keycode kb_keycode(layer l,u8 row,u8 col);
|
||||
void main_key_loop();
|
||||
|
|
Loading…
Reference in New Issue