minor refactor

master
Stefan Dorn 2016-02-04 11:16:53 +00:00
parent fef0497fcf
commit fc3259de73
2 changed files with 49 additions and 89 deletions

View File

@ -15,7 +15,7 @@
/*
* Generate a normal keypress or keyrelease
*/
void kbfun_press_release(void) {
void kbfun_press_release() {
if (!main_arg_trans_key_pressed) {
main_arg_any_non_trans_key_pressed = true;
}
@ -33,7 +33,7 @@ void kbfun_press_release(void) {
* modifier key (shift, control, alt, gui) on the sticky layer instead of
* defining the key to be transparent for the layer.
*/
void kbfun_press_release_preserve_sticky(void) {
void kbfun_press_release_preserve_sticky() {
uint8_t keycode = _kbfun_get_keycode();
_kbfun_press_release(main_arg_is_pressed, keycode);
}
@ -66,21 +66,18 @@ void kbfun_transparent(void) {
* ------------------------------------------------------------------------- */
// all lower layers on a key should be secretly set/unset to enable proper layer stacking
static void layer_enable_downwards(uint8_t layer) {
static void layers_enable_downwards(uint8_t layer) {
// TODO
main_layers_enable(layer, eStickyNone);
}
static void layer_disable_downwards(uint8_t layer) {
static void layers_disable_downwards(uint8_t layer) {
// TODO
main_layers_disable(layer);
}
// enable given layer
static void layer_enable(uint8_t layer) {
// FIXME necessary?
main_layers_disable(layer);
// Only the topmost layer on the stack should be in sticky once state, pop
// the top layer if it is in sticky once state
uint8_t topSticky = main_layers_top_sticky();
@ -88,12 +85,12 @@ static void layer_enable(uint8_t layer) {
main_layers_disable_top();
}
layer_enable_downwards(layer);
layers_enable_downwards(layer);
}
// disable given layer
static void layer_disable(uint8_t layer) {
layer_disable_downwards(layer);
layers_disable_downwards(layer);
}
/*
@ -128,11 +125,10 @@ static void layer_disable(uint8_t layer) {
* popped if the function is invoked on a subsequent keypress.
*/
static void layer_sticky(uint8_t layer) {
uint8_t topLayer = main_layers_top_layer();
uint8_t topSticky = main_layers_top_sticky();
uint8_t topLayer = main_layers_top_layer();
uint8_t topSticky = main_layers_top_sticky();
if (main_arg_is_pressed) {
main_layers_disable(layer);
if (topLayer == layer) {
if (topSticky == eStickyOnceUp) {
main_layers_enable(layer, eStickyLock);
@ -142,7 +138,8 @@ static void layer_sticky(uint8_t layer) {
if (topSticky == eStickyOnceDown || topSticky == eStickyOnceUp) {
main_layers_disable_top();
}
main_layers_enable(layer, eStickyOnceDown);
layers_enable_downwards(layer);
// this should be the only place we care about this flag being cleared
main_arg_any_non_trans_key_pressed = false;
}

View File

@ -18,108 +18,71 @@
// ----------------------------------------------------------------------------
// convenience macros
#define LAYER main_arg_layer
#define LAYER_OFFSET main_arg_layer_offset
#define ROW main_arg_row
#define COL main_arg_col
#define IS_PRESSED main_arg_is_pressed
#define WAS_PRESSED main_arg_was_pressed
// ----------------------------------------------------------------------------
/*
* [name]
* Shift + press|release
*
* [description]
* Generate a 'shift' press or release before the normal keypress or
* keyrelease
* Generate a 'shift' press or release before the normal keypress or release
*/
void kbfun_shift_press_release(void) {
_kbfun_press_release(IS_PRESSED, KEY_LeftShift);
kbfun_press_release();
_kbfun_press_release(main_arg_is_pressed, KEY_LeftShift);
kbfun_press_release();
}
/*
* [name]
* Control + press|release
*
* [description]
* Generate a 'control' press or release before the normal keypress or
* keyrelease
* Generate a 'control' press or release before the normal keypress or release
*/
void kbfun_control_press_release(void) {
_kbfun_press_release(IS_PRESSED, KEY_LeftControl);
kbfun_press_release();
_kbfun_press_release(main_arg_is_pressed, KEY_LeftControl);
kbfun_press_release();
}
/*
* [name]
* Two keys => capslock
* When assigned to two keys (e.g. the physical left and right shift keys)
* (in both the press and release matrices), pressing and holding down one of
* the keys will make the second key toggle capslock
*
* [description]
* When assigned to two keys (e.g. the physical left and right shift keys)
* (in both the press and release matrices), pressing and holding down one of
* the keys will make the second key toggle capslock
*
* [note]
* If either of the shifts are pressed when the second key is pressed, they
* wil be released so that capslock will register properly when pressed.
* Capslock will then be pressed and released, and the original state of the
* shifts will be restored
* If either of the shifts are pressed when the second key is pressed, they
* wil be released so that capslock will register properly when pressed.
* Capslock will then be pressed and released, and the original state of the
* shifts will be restored
*/
void kbfun_2_keys_capslock_press_release(void) {
static uint8_t keys_pressed;
static bool lshift_pressed;
static bool rshift_pressed;
static uint8_t keys_pressed;
static bool lshift_pressed;
static bool rshift_pressed;
uint8_t keycode = kb_layout_get(LAYER, ROW, COL);
uint8_t keycode = _kbfun_get_keycode();
if (!IS_PRESSED) keys_pressed--;
if (!main_arg_is_pressed) { keys_pressed--; }
// take care of the key that was actually pressed
_kbfun_press_release(IS_PRESSED, keycode);
// take care of the key that was actually pressed
_kbfun_press_release(main_arg_is_pressed, keycode);
// take care of capslock (only on the press of the 2nd key)
if (keys_pressed == 1 && IS_PRESSED) {
// save the state of left and right shift
lshift_pressed = _kbfun_is_pressed(KEY_LeftShift);
rshift_pressed = _kbfun_is_pressed(KEY_RightShift);
// disable both
_kbfun_press_release(false, KEY_LeftShift);
_kbfun_press_release(false, KEY_RightShift);
// take care of capslock (only on the press of the 2nd key)
if (keys_pressed == 1 && main_arg_is_pressed) {
// save the state of left and right shift
lshift_pressed = _kbfun_is_pressed(KEY_LeftShift);
rshift_pressed = _kbfun_is_pressed(KEY_RightShift);
// disable both
_kbfun_press_release(false, KEY_LeftShift);
_kbfun_press_release(false, KEY_RightShift);
// press capslock, then release it
_kbfun_press_release(true, KEY_CapsLock);
usb_keyboard_send();
_kbfun_press_release(false, KEY_CapsLock);
usb_keyboard_send();
// press capslock, then release it
_kbfun_press_release(true, KEY_CapsLock); usb_keyboard_send();
_kbfun_press_release(false, KEY_CapsLock); usb_keyboard_send();
// restore the state of left and right shift
if (lshift_pressed)
_kbfun_press_release(true, KEY_LeftShift);
if (rshift_pressed)
_kbfun_press_release(true, KEY_RightShift);
}
// restore the state of left and right shift
if (lshift_pressed) { _kbfun_press_release(true, KEY_LeftShift); }
if (rshift_pressed) { _kbfun_press_release(true, KEY_RightShift); }
}
if (IS_PRESSED) keys_pressed++;
if (main_arg_is_pressed) { keys_pressed++; }
}
/*
* [name]
* Media Key Press Release
*
* [description]
* Generate a keypress for a media key, such as play/pause, next track, or
* previous track
*
* Generate a keypress for a media key
*/
void kbfun_mediakey_press_release(void) {
uint8_t keycode = kb_layout_get(LAYER, ROW, COL);
_kbfun_mediakey_press_release(IS_PRESSED, keycode);
uint8_t keycode = _kbfun_get_keycode();
_kbfun_mediakey_press_release(main_arg_is_pressed, keycode);
}
/* ----------------------------------------------------------------------------