diff options
author | Drashna Jael're <drashna@live.com> | 2022-10-24 23:28:56 -0700 |
---|---|---|
committer | Drashna Jael're <drashna@live.com> | 2022-10-24 23:28:56 -0700 |
commit | eeb3f9c04346da4f387f1beb439f558a82fcb95c (patch) | |
tree | 7b997f5a62d862dac576bb04eb49a1023ef5af0c | |
parent | e3594135012aa8c8bc309bf43aaa958f3135a30a (diff) | |
parent | f100de88e524633d4f7b35602b37ad6a76044f1d (diff) |
Merge remote-tracking branch 'origin/master' into develop
82 files changed, 3898 insertions, 966 deletions
diff --git a/docs/feature_key_lock.md b/docs/feature_key_lock.md index d5ad1708c7..1acee524da 100644 --- a/docs/feature_key_lock.md +++ b/docs/feature_key_lock.md @@ -16,7 +16,7 @@ First, enable Key Lock by setting `KEY_LOCK_ENABLE = yes` in your `rules.mk`. Th ## Caveats -Key Lock is only able to hold standard action keys and [One Shot modifier](one_shot_keys.md) keys (for example, if you have your Shift defined as `OSM(KC_LSFT)`). +Key Lock is only able to hold standard action keys and [One Shot modifier](one_shot_keys.md) keys (for example, if you have your Shift defined as `OSM(MOD_LSFT)`). This does not include any of the QMK special functions (except One Shot modifiers), or shifted versions of keys such as `KC_LPRN`. If it's in the [Basic Keycodes](keycodes_basic.md) list, it can be held. Switching layers will not cancel the Key Lock. The Key Lock can be cancelled by calling the `cancel_key_lock()` function. diff --git a/docs/ja/feature_key_lock.md b/docs/ja/feature_key_lock.md index b786fbb048..22cd9fb810 100644 --- a/docs/ja/feature_key_lock.md +++ b/docs/ja/feature_key_lock.md @@ -21,7 +21,7 @@ ## 注意事項 -キーロックは、標準アクションキーと[ワンショットモディファイア](ja/one_shot_keys.md)キー (例えば、Shift を `OSM(KC_LSFT)` と定義した場合)のみを押し続けることができます。 +キーロックは、標準アクションキーと[ワンショットモディファイア](ja/one_shot_keys.md)キー (例えば、Shift を `OSM(MOD_LSFT)` と定義した場合)のみを押し続けることができます。 これは、QMK の特殊機能(ワンショットモディファイアを除く)、または `KC_LPRN` のような shift を押されたキーのバージョンは含みません。[基本的なキーコード](ja/keycodes_basic.md)リストにある場合、押したままにすることができます。 レイヤーの切り替えは、キーロックを解除しません。 diff --git a/docs/serial_driver.md b/docs/serial_driver.md index fff63109a1..7fad23911a 100644 --- a/docs/serial_driver.md +++ b/docs/serial_driver.md @@ -1,6 +1,6 @@ # 'serial' Driver -The serial driver powers the [Split Keyboard](feature_split_keyboard.md) feature. Several implementations are available, depending on the platform of your split keyboard. Note that none of the drivers support split keyboards with more then two halves. +The serial driver powers the [Split Keyboard](feature_split_keyboard.md) feature. Several implementations are available, depending on the platform of your split keyboard. Note that none of the drivers support split keyboards with more than two halves. | Driver | AVR | ARM | Connection between halves | | --------------------------------------- | ------------------ | ------------------ | --------------------------------------------------------------------------------------------- | diff --git a/keyboards/a_dux/keymaps/daliusd/config.h b/keyboards/a_dux/keymaps/daliusd/config.h index 42e88a687f..786451768a 100644 --- a/keyboards/a_dux/keymaps/daliusd/config.h +++ b/keyboards/a_dux/keymaps/daliusd/config.h @@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #pragma once -#define UNICODE_SELECTED_MODES UC_MAC, UC_LNX +#define UNICODE_SELECTED_MODES UC_LNX #define MOUSEKEY_INTERVAL 12 #define MOUSEKEY_MAX_SPEED 6 @@ -30,3 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MOUSEKEY_WHEEL_INTERVAL 50 // The default is 40 #define MOUSEKEY_WHEEL_TIME_TO_MAX 100 + +#define FLOW_COUNT 6 +#define FLOW_LAYERS_COUNT 5 diff --git a/keyboards/a_dux/keymaps/daliusd/flow.c b/keyboards/a_dux/keymaps/daliusd/flow.c new file mode 100644 index 0000000000..6e4db873fe --- /dev/null +++ b/keyboards/a_dux/keymaps/daliusd/flow.c @@ -0,0 +1,336 @@ +/* Copyright 2022 @daliusd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "flow.h" + +extern const uint16_t flow_config[FLOW_COUNT][2]; +extern const uint16_t flow_layers_config[FLOW_LAYERS_COUNT][2]; + +// Represents the states a flow key can be in +typedef enum { + flow_up_unqueued, + flow_up_queued, + flow_up_queued_used, + flow_down_unused, + flow_down_used, +} flow_state_t; + +#ifdef FLOW_ONESHOT_TERM +const int g_flow_oneshot_term = FLOW_ONESHOT_TERM; +#else +const int g_flow_oneshot_term = 500; +#endif + +#ifdef FLOW_ONESHOT_WAIT_TERM +const int g_flow_oneshot_wait_term = FLOW_ONESHOT_WAIT_TERM; +#else +const int g_flow_oneshot_wait_term = 500; +#endif + +flow_state_t flow_state[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = flow_up_unqueued }; +bool flow_pressed[FLOW_COUNT][2] = { [0 ... FLOW_COUNT - 1] = {false, false} }; +uint16_t flow_timers[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = 0 }; +bool flow_timeout_timers_active[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = false }; +uint16_t flow_timeout_timers_value[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = 0 }; +uint16_t flow_timeout_wait_timers_value[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = 0 }; + +flow_state_t flow_layers_state[FLOW_LAYERS_COUNT] = { + [0 ... FLOW_LAYERS_COUNT - 1] = flow_up_unqueued +}; +bool flow_layer_timeout_timers_active[FLOW_LAYERS_COUNT] = { [0 ... FLOW_LAYERS_COUNT - 1] = false }; +uint16_t flow_layer_timeout_timers_value[FLOW_LAYERS_COUNT] = { [0 ... FLOW_LAYERS_COUNT - 1] = 0 }; +uint16_t flow_layer_timeout_wait_timers_value[FLOW_LAYERS_COUNT] = { [0 ... FLOW_LAYERS_COUNT - 1] = 0 }; + +bool is_flow_ignored_key(uint16_t keycode) { + for (int i = 0; i < FLOW_COUNT; i++) { + if (flow_config[i][0] == keycode) { + return true; + } + } + + for (int i = 0; i < FLOW_LAYERS_COUNT; i++) { + if (flow_layers_config[i][0] == keycode) { + return true; + } + } + + if (keycode == KC_LSFT || keycode == KC_RSFT + || keycode == KC_LCTL || keycode == KC_RCTL + || keycode == KC_LALT || keycode == KC_RALT + || keycode == KC_LGUI || keycode == KC_RGUI) { + return true; + } + + return false; +} + +bool update_flow_mods( + uint16_t keycode, + bool pressed +) { + bool pass = true; + bool flow_key_list_triggered[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = false }; + bool flow_key_list_pressed[FLOW_COUNT] = { [0 ... FLOW_COUNT - 1] = false }; + + bool flow_triggered = false; + + for (uint8_t i = 0; i < FLOW_COUNT; i++) { + // Layer key + if (keycode == flow_config[i][0]) { + if (pressed) { + flow_pressed[i][0] = true; + } else { + flow_pressed[i][0] = false; + } + // KC mod key + } else if (keycode == flow_config[i][1]) { + if (pressed) { + if (flow_pressed[i][0]) { + flow_pressed[i][1] = true; + flow_key_list_triggered[i] = true; + flow_triggered = true; + flow_key_list_pressed[i] = true; + pass = false; + } + } else if (flow_pressed[i][1]) { + flow_pressed[i][1] = false; + if (flow_pressed[i][0]) { + flow_key_list_triggered[i] = true; + flow_triggered = true; + pass = false; + } else if ((flow_state[i] == flow_down_unused) + || (flow_state[i] == flow_down_used)) { + flow_key_list_triggered[i] = true; + flow_triggered = true; + pass = false; + } + } + } + } + + for (uint8_t i = 0; i < FLOW_COUNT; i++) { + if (flow_key_list_triggered[i]) { + if (flow_key_list_pressed[i]) { + if (flow_state[i] == flow_up_unqueued) { + register_code(flow_config[i][1]); + } + flow_timeout_wait_timers_value[i] = timer_read(); + flow_state[i] = flow_down_unused; + } else { + // Trigger keyup + switch (flow_state[i]) { + case flow_down_unused: + if (!flow_pressed[i][1]) { + if (timer_elapsed(flow_timeout_wait_timers_value[i]) > g_flow_oneshot_wait_term) { + flow_state[i] = flow_up_unqueued; + unregister_code(flow_config[i][1]); + } else { + // If we didn't use the mod while trigger was held, queue it. + flow_state[i] = flow_up_queued; + flow_timeout_timers_active[i] = true; + flow_timeout_timers_value[i] = timer_read(); + } + } + break; + case flow_down_used: + // If we did use the mod while trigger was held, unregister it. + if (!flow_pressed[i][1]) { + flow_state[i] = flow_up_unqueued; + unregister_code(flow_config[i][1]); + } + break; + default: + break; + } + } + } else if (!flow_triggered) { + if (pressed) { + if (!is_flow_ignored_key(keycode)) { + switch (flow_state[i]) { + case flow_up_queued: + flow_state[i] = flow_up_queued_used; + flow_timeout_timers_active[i] = false; + break; + case flow_up_queued_used: + flow_state[i] = flow_up_unqueued; + unregister_code(flow_config[i][1]); + break; + default: + break; + } + } + } else { + if (!is_flow_ignored_key(keycode)) { + // On non-ignored keyup, consider the oneshot used. + switch (flow_state[i]) { + case flow_down_unused: + flow_state[i] = flow_down_used; + break; + case flow_up_queued: + flow_state[i] = flow_up_unqueued; + unregister_code(flow_config[i][1]); + break; + case flow_up_queued_used: + flow_state[i] = flow_up_unqueued; + unregister_code(flow_config[i][1]); + break; + default: + break; + } + } + } + } + } + + return pass; +} + +void change_pressed_status(uint16_t keycode, bool pressed) { + for (int i = 0; i < FLOW_COUNT; i++) { + if (flow_config[i][0] == keycode) { + flow_pressed[i][0] = pressed; + } + } +} + +bool update_flow_layers( + uint16_t keycode, + bool pressed, + keypos_t key_position +) { + uint8_t key_layer = read_source_layers_cache(key_position); + bool pass = true; + + for (int i = 0; i < FLOW_LAYERS_COUNT; i++) { + uint16_t trigger = flow_layers_config[i][0]; + uint16_t layer = flow_layers_config[i][1]; + + if (keycode == trigger) { + if (pressed) { + // Trigger keydown + if (flow_layers_state[i] == flow_up_unqueued) { + layer_on(layer); + change_pressed_status(trigger, true); + } + flow_layer_timeout_wait_timers_value[i] = timer_read(); + flow_layers_state[i] = flow_down_unused; + pass = false; + } else { + // Trigger keyup + switch (flow_layers_state[i]) { + case flow_down_unused: + if (timer_elapsed(flow_layer_timeout_wait_timers_value[i]) > g_flow_oneshot_wait_term) { + flow_layers_state[i] = flow_up_unqueued; + layer_off(layer); + change_pressed_status(trigger, false); + pass = false; + } else { + // If we didn't use the layer while trigger was held, queue it. + flow_layers_state[i] = flow_up_queued; + flow_layer_timeout_timers_active[i] = true; + flow_layer_timeout_timers_value[i] = timer_read(); + pass = false; + change_pressed_status(trigger, true); + } + break; + case flow_down_used: + // If we did use the layer while trigger was held, turn off it. + flow_layers_state[i] = flow_up_unqueued; + layer_off(layer); + change_pressed_status(trigger, false); + pass = false; + break; + default: + break; + } + } + } else { + if (pressed) { + if (key_layer == layer) { + // On non-ignored keyup, consider the oneshot used. + switch (flow_layers_state[i]) { + case flow_down_unused: + flow_layers_state[i] = flow_down_used; + break; + case flow_up_queued: + flow_layers_state[i] = flow_up_queued_used; + flow_layer_timeout_timers_active[i] = false; + break; + case flow_up_queued_used: + flow_layers_state[i] = flow_up_unqueued; + layer_off(layer); + change_pressed_status(trigger, false); + pass = false; + break; + default: + br |