diff options
author | Pascal Getreuer <50221757+getreuer@users.noreply.github.com> | 2023-05-20 05:35:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-20 22:35:06 +1000 |
commit | 3993b15f054265071730cdb450f43457dcf4c64a (patch) | |
tree | 61c5b980ed14428bae3c0278c27937dbb5d33627 /quantum/repeat_key.h | |
parent | e1766df185869d8a591228d37f3f7b6d5b4049b4 (diff) |
[Core] Add Repeat Key ("repeat last key") as a core feature. (#19700)
Co-authored-by: casuanoob <96005765+casuanoob@users.noreply.github.com>
Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Diffstat (limited to 'quantum/repeat_key.h')
-rw-r--r-- | quantum/repeat_key.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/quantum/repeat_key.h b/quantum/repeat_key.h new file mode 100644 index 0000000000..06e8364529 --- /dev/null +++ b/quantum/repeat_key.h @@ -0,0 +1,80 @@ +// Copyright 2022-2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "quantum.h" + +uint16_t get_last_keycode(void); /**< Keycode of the last key. */ +uint8_t get_last_mods(void); /**< Mods active with the last key. */ +void set_last_keycode(uint16_t keycode); /**< Sets the last key. */ +void set_last_mods(uint8_t mods); /**< Sets the last mods. */ + +/** @brief Gets the record for the last key. */ +keyrecord_t* get_last_record(void); + +/** @brief Sets keycode and record info for the last key. */ +void set_last_record(uint16_t keycode, keyrecord_t* record); + +/** + * @brief Signed count of times the key has been repeated or alternate repeated. + * + * @note The count is nonzero only while a repeated or alternate-repeated key is + * being processed. + * + * When a key is pressed normally, the count is 0. When the Repeat Key is used + * to repeat a key, the count is 1 on the first repeat, 2 on the second repeat, + * and continuing up to 127. + * + * Negative counts are used similarly for alternate repeating. When the + * Alternate Repeat Key is used, the count is -1 on the first alternate repeat, + * -2 on the second, continuing down to -127. + */ +int8_t get_repeat_key_count(void); + +/** + * @brief Calls `process_record()` on a generated record repeating the last key. + * @param event Event information in the generated record. + */ +void repeat_key_invoke(const keyevent_t* event); + +#ifndef NO_ALT_REPEAT_KEY + +/** + * @brief Keycode to be used for alternate repeating. + * + * Alternate Repeat performs this keycode based on the last eligible pressed key + * and mods, get_last_keycode() and get_last_mods(). For example, when the last + * key was KC_UP, this function returns KC_DOWN. The function returns KC_NO if + * the last key doesn't have a defined alternate. + */ +uint16_t get_alt_repeat_key_keycode(void); + +/** + * @brief Calls `process_record()` to alternate repeat the last key. + * @param event Event information in the generated record. + */ +void alt_repeat_key_invoke(const keyevent_t* event); + +/** + * @brief Optional user callback to define additional alternate keys. + * + * When `get_alt_repeat_key_keycode()` is called, it first calls this callback. + * It should return a keycode representing the "alternate" of the given keycode + * and mods. Returning KC_NO defers to the default definitions in + * `get_alt_repeat_key_keycode()`. + */ +uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods); + +#endif // NO_ALT_REPEAT_KEY |