Merge remote-tracking branch 'qmk/master' into merge-2023-06-03

This commit is contained in:
Ilya Zhuravlev
2023-06-03 12:35:25 -06:00
14389 changed files with 536595 additions and 476101 deletions

View File

@ -402,12 +402,10 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
// If Retro Shift is disabled, possible custom actions shouldn't happen.
// clang-format off
# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
# if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY)
# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
const bool is_hold_on_interrupt = get_hold_on_other_key_press(keycode, record);
# elif defined(IGNORE_MOD_TAP_INTERRUPT)
const bool is_hold_on_interrupt = false;
# else
const bool is_hold_on_interrupt = IS_QK_MOD_TAP(keycode);
const bool is_hold_on_interrupt = false;
# endif
# endif
if (IS_RETRO(keycode)
@ -445,12 +443,8 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
# endif
) {
// Fixes modifiers not being applied to rolls with AUTO_SHIFT_MODIFIERS set.
# if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY)
if (autoshift_flags.in_progress
# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
&& get_hold_on_other_key_press(keycode, record)
# endif
) {
# ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
if (autoshift_flags.in_progress && get_hold_on_other_key_press(keycode, record)) {
autoshift_end(KC_NO, now, false, &autoshift_lastrecord);
}
# endif

View File

@ -14,6 +14,54 @@
#include "process_caps_word.h"
#ifdef CAPS_WORD_INVERT_ON_SHIFT
static uint8_t held_mods = 0;
static bool handle_shift(uint16_t keycode, keyrecord_t* record) {
switch (keycode) {
case OSM(MOD_LSFT):
keycode = KC_LSFT;
break;
case OSM(MOD_RSFT):
keycode = KC_RSFT;
break;
# ifndef NO_ACTION_TAPPING
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
if (record->tap.count == 0) { // Mod-tap key is held.
switch (QK_MOD_TAP_GET_MODS(keycode)) {
case MOD_LSFT:
keycode = KC_LSFT;
break;
case MOD_RSFT:
keycode = KC_RSFT;
break;
}
}
# endif // NO_ACTION_TAPPING
}
if (keycode == KC_LSFT || keycode == KC_RSFT) {
const uint8_t mod = MOD_BIT(keycode);
if (is_caps_word_on()) {
if (record->event.pressed) {
held_mods |= mod;
} else {
held_mods &= ~mod;
}
return false;
} else if ((held_mods & mod) != 0) {
held_mods &= ~mod;
del_mods(mod);
return record->event.pressed;
}
}
return true;
}
#endif // CAPS_WORD_INVERT_ON_SHIFT
bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
if (keycode == QK_CAPS_WORD_TOGGLE) {
if (record->event.pressed) {
@ -21,6 +69,11 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
}
return false;
}
#ifdef CAPS_WORD_INVERT_ON_SHIFT
if (!handle_shift(keycode, record)) {
return false;
}
#endif // CAPS_WORD_INVERT_ON_SHIFT
#ifndef NO_ACTION_ONESHOT
const uint8_t mods = get_mods() | get_oneshot_mods();
@ -95,6 +148,7 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
case QK_TRI_LAYER_LOWER ... QK_TRI_LAYER_UPPER:
// Ignore AltGr.
case KC_RALT:
case OSM(MOD_RALT):
@ -111,12 +165,14 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
if (record->tap.count == 0) { // Mod-tap key is held.
const uint8_t mods = QK_MOD_TAP_GET_MODS(keycode);
switch (mods) {
# ifndef CAPS_WORD_INVERT_ON_SHIFT
case MOD_LSFT:
keycode = KC_LSFT;
break;
case MOD_RSFT:
keycode = KC_RSFT;
break;
# endif // CAPS_WORD_INVERT_ON_SHIFT
case MOD_RSFT | MOD_RALT:
keycode = RSFT(KC_RALT);
break;
@ -124,6 +180,9 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
return true;
default:
caps_word_off();
# ifdef CAPS_WORD_INVERT_ON_SHIFT
add_mods(held_mods);
# endif // CAPS_WORD_INVERT_ON_SHIFT
return true;
}
} else {
@ -163,12 +222,20 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
clear_weak_mods();
#endif // AUTO_SHIFT_ENABLE
if (caps_word_press_user(keycode)) {
#ifdef CAPS_WORD_INVERT_ON_SHIFT
if (held_mods) {
set_weak_mods(get_weak_mods() ^ MOD_BIT(KC_LSFT));
}
#endif // CAPS_WORD_INVERT_ON_SHIFT
send_keyboard_report();
return true;
}
}
caps_word_off();
#ifdef CAPS_WORD_INVERT_ON_SHIFT
add_mods(held_mods);
#endif // CAPS_WORD_INVERT_ON_SHIFT
return true;
}

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "keymap_common.h"
#include "print.h"
#include "process_combo.h"
#include "action_tapping.h"
@ -24,14 +25,18 @@
/* dynamic combos are stored entirely in ram */
#undef pgm_read_word
#define pgm_read_word(address_short) *((uint16_t*)(address_short))
#endif
#ifdef COMBO_COUNT
__attribute__((weak)) combo_t key_combos[COMBO_COUNT];
uint16_t COMBO_LEN = COMBO_COUNT;
uint16_t combo_count(void) {
return VIAL_COMBO_ENTRIES;
}
extern combo_t key_combos[];
combo_t* combo_get(uint16_t combo_idx) {
return &key_combos[combo_idx];
}
#else
extern combo_t key_combos[];
extern uint16_t COMBO_LEN;
#include "keymap_introspection.h"
#endif
__attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {}
@ -151,7 +156,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
static inline void release_combo(uint16_t combo_index, combo_t *combo) {
if (combo->keycode) {
keyrecord_t record = {
.event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false),
.event = MAKE_COMBOEVENT(false),
.keycode = combo->keycode,
};
#ifndef NO_ACTION_TAPPING
@ -201,8 +206,8 @@ static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) {
void clear_combos(void) {
uint16_t index = 0;
longest_term = 0;
for (index = 0; index < COMBO_LEN; ++index) {
combo_t *combo = &key_combos[index];
for (index = 0; index < combo_count(); ++index) {
combo_t *combo = combo_get(index);
if (!COMBO_ACTIVE(combo)) {
RESET_COMBO_STATE(combo);
}
@ -239,7 +244,7 @@ static inline void dump_key_buffer(void) {
process_record(record);
#endif
}
record->event.time = 0;
record->event.type = TICK_EVENT;
#if defined(CAPS_WORD_ENABLE) && defined(AUTO_SHIFT_ENABLE)
// Edge case: preserve the weak Left Shift mod if both Caps Word and
@ -293,7 +298,7 @@ void drop_combo_from_buffer(uint16_t combo_index) {
queued_combo_t *qcombo = &combo_buffer[i];
if (qcombo->combo_index == combo_index) {
combo_t *combo = &key_combos[combo_index];
combo_t *combo = combo_get(combo_index);
DISABLE_COMBO(combo);
if (i == combo_buffer_read) {
@ -339,8 +344,9 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
KEY_STATE_DOWN(state, key_index);
if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) {
// this in the end executes the combo when the key_buffer is dumped.
record->keycode = combo->keycode;
record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO);
record->keycode = combo->keycode;
record->event.type = COMBO_EVENT;
record->event.key = MAKE_KEYPOS(0, 0);
qrecord->combo_index = combo_index;
ACTIVATE_COMBO(combo);
@ -349,7 +355,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
} else {
// key was part of the combo but not the last one, "disable" it
// by making it a TICK event.
record->event.time = 0;
record->event.type = TICK_EVENT;
}
}
drop_combo_from_buffer(combo_index);
@ -359,7 +365,7 @@ static inline void apply_combos(void) {
// Apply all buffered normal combos.
for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) {
queued_combo_t *buffered_combo = &combo_buffer[i];
combo_t * combo = &key_combos[buffered_combo->combo_index];
combo_t * combo = combo_get(buffered_combo->combo_index);
#ifdef COMBO_MUST_TAP_PER_COMBO
if (get_combo_must_tap(buffered_combo->combo_index, combo)) {
@ -464,7 +470,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
combo_t *drop = NULL;
for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) {
queued_combo_t *qcombo = &combo_buffer[combo_buffer_i];
combo_t * buffered_combo = &key_combos[qcombo->combo_index];
combo_t * buffered_combo = combo_get(qcombo->combo_index);
if ((drop = overlaps(buffered_combo, combo))) {
DISABLE_COMBO(drop);
@ -570,8 +576,8 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) {
}
#endif
for (uint16_t idx = 0; idx < COMBO_LEN; ++idx) {
combo_t *combo = &key_combos[idx];
for (uint16_t idx = 0; idx < combo_count(); ++idx) {
combo_t *combo = combo_get(idx);
is_combo_key |= process_single_combo(combo, keycode, record, idx);
no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo));
}

View File

@ -37,7 +37,7 @@
# define COMBO_BUFFER_LENGTH 4
#endif
typedef struct {
typedef struct combo_t {
const uint16_t *keys;
uint16_t keycode;
#ifdef EXTRA_SHORT_COMBOS

View File

@ -29,7 +29,7 @@ void dynamic_macro_led_blink(void) {
/* User hooks for Dynamic Macros */
__attribute__((weak)) void dynamic_macro_record_start_user(void) {
__attribute__((weak)) void dynamic_macro_record_start_user(int8_t direction) {
dynamic_macro_led_blink();
}
@ -62,10 +62,10 @@ __attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrec
* @param[out] macro_pointer The new macro buffer iterator.
* @param[in] macro_buffer The macro buffer used to initialize macro_pointer.
*/
void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer) {
void dynamic_macro_record_start(keyrecord_t **macro_pointer, keyrecord_t *macro_buffer, int8_t direction) {
dprintln("dynamic macro recording: started");
dynamic_macro_record_start_user();
dynamic_macro_record_start_user(direction);
clear_keyboard();
layer_clear();
@ -213,11 +213,11 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
if (!record->event.pressed) {
switch (keycode) {
case QK_DYNAMIC_MACRO_RECORD_START_1:
dynamic_macro_record_start(&macro_pointer, macro_buffer);
dynamic_macro_record_start(&macro_pointer, macro_buffer, +1);
macro_id = 1;
return false;
case QK_DYNAMIC_MACRO_RECORD_START_2:
dynamic_macro_record_start(&macro_pointer, r_macro_buffer);
dynamic_macro_record_start(&macro_pointer, r_macro_buffer, -1);
macro_id = 2;
return false;
case QK_DYNAMIC_MACRO_PLAY_1:

View File

@ -35,7 +35,7 @@
void dynamic_macro_led_blink(void);
bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record);
void dynamic_macro_record_start_user(void);
void dynamic_macro_record_start_user(int8_t direction);
void dynamic_macro_play_user(int8_t direction);
void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record);
void dynamic_macro_record_end_user(int8_t direction);

View File

@ -0,0 +1,109 @@
// 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.
#include "process_repeat_key.h"
// 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 true;
}
static bool remember_last_key(uint16_t keycode, keyrecord_t* record, uint8_t* remembered_mods) {
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
case QK_REPEAT_KEY:
#ifndef NO_ALT_REPEAT_KEY
case QK_ALT_REPEAT_KEY:
#endif // NO_ALT_REPEAT_KEY
return false;
}
return remember_last_key_user(keycode, record, remembered_mods);
}
bool process_last_key(uint16_t keycode, keyrecord_t* record) {
if (get_repeat_key_count()) {
return true;
}
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(keycode, record, &remembered_mods)) {
set_last_record(keycode, record);
set_last_mods(remembered_mods);
}
}
return true;
}
bool process_repeat_key(uint16_t keycode, keyrecord_t* record) {
if (get_repeat_key_count()) {
return true;
}
if (keycode == QK_REPEAT_KEY) {
repeat_key_invoke(&record->event);
return false;
#ifndef NO_ALT_REPEAT_KEY
} else if (keycode == QK_ALT_REPEAT_KEY) {
alt_repeat_key_invoke(&record->event);
return false;
#endif // NO_ALT_REPEAT_KEY
}
return true;
}

View File

@ -0,0 +1,62 @@
// 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"
/**
* @brief Process handler for remembering the last key.
*
* @param keycode Keycode registered by matrix press, per keymap
* @param record keyrecord_t structure
* @return true Continue processing keycodes, and send to host
* @return false Stop processing keycodes, and don't send to host
*/
bool process_last_key(uint16_t keycode, keyrecord_t* record);
/**
* @brief Optional 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
* @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 Process handler for Repeat Key feature.
*
* @param keycode Keycode registered by matrix press, per keymap
* @param record keyrecord_t structure
* @return true Continue processing keycodes, and send to host
* @return false Stop processing keycodes, and don't send to host
*/
bool process_repeat_key(uint16_t keycode, keyrecord_t* record);

View File

@ -173,13 +173,13 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
#ifdef STENO_ENABLE_ALL
case QK_STENO_BOLT:
if (IS_PRESSED(record->event)) {
if (record->event.pressed) {
steno_set_mode(STENO_MODE_BOLT);
}
return false;
case QK_STENO_GEMINI:
if (IS_PRESSED(record->event)) {
if (record->event.pressed) {
steno_set_mode(STENO_MODE_GEMINI);
}
return false;
@ -193,7 +193,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
}
#endif // STENO_COMBINEDMAP
case STN__MIN ... STN__MAX:
if (IS_PRESSED(record->event)) {
if (record->event.pressed) {
n_pressed_keys++;
switch (mode) {
#ifdef STENO_ENABLE_BOLT