remove repeat key
This commit is contained in:
parent
3453453c27
commit
35b2480946
|
@ -1 +1,2 @@
|
|||
.DS_Store
|
||||
.vscode
|
|
@ -10,3 +10,7 @@ SUBS(O_OUGH, "ough", NAV_REP, HRM_O)
|
|||
SUBS(G_ING, "ing", NAV_REP, KC_G)
|
||||
SUBS(Q_QU, "qu", NAV_REP, KC_Q)
|
||||
|
||||
// Swedish
|
||||
SUBS(CB_Q, "q", U_AO, KC_W)
|
||||
SUBS(CB_Z, "z", U_AE, KC_X)
|
||||
SUBS(CB_QUOT, "'", U_OE, KC_Y)
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#define FORCE_NKRO
|
||||
|
||||
#define UNICODE_SELECTED_MODES UNICODE_MODE_MACOS
|
||||
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
// The default is 100
|
||||
#define MOUSEKEY_WHEEL_INTERVAL 50
|
||||
|
|
|
@ -1,439 +0,0 @@
|
|||
// 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.
|
||||
|
||||
/**
|
||||
* @file repeat_key.c
|
||||
* @brief Repeat Key implementation
|
||||
*/
|
||||
|
||||
#include "repeat_key.h"
|
||||
|
||||
#pragma message \
|
||||
"Repeat Key is now a core QMK feature! To use it, update your QMK set up and see https://docs.qmk.fm/#/feature_repeat_key"
|
||||
|
||||
// This library makes use of keyrecord_t's `.keycode` field. This field is only
|
||||
// present when Combos are enabled, which we check here. Enable Combos in your
|
||||
// rules.mk by setting:
|
||||
// COMBO_ENABLE = yes
|
||||
#ifndef COMBO_ENABLE
|
||||
#error "repeat_key: Please set `COMBO_ENABLE = yes` in rules.mk."
|
||||
#else
|
||||
|
||||
// Variables saving the state of the last key press.
|
||||
static keyrecord_t last_record = {0};
|
||||
static uint8_t last_mods = 0;
|
||||
// Signed count of the number of times the last key has been repeated or
|
||||
// alternate repeated: it is 0 when a key is pressed normally, positive when
|
||||
// repeated, and negative when alternate repeated.
|
||||
static int8_t last_repeat_count = 0;
|
||||
|
||||
// The repeat_count, but set to 0 outside of repeat_key_invoke() so that it is
|
||||
// nonzero only while a repeated key is being processed.
|
||||
static int8_t processing_repeat_count = 0;
|
||||
|
||||
/** @brief Updates `last_repeat_count` in direction `dir`. */
|
||||
static void update_last_repeat_count(int8_t dir) {
|
||||
if (dir * last_repeat_count < 0) {
|
||||
last_repeat_count = dir;
|
||||
} else if (dir * last_repeat_count < 127) {
|
||||
last_repeat_count += dir;
|
||||
}
|
||||
}
|
||||
|
||||
static void set_last_record(uint16_t keycode, keyrecord_t* record) {
|
||||
last_record = *record;
|
||||
last_record.keycode = keycode;
|
||||
last_repeat_count = 0;
|
||||
}
|
||||
|
||||
static void repeat_key_invoke(const keyevent_t* event) {
|
||||
// It is possible (e.g. in rolled presses) that the last key changes while the
|
||||
// Repeat Key is pressed. To prevent stuck keys, it is important to remember
|
||||
// separately what key record was processed on press so that the the
|
||||
// corresponding record is generated on release.
|
||||
static keyrecord_t registered_record = {0};
|
||||
static int8_t registered_repeat_count = 0;
|
||||
// Since this function calls process_record(), it may recursively call itself.
|
||||
// We return early if `processing_repeat_count` is nonzero to prevent infinite
|
||||
// recursion.
|
||||
if (processing_repeat_count || !last_record.keycode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->pressed) {
|
||||
update_last_repeat_count(1);
|
||||
// On press, apply the last mods state, stacking on top of current mods.
|
||||
register_weak_mods(last_mods);
|
||||
registered_record = last_record;
|
||||
registered_repeat_count = last_repeat_count;
|
||||
}
|
||||
|
||||
// Generate a keyrecord and plumb it into the event pipeline.
|
||||
registered_record.event = *event;
|
||||
processing_repeat_count = registered_repeat_count;
|
||||
process_record(®istered_record);
|
||||
processing_repeat_count = 0;
|
||||
|
||||
// On release, restore the mods state.
|
||||
if (!event->pressed) {
|
||||
unregister_weak_mods(last_mods);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find alternate keycode from a table of opposing keycode pairs.
|
||||
* @param table Array of pairs of basic keycodes, declared as PROGMEM.
|
||||
* @param table_size_bytes The size of the table in bytes.
|
||||
* @param target The basic keycode to find.
|
||||
* @return The alternate basic keycode, or KC_NO if none was found.
|
||||
*
|
||||
* @note The table keycodes and target must be basic keycodes.
|
||||
*
|
||||
* This helper is used several times below to define alternate keys. Given a
|
||||
* table of pairs of basic keycodes, the function finds the pair containing
|
||||
* `target` and returns the other keycode in the pair.
|
||||
*/
|
||||
static uint8_t find_alt_keycode(const uint8_t (*table)[2],
|
||||
uint8_t table_size_bytes, uint8_t target) {
|
||||
const uint8_t* keycodes = (const uint8_t*)table;
|
||||
for (uint8_t i = 0; i < table_size_bytes; ++i) {
|
||||
if (target == pgm_read_byte(keycodes + i)) {
|
||||
// Xor (i ^ 1) the index to get the other element in the pair.
|
||||
return pgm_read_byte(keycodes + (i ^ 1));
|
||||
}
|
||||
}
|
||||
return KC_NO;
|
||||
}
|
||||
|
||||
static void alt_repeat_key_invoke(const keyevent_t* event) {
|
||||
static keyrecord_t registered_record = {0};
|
||||
static int8_t registered_repeat_count = 0;
|
||||
// Since this function calls process_record(), it may recursively call itself.
|
||||
// We return early if `processing_repeat_count` is nonzero to prevent infinite
|
||||
// recursion.
|
||||
if (processing_repeat_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->pressed) {
|
||||
registered_record = (keyrecord_t){
|
||||
#ifndef NO_ACTION_TAPPING
|
||||
.tap.interrupted = false,
|
||||
.tap.count = 0,
|
||||
#endif
|
||||
.keycode = get_alt_repeat_key_keycode(),
|
||||
};
|
||||
}
|
||||
|
||||
// Early return if there is no alternate key defined.
|
||||
if (!registered_record.keycode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->pressed) {
|
||||
update_last_repeat_count(-1);
|
||||
registered_repeat_count = last_repeat_count;
|
||||
}
|
||||
|
||||
// Generate a keyrecord and plumb it into the event pipeline.
|
||||
registered_record.event = *event;
|
||||
processing_repeat_count = registered_repeat_count;
|
||||
process_record(®istered_record);
|
||||
processing_repeat_count = 0;
|
||||
}
|
||||
|
||||
__attribute__((weak)) bool get_repeat_key_eligible(uint16_t keycode,
|
||||
keyrecord_t* record) {
|
||||
switch (keycode) {
|
||||
// Ignore MO, TO, TG, TT, and TL layer switch keys.
|
||||
case QK_MOMENTARY ... QK_MOMENTARY_MAX:
|
||||
case QK_TO ... QK_TO_MAX:
|
||||
case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
|
||||
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
|
||||
// Ignore mod keys.
|
||||
case KC_LCTL ... KC_RGUI:
|
||||
case KC_HYPR:
|
||||
case KC_MEH:
|
||||
#ifndef NO_ACTION_ONESHOT // Ignore one-shot keys.
|
||||
case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
|
||||
case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
|
||||
#endif // NO_ACTION_ONESHOT
|
||||
#ifdef TRI_LAYER_ENABLE // Ignore Tri Layer keys.
|
||||
case QK_TRI_LAYER_LOWER:
|
||||
case QK_TRI_LAYER_UPPER:
|
||||
#endif // TRI_LAYER_ENABLE
|
||||
return false;
|
||||
|
||||
// Ignore hold events on tap-hold keys.
|
||||
#ifndef NO_ACTION_TAPPING
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
#ifndef NO_ACTION_LAYER
|
||||
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
|
||||
#endif // NO_ACTION_LAYER
|
||||
if (record->tap.count == 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
#endif // NO_ACTION_TAPPING
|
||||
|
||||
#ifdef SWAP_HANDS_ENABLE
|
||||
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
|
||||
if (IS_SWAP_HANDS_KEYCODE(keycode) || record->tap.count == 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
#endif // SWAP_HANDS_ENABLE
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool remember_last_key_wrapper(uint16_t keycode, keyrecord_t* record,
|
||||
uint8_t* remembered_mods) {
|
||||
return get_repeat_key_eligible(keycode, record) &&
|
||||
remember_last_key_user(keycode, record, remembered_mods);
|
||||
}
|
||||
|
||||
bool process_repeat_key(uint16_t keycode, keyrecord_t* record,
|
||||
uint16_t repeat_keycode) {
|
||||
if (get_repeat_key_count()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keycode == repeat_keycode) {
|
||||
repeat_key_invoke(&record->event);
|
||||
return false;
|
||||
} else if (record->event.pressed) {
|
||||
uint8_t remembered_mods = get_mods() | get_weak_mods();
|
||||
#ifndef NO_ACTION_ONESHOT
|
||||
remembered_mods |= get_oneshot_mods();
|
||||
#endif // NO_ACTION_ONESHOT
|
||||
|
||||
if (remember_last_key_wrapper(keycode, record, &remembered_mods)) {
|
||||
set_last_record(keycode, record);
|
||||
set_last_mods(remembered_mods);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool process_repeat_key_with_alt(uint16_t keycode, keyrecord_t* record,
|
||||
uint16_t repeat_keycode,
|
||||
uint16_t alt_repeat_keycode) {
|
||||
if (keycode == alt_repeat_keycode) {
|
||||
alt_repeat_key_invoke(&record->event);
|
||||
return false;
|
||||
}
|
||||
|
||||
return process_repeat_key(keycode, record, repeat_keycode);
|
||||
}
|
||||
|
||||
int8_t get_repeat_key_count(void) { return processing_repeat_count; }
|
||||
|
||||
uint16_t get_last_keycode(void) { return last_record.keycode; }
|
||||
|
||||
uint8_t get_last_mods(void) { return last_mods; }
|
||||
|
||||
void set_last_keycode(uint16_t keycode) {
|
||||
set_last_record(keycode, &(keyrecord_t){
|
||||
#ifndef NO_ACTION_TAPPING
|
||||
.tap.interrupted = false,
|
||||
.tap.count = 1,
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
void set_last_mods(uint8_t mods) { last_mods = mods; }
|
||||
|
||||
uint16_t get_alt_repeat_key_keycode(void) {
|
||||
uint16_t keycode = last_record.keycode;
|
||||
uint8_t mods = last_mods;
|
||||
|
||||
// Call the user callback first to give it a chance to override the default
|
||||
// alternate key definitions that follow.
|
||||
uint16_t alt_keycode = get_alt_repeat_key_keycode_user(keycode, mods);
|
||||
|
||||
if (alt_keycode != KC_TRNS) {
|
||||
return alt_keycode;
|
||||
}
|
||||
|
||||
// Convert 8-bit mods to the 5-bit format used in keycodes. This is lossy: if
|
||||
// left and right handed mods were mixed, they all become right handed.
|
||||
mods = ((mods & 0xf0) ? /* set right hand bit */ 0x10 : 0)
|
||||
// Combine right and left hand mods.
|
||||
| (((mods >> 4) | mods) & 0xf);
|
||||
|
||||
switch (keycode) {
|
||||
case QK_MODS ... QK_MODS_MAX: // Unpack modifier + basic key.
|
||||
mods |= QK_MODS_GET_MODS(keycode);
|
||||
keycode = QK_MODS_GET_BASIC_KEYCODE(keycode);
|
||||
break;
|
||||
|
||||
#ifndef NO_ACTION_TAPPING
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
|
||||
break;
|
||||
#ifndef NO_ACTION_LAYER
|
||||
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
|
||||
keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
|
||||
break;
|
||||
#endif // NO_ACTION_LAYER
|
||||
#endif // NO_ACTION_TAPPING
|
||||
|
||||
#ifdef SWAP_HANDS_ENABLE
|
||||
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
|
||||
if (IS_SWAP_HANDS_KEYCODE(keycode)) {
|
||||
return KC_NO;
|
||||
}
|
||||
keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode);
|
||||
break;
|
||||
#endif // SWAP_HANDS_ENABLE
|
||||
}
|
||||
|
||||
if (IS_QK_BASIC(keycode)) {
|
||||
if ((mods & (MOD_LCTL | MOD_LALT | MOD_LGUI))) {
|
||||
// The last key was pressed with a modifier other than Shift. The
|
||||
// following maps
|
||||
// mod + F <-> mod + B
|
||||
// and a few others, supporting several core hotkeys used in Emacs, Vim,
|
||||
// less, and other programs.
|
||||
// clang-format off
|
||||
static const uint8_t pairs[][2] PROGMEM = {
|
||||
{KC_F , KC_B }, // Forward / Backward.
|
||||
{KC_D , KC_U }, // Down / Up.
|
||||
{KC_N , KC_P }, // Next / Previous.
|
||||
{KC_A , KC_E }, // Home / End.
|
||||
{KC_O , KC_I }, // Vim jumplist Older / Newer.
|
||||
};
|
||||
// clang-format on
|
||||
alt_keycode = find_alt_keycode(pairs, sizeof(pairs), keycode);
|
||||
} else {
|
||||
// The last key was pressed with no mods or only Shift. The following map
|
||||
// a few more Vim hotkeys.
|
||||
// clang-format off
|
||||
static const uint8_t pairs[][2] PROGMEM = {
|
||||
{KC_J , KC_K }, // Down / Up.
|
||||
{KC_H , KC_L }, // Left / Right.
|
||||
// These two lines map W and E to B, and B to W.
|
||||
{KC_W , KC_B }, // Forward / Backward by word.
|
||||
{KC_E , KC_B }, // Forward / Backward by word.
|
||||
};
|
||||
// clang-format on
|
||||
alt_keycode = find_alt_keycode(pairs, sizeof(pairs), keycode);
|
||||
}
|
||||
|
||||
if (!alt_keycode) {
|
||||
// The following key pairs are considered with any mods.
|
||||
// clang-format off
|
||||
static const uint8_t pairs[][2] PROGMEM = {
|
||||
{KC_LEFT, KC_RGHT}, // Left / Right Arrow.
|
||||
{KC_UP , KC_DOWN}, // Up / Down Arrow.
|
||||
{KC_HOME, KC_END }, // Home / End.
|
||||
{KC_PGUP, KC_PGDN}, // Page Up / Page Down.
|
||||
{KC_BSPC, KC_DEL }, // Backspace / Delete.
|
||||
{KC_LBRC, KC_RBRC}, // Brackets [ ] and { }.
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
{KC_WBAK, KC_WFWD}, // Browser Back / Forward.
|
||||
{KC_MNXT, KC_MPRV}, // Next / Previous Media Track.
|
||||
{KC_MFFD, KC_MRWD}, // Fast Forward / Rewind Media.
|
||||
{KC_VOLU, KC_VOLD}, // Volume Up / Down.
|
||||
{KC_BRIU, KC_BRID}, // Brightness Up / Down.
|
||||
#endif // EXTRAKEY_ENABLE
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
{KC_MS_L, KC_MS_R}, // Mouse Cursor Left / Right.
|
||||
{KC_MS_U, KC_MS_D}, // Mouse Cursor Up / Down.
|
||||
{KC_WH_L, KC_WH_R}, // Mouse Wheel Left / Right.
|
||||
{KC_WH_U, KC_WH_D}, // Mouse Wheel Up / Down.
|
||||
#endif // MOUSEKEY_ENABLE
|
||||
};
|
||||
// clang-format on
|
||||
alt_keycode = find_alt_keycode(pairs, sizeof(pairs), keycode);
|
||||
}
|
||||
|
||||
if (alt_keycode) {
|
||||
// Combine basic keycode with mods.
|
||||
return (mods << 8) | alt_keycode;
|
||||
}
|
||||
}
|
||||
|
||||
return KC_NO; // No alternate key found.
|
||||
}
|
||||
|
||||
void repeat_key_register(void) {
|
||||
repeat_key_invoke(&MAKE_KEYEVENT(0, 0, true));
|
||||
}
|
||||
|
||||
void repeat_key_unregister(void) {
|
||||
repeat_key_invoke(&MAKE_KEYEVENT(0, 0, false));
|
||||
}
|
||||
|
||||
void repeat_key_tap(void) {
|
||||
repeat_key_register();
|
||||
wait_ms(TAP_CODE_DELAY);
|
||||
repeat_key_unregister();
|
||||
}
|
||||
|
||||
bool alt_repeat_key_register(void) {
|
||||
if (get_alt_repeat_key_keycode()) {
|
||||
alt_repeat_key_invoke(&MAKE_KEYEVENT(0, 0, true));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool alt_repeat_key_unregister(void) {
|
||||
if (get_alt_repeat_key_keycode()) {
|
||||
alt_repeat_key_invoke(&MAKE_KEYEVENT(0, 0, false));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool alt_repeat_key_tap(void) {
|
||||
if (get_alt_repeat_key_keycode()) {
|
||||
alt_repeat_key_register();
|
||||
wait_ms(TAP_CODE_DELAY);
|
||||
alt_repeat_key_unregister();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Default implementation of remember_last_key_user().
|
||||
__attribute__((weak)) bool remember_last_key_user(uint16_t keycode,
|
||||
keyrecord_t* record,
|
||||
uint8_t* remembered_mods) {
|
||||
return get_repeat_key_eligible_user(keycode, record, remembered_mods);
|
||||
}
|
||||
|
||||
// Default implementation of deprecated callback.
|
||||
__attribute__((weak)) bool get_repeat_key_eligible_user(
|
||||
uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Default implementation of get_alt_repeat_key_keycode_user().
|
||||
__attribute__((weak)) uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode,
|
||||
uint8_t mods) {
|
||||
return get_rev_repeat_key_keycode_user(keycode, mods);
|
||||
}
|
||||
|
||||
// Default implementation of deprecated callback.
|
||||
__attribute__((weak)) uint16_t get_rev_repeat_key_keycode_user(uint16_t keycode,
|
||||
uint8_t mods) {
|
||||
return KC_TRNS;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,247 +0,0 @@
|
|||
// 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.
|
||||
|
||||
/**
|
||||
* @file repeat_key.h
|
||||
* @brief Repeat Key - an extensible "repeat last key" implementation.
|
||||
*
|
||||
* @note Repeat Key is now a core QMK feature! See
|
||||
* <https://docs.qmk.fm/#/feature_repeat_key>
|
||||
*
|
||||
* Repeat Key performs the action of last pressed key. Tapping the Repeat Key
|
||||
* after tapping the Z key types another "z." Repeat Key remembers the modifiers
|
||||
* that were active with the last key press. These modifiers are combined with
|
||||
* any additional active modifiers while pressing the Repeat Key. For instance,
|
||||
* if the last press key was Ctrl + Z, then Shift + Repeat Key performs Ctrl +
|
||||
* Shift + Z.
|
||||
*
|
||||
* Also included is an Alternate Repeat Key, performing the "alternate" if there
|
||||
* is one for the last key. By default it is defined for navigation keys to act
|
||||
* in the reverse direction. If Page Down was the last key, the Alternate Repeat
|
||||
* performs Page Up.
|
||||
*
|
||||
* The implementation is a generic event-plumbing strategy that interoperates
|
||||
* predictably with most QMK features, including tap-hold keys, Auto Shift,
|
||||
* Combos, and userspace macros.
|
||||
*
|
||||
* For full documentation, see
|
||||
* <https://getreuer.info/posts/keyboards/repeat-key>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Handler function for Repeat Key. Call either this function or
|
||||
* `process_repeat_key_with_rev()` (but not both) from `process_record_user()`
|
||||
* to implement Repeat Key in your keymap.
|
||||
*
|
||||
* If your `process_record_user()` has other handlers or macros, Repeat Key’s
|
||||
* handler `process_repeat_key()` should preferably be called before anything
|
||||
* else. (If you also use Achordion, then call Achordion's handler first, Repeat
|
||||
* Key's handler second, and then other handlers.)
|
||||
*/
|
||||
bool process_repeat_key(uint16_t keycode, keyrecord_t* record,
|
||||
uint16_t repeat_keycode);
|
||||
|
||||
/** Handler function for Repeat Key and Alternate Repeat Key. */
|
||||
bool process_repeat_key_with_alt(uint16_t keycode, keyrecord_t* record,
|
||||
uint16_t repeat_keycode,
|
||||
uint16_t alt_repeat_keycode);
|
||||
|
||||
/**
|
||||
* @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 Keycode of the last key. */
|
||||
uint16_t get_last_keycode(void);
|
||||
/** @brief Mods that were active with the last key. */
|
||||
uint8_t get_last_mods(void);
|
||||
/** @brief Sets the last keycode. */
|
||||
void set_last_keycode(uint16_t keycode);
|
||||
/** @brief Sets the last mods. */
|
||||
void set_last_mods(uint8_t mods);
|
||||
|
||||
/**
|
||||
* @brief Callback defining which keys are remembered.
|
||||
*
|
||||
* @param keycode Keycode that was just pressed
|
||||
* @param record keyrecord_t structure
|
||||
* @param remembered_mods Mods that will be remembered with this key
|
||||
* @return true Key is remembered (eligible for repeating)
|
||||
* @return false Key is ignored
|
||||
*
|
||||
* Modifier and layer switch keys are always ignored. For all other keys, this
|
||||
* callback is called on every key press. Returning true means that the key is
|
||||
* remembered, false means it is ignored. By default, all non-modifier,
|
||||
* non-layer switch keys are remembered.
|
||||
*
|
||||
* The `remembered_mods` arg represents the mods that will be remembered with
|
||||
* this key. It can be modified to forget certain mods, for instance to forget
|
||||
* capitalization when repeating shifted letters:
|
||||
*
|
||||
* // Forget Shift on letter keys.
|
||||
* if (KC_A <= keycode && keycode <= KC_Z &&
|
||||
* (*remembered_mods & ~MOD_MASK_SHIFT) == 0) {
|
||||
* *remembered_mods = 0;
|
||||
* }
|
||||
*/
|
||||
bool remember_last_key_user(uint16_t keycode, keyrecord_t* record,
|
||||
uint8_t* remembered_mods);
|
||||
|
||||
/**
|
||||
* @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 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()`.
|
||||
*
|
||||
* This callback can be used to define additional pairs of keys that "reverse"
|
||||
* each other. More generally, Alternate Repeat can be configured to perform an
|
||||
* action that "complements" the last key---Alternate Repeat not limited to
|
||||
* reverse repeating, and it need not be symmetric. For instance, you can use it
|
||||
* to eliminate the worst same-finger bigrams in your layout.
|
||||
*/
|
||||
uint16_t get_alt_repeat_key_keycode_user(uint16_t keycode, uint8_t mods);
|
||||
|
||||
/**
|
||||
* Registers (presses down) the Repeat Key. This is useful for invoking Repeat
|
||||
* as part of a tap dance or other custom handler. Note that if doing so, you
|
||||
* likely want to define `repeat_key_press_user()` to ignore the key associated
|
||||
* with that handler so that the Repeat Key does not attempt to repeat itself.
|
||||
*/
|
||||
void repeat_key_register(void);
|
||||
|
||||
/** Unregisters (releases) the Repeat Key. */
|
||||
void repeat_key_unregister(void);
|
||||
|
||||
/** Taps the Repeat Key with a delay of `TAP_CODE_DELAY`. */
|
||||
void repeat_key_tap(void);
|
||||
|
||||
/**
|
||||
* Registers (presses down) the Alternate Repeat Key, performing the alternate,
|
||||
* if there is one, for the last pressed key. If no alternate is found, the
|
||||
* function takes no action and returns false.
|
||||
*
|
||||
* @return True if an alternate key was found.
|
||||
*/
|
||||
bool alt_repeat_key_register(void);
|
||||
|
||||
/**
|
||||
* Unregisters (releases) the Alternate Repeat Key.
|
||||
*
|
||||
* @return True if an alternate key was found.
|
||||
*/
|
||||
bool alt_repeat_key_unregister(void);
|
||||
|
||||
/**
|
||||
* Taps the Alternate Repeat Key with a delay of TAP_CODE_DELAY.
|
||||
*
|
||||
* @return True if an alternate key was found.
|
||||
*/
|
||||
bool alt_repeat_key_tap(void);
|
||||
|
||||
// Deprecated APIs.
|
||||
|
||||
/** @deprecated Use `process_repeat_key_with_alt()` instead. */
|
||||
static inline bool process_repeat_key_with_rev(uint16_t keycode,
|
||||
keyrecord_t* record,
|
||||
uint16_t repeat_keycode,
|
||||
uint16_t rev_repeat_keycode) {
|
||||
return process_repeat_key_with_alt(keycode, record, repeat_keycode,
|
||||
rev_repeat_keycode);
|
||||
}
|
||||
|
||||
/** @deprecated Use `get_repeat_key_count()` instead. */
|
||||
static inline int8_t repeat_key_count(void) { return get_repeat_key_count(); }
|
||||
|
||||
/** @deprecated Use `get_last_keycode()` instead. */
|
||||
static inline uint16_t get_repeat_key_keycode(void) {
|
||||
return get_last_keycode();
|
||||
}
|
||||
/** @deprecated Use `get_last_keycode()` instead. */
|
||||
static inline uint16_t repeat_key_keycode(void) { return get_last_keycode(); }
|
||||
/** @deprecated Use `get_last_mods()` instead. */
|
||||
static inline uint8_t get_repeat_key_mods(void) { return get_last_mods(); }
|
||||
/** @deprecated Use `get_last_mods()` instead. */
|
||||
static inline uint8_t repeat_key_mods(void) { return get_last_mods(); }
|
||||
/** @deprecated Use `set_last_keycode()` instead. */
|
||||
static inline void set_repeat_key_keycode(uint16_t keycode) {
|
||||
set_last_keycode(keycode);
|
||||
}
|
||||
/** @deprecated Use `set_last_mods()` instead. */
|
||||
static inline void set_repeat_key_mods(uint8_t mods) { set_last_mods(mods); }
|
||||
|
||||
/** @deprecated Use `remember_last_key_user()` instead. */
|
||||
bool get_repeat_key_eligible_user(uint16_t keycode, keyrecord_t* record,
|
||||
uint8_t* remembered_mods);
|
||||
/** @deprecated Use `remember_last_key_user()` instead. */
|
||||
bool get_repeat_key_eligible(uint16_t keycode, keyrecord_t* record);
|
||||
|
||||
/** @deprecated Use `get_alt_repeat_key_keycode()` instead. */
|
||||
static inline uint16_t rev_repeat_key_keycode(void) {
|
||||
return get_alt_repeat_key_keycode();
|
||||
}
|
||||
/** @deprecated Use `get_alt_repeat_key_keycode()` instead. */
|
||||
static inline uint16_t get_rev_repeat_key_keycode(void) {
|
||||
return get_alt_repeat_key_keycode();
|
||||
}
|
||||
|
||||
/** @deprecated Use `get_alt_repeat_key_keycode_user()` instead. */
|
||||
uint16_t get_rev_repeat_key_keycode_user(uint16_t keycode, uint8_t mods);
|
||||
|
||||
/** @deprecated Use `alt_repeat_key_register()` instead. */
|
||||
static inline bool rev_repeat_key_register(void) {
|
||||
return alt_repeat_key_register();
|
||||
}
|
||||
|
||||
/** @deprecated Use `alt_repeat_key_unregister()` instead. */
|
||||
static inline bool rev_repeat_key_unregister(void) {
|
||||
return alt_repeat_key_unregister();
|
||||
}
|
||||
|
||||
/** @deprecated Use `alt_repeat_key_tap()` instead. */
|
||||
static inline bool rev_repeat_key_tap(void) { return alt_repeat_key_tap(); }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Binary file not shown.
|
@ -2,10 +2,33 @@
|
|||
#include "action_layer.h"
|
||||
#include "features/achordion.h"
|
||||
#include "features/custom_shift_keys.h"
|
||||
#include "features/repeat_key.h"
|
||||
#include "keycodes.h"
|
||||
#include "quantum.h"
|
||||
|
||||
enum unicode_names {
|
||||
U_AE_LOWER,
|
||||
U_AE_UPPER,
|
||||
U_OE_LOWER,
|
||||
U_OE_UPPER,
|
||||
U_AO_LOWER,
|
||||
U_AO_UPPER,
|
||||
};
|
||||
|
||||
#define U_AE XP(U_AE_LOWER, U_AE_UPPER)
|
||||
#define U_OE XP(U_OE_LOWER, U_OE_UPPER)
|
||||
#define U_AO XP(U_AO_LOWER, U_AO_UPPER)
|
||||
|
||||
// Code lookup tool
|
||||
// https://unicode.emnudge.dev/
|
||||
const uint32_t unicode_map[] PROGMEM = {
|
||||
[U_AE_LOWER] = 0x00e4, // ä
|
||||
[U_AE_UPPER] = 0x00c4, // Ä
|
||||
[U_OE_LOWER] = 0x00f6, // ö
|
||||
[U_OE_UPPER] = 0x00d6, // Ö
|
||||
[U_AO_LOWER] = 0x00e5, // å
|
||||
[U_AO_UPPER] = 0x00c5, // Å
|
||||
};
|
||||
|
||||
enum layers {
|
||||
DEF,
|
||||
SWE,
|
||||
|
@ -21,8 +44,6 @@ enum custom_keycodes {
|
|||
DIRUP = SAFE_RANGE,
|
||||
NEQ,
|
||||
COLNEQ,
|
||||
REPEAT,
|
||||
ALT_REP,
|
||||
};
|
||||
|
||||
// Home row mods
|
||||
|
@ -42,7 +63,7 @@ enum custom_keycodes {
|
|||
#define TMB_TAB LGUI_T(KC_TAB)
|
||||
#define TMB_ENT RGUI_T(KC_ENT)
|
||||
#define TMB_SPC LT(SYM, KC_SPC)
|
||||
#define NAV_REP LT(NAV, REPEAT)
|
||||
#define NAV_REP LT(NAV, KC_BSPC)
|
||||
|
||||
// Nav
|
||||
#define TAB_NXT LCTL(KC_TAB)
|
||||
|
@ -59,16 +80,21 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|||
*/
|
||||
|
||||
[DEF] = LAYOUT(
|
||||
KC_Q, KC_W, KC_F, KC_P, KC_B, KC_J, KC_L, KC_U, KC_Y, KC_QUOT,
|
||||
HRM_A, HRM_R, HRM_S, HRM_T, KC_G, KC_M, HRM_N, HRM_E, HRM_I, HRM_O,
|
||||
KC_Z, KC_X, KC_C, MY_D, KC_V, KC_K, KC_H, KC_COMM, KC_DOT, KC_COLN,
|
||||
NAV_REP, TMB_TAB, TMB_ENT, TMB_SPC
|
||||
KC_Q, KC_W, KC_F, KC_P, KC_B, KC_J, KC_L, KC_U, KC_Y, KC_QUOT,
|
||||
HRM_A, HRM_R, HRM_S, HRM_T, KC_G, KC_M, HRM_N, HRM_E, HRM_I, HRM_O,
|
||||
KC_Z, KC_X, KC_C, MY_D, KC_V, KC_K, KC_H, KC_COMM, KC_DOT, KC_COLN,
|
||||
NAV_REP, TMB_TAB, TMB_ENT, TMB_SPC
|
||||
),
|
||||
|
||||
/*
|
||||
* å w f p b j l u y ö
|
||||
* a r s t g m n e i o
|
||||
* ä x c d v k h , . :
|
||||
*/
|
||||
[SWE] = LAYOUT(
|
||||
U_AO, _______, _______, _______, _______, _______, _______, _______, _______, U_OE,
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
U_AE, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______
|
||||
),
|
||||
|
||||
|
@ -101,14 +127,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|||
_______, _______, _______, _______, _______, _______, KC_7, KC_8, KC_9, _______,
|
||||
_______, _______, _______, _______, _______, _______, KC_1, KC_2, KC_3, KC_DOT,
|
||||
_______, _______, _______, _______, _______, _______, KC_4, KC_5, KC_6, _______,
|
||||
_______, _______, _______, KC_0
|
||||
_______, _______, _______, KC_0
|
||||
),
|
||||
|
||||
[NAV] = LAYOUT(
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
||||
_______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT,
|
||||
_______, _______, _______, _______, _______, TG(SWE), KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT,
|
||||
_______, _______, _______, _______, _______, _______, TAB_PRV, HST_BCK, HST_FWD, TAB_NXT,
|
||||
_______, _______, _______, KC_BSPC
|
||||
_______, _______, _______, _______
|
||||
),
|
||||
|
||||
[MED] = LAYOUT(
|
||||
|
@ -162,12 +188,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|||
return false;
|
||||
if (!process_custom_shift_keys(keycode, record))
|
||||
return false;
|
||||
if (keycode == NAV_REP && !record->tap.count) {
|
||||
return true;
|
||||
}
|
||||
if (!process_repeat_key_with_alt(keycode, record, NAV_REP, ALT_REP)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (keycode) {
|
||||
case DIRUP:
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
SRC += features/achordion.c \
|
||||
features/custom_shift_keys.c \
|
||||
features/repeat_key.c
|
||||
#unicode.c
|
||||
VPATH += keyboards/gboards
|
||||
COMBO_ENABLE = yes
|
||||
CAPS_WORD_ENABLE = yes
|
||||
NKRO_ENABLE = yes
|
||||
UNICODEMAP_ENABLE = yes
|
||||
RGBLIGHT_ENABLE = yes
|
||||
CONVERT_TO=promicro_rp2040
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d52bafade333d2da76c514f2a152b38b3a446c1c
|
||||
Subproject commit ace510ffa0f8d51e1393ae9fcd17da00a5404c37
|
Loading…
Reference in New Issue