Merge remote-tracking branch 'upstream/master' into firmware23

This commit is contained in:
Drashna Jael're
2023-09-05 14:08:28 -07:00
590 changed files with 12349 additions and 4945 deletions

View File

@@ -1,5 +1,6 @@
#include "audio.h"
#include "process_audio.h"
#include <math.h>
#ifndef VOICE_CHANGE_SONG
# define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
@@ -12,7 +13,7 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG;
float compute_freq_for_midi_note(uint8_t note) {
// https://en.wikipedia.org/wiki/MIDI_tuning_standard
return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A;
return powf(2.0f, (note - 69) / 12.0f) * PITCH_STANDARD_A;
}
bool process_audio(uint16_t keycode, keyrecord_t *record) {
@@ -61,6 +62,3 @@ void process_audio_noteoff(uint8_t note) {
void process_audio_all_notes_off(void) {
stop_all_notes();
}
__attribute__((weak)) void audio_on_user(void) {}
__attribute__((weak)) void audio_off_user(void) {}

View File

@@ -1,11 +1,12 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
float compute_freq_for_midi_note(uint8_t note);
bool process_audio(uint16_t keycode, keyrecord_t *record);
void process_audio_noteon(uint8_t note);
void process_audio_noteoff(uint8_t note);
void process_audio_all_notes_off(void);
void audio_on_user(void);
void audio_off_user(void);

View File

@@ -14,27 +14,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef AUTO_SHIFT_ENABLE
#include "process_auto_shift.h"
#include "quantum.h"
#include "action_util.h"
#include "timer.h"
#include "keycodes.h"
# include <stdbool.h>
# include "process_auto_shift.h"
# ifndef AUTO_SHIFT_DISABLED_AT_STARTUP
# define AUTO_SHIFT_STARTUP_STATE true /* enabled */
# else
# define AUTO_SHIFT_STARTUP_STATE false /* disabled */
# endif
#ifndef AUTO_SHIFT_DISABLED_AT_STARTUP
# define AUTO_SHIFT_STARTUP_STATE true /* enabled */
#else
# define AUTO_SHIFT_STARTUP_STATE false /* disabled */
#endif
// Stores the last Auto Shift key's up or down time, for evaluation or keyrepeat.
static uint16_t autoshift_time = 0;
# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
// Stores the last key's up or down time, to replace autoshift_time so that Tap Hold times are accurate.
static uint16_t retroshift_time = 0;
// Stores a possibly Retro Shift key's up or down time, as retroshift_time needs
// to be set before the Retro Shift key is evaluated if it is interrupted by an
// Auto Shifted key.
static uint16_t last_retroshift_time;
# endif
#endif
static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
static uint16_t autoshift_lastkey = KC_NO;
static keyrecord_t autoshift_lastrecord;
@@ -68,15 +69,23 @@ __attribute__((weak)) bool get_custom_auto_shifted_key(uint16_t keycode, keyreco
/** \brief Called on physical press, returns whether is Auto Shift key */
__attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
# ifndef NO_AUTO_SHIFT_ALPHA
#ifndef NO_AUTO_SHIFT_ALPHA
case AUTO_SHIFT_ALPHA:
# endif
# ifndef NO_AUTO_SHIFT_NUMERIC
#endif
#ifndef NO_AUTO_SHIFT_NUMERIC
case AUTO_SHIFT_NUMERIC:
#endif
#ifndef NO_AUTO_SHIFT_SPECIAL
# ifndef NO_AUTO_SHIFT_TAB
case KC_TAB:
# endif
# ifndef NO_AUTO_SHIFT_SPECIAL
case AUTO_SHIFT_SPECIAL:
# ifndef NO_AUTO_SHIFT_SYMBOLS
case AUTO_SHIFT_SYMBOLS:
# endif
#endif
#ifdef AUTO_SHIFT_ENTER
case KC_ENT:
#endif
return true;
}
return get_custom_auto_shifted_key(keycode, record);
@@ -123,9 +132,9 @@ bool get_autoshift_shift_state(uint16_t keycode) {
/** \brief Restores the shift key if it was cancelled by Auto Shift */
static void autoshift_flush_shift(void) {
autoshift_flags.holding_shift = false;
# ifdef CAPS_WORD_ENABLE
#ifdef CAPS_WORD_ENABLE
if (!is_caps_word_on())
# endif // CAPS_WORD_ENABLE
#endif // CAPS_WORD_ENABLE
{
del_weak_mods(MOD_BIT(KC_LSFT));
}
@@ -147,26 +156,26 @@ static void autoshift_flush_shift(void) {
static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) {
// clang-format off
if ((get_mods()
# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
| get_oneshot_mods()
# endif
#endif
) & (~MOD_BIT(KC_LSFT))
) {
// clang-format on
// Prevents keyrepeating unshifted value of key after using it in a key combo.
autoshift_lastkey = KC_NO;
# ifndef AUTO_SHIFT_MODIFIERS
#ifndef AUTO_SHIFT_MODIFIERS
// We can't return true here anymore because custom unshifted values are
// possible and there's no good way to tell whether the press returned
// true upon release.
set_autoshift_shift_state(keycode, false);
autoshift_press_user(keycode, false, record);
# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
set_oneshot_mods(get_oneshot_mods() & (~MOD_BIT(KC_LSFT)));
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
# endif
return false;
# endif
return false;
#endif
}
// Store record to be sent to user functions if there's no release record then.
@@ -174,19 +183,19 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record)
autoshift_lastrecord.event.pressed = false;
autoshift_lastrecord.event.time = 0;
// clang-format off
# if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)
#if defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)
if (keycode == autoshift_lastkey &&
# ifdef AUTO_SHIFT_REPEAT_PER_KEY
# ifdef AUTO_SHIFT_REPEAT_PER_KEY
get_auto_shift_repeat(autoshift_lastkey, record) &&
# endif
# if !defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY)
# endif
# if !defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY)
(
!autoshift_flags.lastshifted
# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY
# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY
|| get_auto_shift_no_auto_repeat(autoshift_lastkey, record)
# endif
) &&
# endif
) &&
# endif
TIMER_DIFF_16(now, autoshift_time) < GET_TAPPING_TERM(autoshift_lastkey, record)
) {
// clang-format on
@@ -203,23 +212,23 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record)
autoshift_press_user(autoshift_lastkey, autoshift_flags.lastshifted, record);
return false;
}
# endif
#endif
// Use physical shift state of press event to be more like normal typing.
# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
autoshift_flags.lastshifted = (get_mods() | get_oneshot_mods()) & MOD_BIT(KC_LSFT);
set_oneshot_mods(get_oneshot_mods() & (~MOD_BIT(KC_LSFT)));
# else
#else
autoshift_flags.lastshifted = get_mods() & MOD_BIT(KC_LSFT);
# endif
#endif
// Record the keycode so we can simulate it later.
autoshift_lastkey = keycode;
autoshift_time = now;
autoshift_flags.in_progress = true;
# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
# endif
#endif
return false;
}
@@ -240,11 +249,11 @@ static void autoshift_end(uint16_t keycode, uint16_t now, bool matrix_trigger, k
autoshift_flags.lastshifted =
autoshift_flags.lastshifted
|| TIMER_DIFF_16(now, autoshift_time) >=
# ifdef AUTO_SHIFT_TIMEOUT_PER_KEY
#ifdef AUTO_SHIFT_TIMEOUT_PER_KEY
get_autoshift_timeout(autoshift_lastkey, record)
# else
#else
autoshift_timeout
# endif
#endif
;
// clang-format on
set_autoshift_shift_state(autoshift_lastkey, autoshift_flags.lastshifted);
@@ -259,23 +268,23 @@ static void autoshift_end(uint16_t keycode, uint16_t now, bool matrix_trigger, k
autoshift_press_user(autoshift_lastkey, autoshift_flags.lastshifted, record);
// clang-format off
# if (defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)) && (!defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY))
#if (defined(AUTO_SHIFT_REPEAT) || defined(AUTO_SHIFT_REPEAT_PER_KEY)) && (!defined(AUTO_SHIFT_NO_AUTO_REPEAT) || defined(AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY))
if (matrix_trigger
# ifdef AUTO_SHIFT_REPEAT_PER_KEY
# ifdef AUTO_SHIFT_REPEAT_PER_KEY
&& get_auto_shift_repeat(autoshift_lastkey, record)
# endif
# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY
# endif
# ifdef AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY
&& !get_auto_shift_no_auto_repeat(autoshift_lastkey, record)
# endif
# endif
) {
// Prevents release.
return;
}
# endif
#endif
// clang-format on
# if TAP_CODE_DELAY > 0
#if TAP_CODE_DELAY > 0
wait_ms(TAP_CODE_DELAY);
# endif
#endif
autoshift_release_user(autoshift_lastkey, autoshift_flags.lastshifted, record);
autoshift_flush_shift();
@@ -303,11 +312,11 @@ void autoshift_matrix_scan(void) {
if (autoshift_flags.in_progress) {
const uint16_t now = timer_read();
if (TIMER_DIFF_16(now, autoshift_time) >=
# ifdef AUTO_SHIFT_TIMEOUT_PER_KEY
#ifdef AUTO_SHIFT_TIMEOUT_PER_KEY
get_autoshift_timeout(autoshift_lastkey, &autoshift_lastrecord)
# else
#else
autoshift_timeout
# endif
#endif
) {
autoshift_end(autoshift_lastkey, now, true, &autoshift_lastrecord);
}
@@ -328,18 +337,18 @@ void autoshift_disable(void) {
autoshift_flush_shift();
}
# ifndef AUTO_SHIFT_NO_SETUP
#ifndef AUTO_SHIFT_NO_SETUP
void autoshift_timer_report(void) {
# ifdef SEND_STRING_ENABLE
# ifdef SEND_STRING_ENABLE
const char *autoshift_timeout_str = get_u16_str(autoshift_timeout, ' ');
// Skip padding spaces
while (*autoshift_timeout_str == ' ') {
autoshift_timeout_str++;
}
send_string(autoshift_timeout_str);
# endif
}
# endif
}
#endif
bool get_autoshift_state(void) {
return autoshift_flags.enabled;
@@ -361,11 +370,11 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
// https://github.com/qmk/qmk_firmware/pull/9826#issuecomment-733559550
// clang-format off
const uint16_t now =
# if !defined(RETRO_SHIFT) || defined(NO_ACTION_TAPPING)
#if !defined(RETRO_SHIFT) || defined(NO_ACTION_TAPPING)
timer_read()
# else
#else
(record->event.pressed) ? retroshift_time : timer_read()
# endif
#endif
;
// clang-format on
@@ -386,7 +395,7 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
autoshift_disable();
break;
# ifndef AUTO_SHIFT_NO_SETUP
#ifndef AUTO_SHIFT_NO_SETUP
case AS_UP:
autoshift_timeout += 5;
break;
@@ -396,29 +405,27 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
case AS_RPT:
autoshift_timer_report();
break;
# endif
#endif
}
// 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)
#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
# 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)
# else
const bool is_hold_on_interrupt = false;
# else
const bool is_hold_on_interrupt = IS_QK_MOD_TAP(keycode);
# endif
# endif
# endif
#endif
if (IS_RETRO(keycode)
# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
// Not tapped or #defines mean that rolls should use hold action.
&& (
record->tap.count == 0
# ifdef RETRO_TAPPING_PER_KEY
# ifdef RETRO_TAPPING_PER_KEY
|| !get_retro_tapping(keycode, record)
# endif
|| (record->tap.interrupted && is_hold_on_interrupt))
# endif
|| (record->tap.interrupted && is_hold_on_interrupt))
#endif
) {
// clang-format on
autoshift_lastkey = KC_NO;
@@ -434,25 +441,21 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
// tap.count gets set to 0 in process_action
// clang-format off
else if (IS_RETRO(keycode)
# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
&& (
record->tap.count == 0
# ifdef RETRO_TAPPING_PER_KEY
# ifdef RETRO_TAPPING_PER_KEY
|| !get_retro_tapping(keycode, record)
# endif
)
# endif
)
#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
#endif
// clang-format on
return true;
}
@@ -478,7 +481,7 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
return true;
}
# if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
#if defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
// Called to record time before possible delays by action_tapping_process.
void retroshift_poll_time(keyevent_t *event) {
last_retroshift_time = retroshift_time;
@@ -492,6 +495,4 @@ void retroshift_swap_times(void) {
last_retroshift_time = temp;
}
}
# endif
#endif

View File

@@ -16,7 +16,11 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
#include "keyboard.h"
#include "keycodes.h"
#ifndef AUTO_SHIFT_TIMEOUT
# define AUTO_SHIFT_TIMEOUT 175
@@ -28,6 +32,10 @@
// clang-format off
#define AUTO_SHIFT_ALPHA KC_A ... KC_Z
#define AUTO_SHIFT_NUMERIC KC_1 ... KC_0
#define AUTO_SHIFT_SYMBOLS \
KC_MINUS ... KC_SLASH: \
case KC_NONUS_BACKSLASH
#ifdef NO_AUTO_SHIFT_TAB
#define AUTO_SHIFT_SPECIAL \
KC_MINUS ... KC_SLASH: \

View File

@@ -1,11 +1,16 @@
// Copyright 2021 Google LLC
// Copyright 2021 @filterpaper
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// SPDX-License-Identifier: Apache-2.0
// Original source: https://getreuer.info/posts/keyboards/autocorrection
#include "process_autocorrect.h"
#include <string.h>
#include "keycodes.h"
#include "quantum_keycodes.h"
#include "keycode_config.h"
#include "send_string.h"
#include "action_util.h"
#if __has_include("autocorrect_data.h")
# include "autocorrect_data.h"
@@ -57,7 +62,7 @@ void autocorrect_toggle(void) {
}
/**
* @brief handler for determining if autocorrect should process keypress
* @brief handler for user to override whether autocorrect should process this keypress
*
* @param keycode Keycode registered by matrix press, per keymap
* @param record keyrecord_t structure
@@ -67,6 +72,23 @@ void autocorrect_toggle(void) {
* @return false Stop processing and escape from autocorrect.
*/
__attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) {
return process_autocorrect_default_handler(keycode, record, typo_buffer_size, mods);
}
/**
* @brief fallback handler for determining if autocorrect should process this keypress
* can be used by user callback to get the basic keycode being "wrapped"
*
* NOTE: These values may have been edited by user callback before getting here
*
* @param keycode Keycode registered by matrix press, per keymap
* @param record keyrecord_t structure
* @param typo_buffer_size passed along to allow resetting of autocorrect buffer
* @param mods allow processing of mod status
* @return true Allow autocorection
* @return false Stop processing and escape from autocorrect.
*/
bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) {
// See quantum_keycodes.h for reference on these matched ranges.
switch (*keycode) {
// Exclude these keycodes from processing.
@@ -157,10 +179,12 @@ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord
*
* @param backspaces number of characters to remove
* @param str pointer to PROGMEM string to replace mistyped seletion with
* @param typo the wrong string that triggered a correction
* @param correct what it would become after the changes
* @return true apply correction
* @return false user handled replacement
*/
__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str) {
__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct) {
return true;
}
@@ -284,11 +308,57 @@ bool process_autocorrect(uint16_t keycode, keyrecord_t *record) {
if (code & 128) { // A typo was found! Apply autocorrect.
const uint8_t backspaces = (code & 63) + !record->event.pressed;
if (apply_autocorrect(backspaces, (char const *)(autocorrect_data + state + 1))) {
const char * changes = (const char *)(autocorrect_data + state + 1);
/* Gather info about the typo'd word
*
* Since buffer may contain several words, delimited by spaces, we
* iterate from the end to find the start and length of the typo
*/
char typo[AUTOCORRECT_MAX_LENGTH + 1] = {0}; // extra char for null terminator
uint8_t typo_len = 0;
uint8_t typo_start = 0;
bool space_last = typo_buffer[typo_buffer_size - 1] == KC_SPC;
for (uint8_t i = typo_buffer_size; i > 0; --i) {
// stop counting after finding space (unless it is the last thing)
if (typo_buffer[i - 1] == KC_SPC && i != typo_buffer_size) {
typo_start = i;
break;
}
++typo_len;
}
// when detecting 'typo:', reduce the length of the string by one
if (space_last) {
--typo_len;
}
// convert buffer of keycodes into a string
for (uint8_t i = 0; i < typo_len; ++i) {
typo[i] = typo_buffer[typo_start + i] - KC_A + 'a';
}
/* Gather the corrected word
*
* A) Correction of 'typo:' -- Code takes into account
* an extra backspace to delete the space (which we dont copy)
* for this reason the offset is correct to "skip" the null terminator
*
* B) When correcting 'typo' -- Need extra offset for terminator
*/
char correct[AUTOCORRECT_MAX_LENGTH + 10] = {0}; // let's hope this is big enough
uint8_t offset = space_last ? backspaces : backspaces + 1;
strcpy(correct, typo);
strcpy_P(correct + typo_len - offset, changes);
if (apply_autocorrect(backspaces, changes, typo, correct)) {
for (uint8_t i = 0; i < backspaces; ++i) {
tap_code(KC_BSPC);
}
send_string_P((char const *)(autocorrect_data + state + 1));
send_string_P(changes);
}
if (keycode == KC_SPC) {

View File

@@ -1,15 +1,19 @@
// Copyright 2021 Google LLC
// Copyright 2021 @filterpaper
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// SPDX-License-Identifier: Apache-2.0
// Original source: https://getreuer.info/posts/keyboards/autocorrection
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_autocorrect(uint16_t keycode, keyrecord_t *record);
bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods);
bool apply_autocorrect(uint8_t backspaces, const char *str);
bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods);
bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct);
bool autocorrect_is_enabled(void);
void autocorrect_enable(void);

View File

@@ -16,6 +16,8 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_backlight(uint16_t keycode, keyrecord_t *record);

View File

@@ -13,6 +13,62 @@
// limitations under the License.
#include "process_caps_word.h"
#include "process_auto_shift.h"
#include "caps_word.h"
#include "keycodes.h"
#include "quantum_keycodes.h"
#include "modifiers.h"
#include "timer.h"
#include "action_tapping.h"
#include "action_util.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) {
@@ -21,6 +77,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 +156,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 +173,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 +188,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 +230,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,8 +14,9 @@
#pragma once
#include "quantum.h"
#include "caps_word.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
/**
* @brief Process handler for Caps Word feature.

View File

@@ -1,5 +1,7 @@
#include "audio.h"
#include "process_clicky.h"
#include "audio.h"
#include "eeconfig.h"
#include <stdlib.h>
#ifdef AUDIO_CLICKY

View File

@@ -1,5 +1,9 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
void clicky_play(void);
bool process_clicky(uint16_t keycode, keyrecord_t *record);

View File

@@ -14,18 +14,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "print.h"
#include "process_combo.h"
#include <stddef.h>
#include "process_auto_shift.h"
#include "caps_word.h"
#include "timer.h"
#include "wait.h"
#include "keyboard.h"
#include "keymap_common.h"
#include "action_layer.h"
#include "action_tapping.h"
#include "action.h"
#ifdef COMBO_COUNT
__attribute__((weak)) combo_t key_combos[COMBO_COUNT];
uint16_t COMBO_LEN = COMBO_COUNT;
#else
extern combo_t key_combos[];
extern uint16_t COMBO_LEN;
#endif
#include "action_util.h"
#include "keymap_introspection.h"
__attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {}
@@ -144,7 +144,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
@@ -194,8 +194,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);
}
@@ -232,7 +232,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
@@ -286,7 +286,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) {
@@ -332,8 +332,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);
@@ -342,7 +343,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);
@@ -352,7 +353,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)) {
@@ -457,7 +458,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);
@@ -563,8 +564,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

@@ -16,9 +16,11 @@
#pragma once
#include "progmem.h"
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
#include "keycodes.h"
#include "quantum_keycodes.h"
#ifdef EXTRA_SHORT_COMBOS
# define MAX_COMBO_LENGTH 6
@@ -37,7 +39,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

@@ -17,6 +17,15 @@
/* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */
#include "process_dynamic_macro.h"
#include <stddef.h>
#include "action_layer.h"
#include "keycodes.h"
#include "debug.h"
#include "wait.h"
#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
#endif
// default feedback method
void dynamic_macro_led_blink(void) {
@@ -29,7 +38,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 +71,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();
@@ -151,6 +160,67 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin
*macro_end = macro_pointer;
}
/* Both macros use the same buffer but read/write on different
* ends of it.
*
* Macro1 is written left-to-right starting from the beginning of
* the buffer.
*
* Macro2 is written right-to-left starting from the end of the
* buffer.
*
* &macro_buffer macro_end
* v v
* +------------------------------------------------------------+
* |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<|
* +------------------------------------------------------------+
* ^ ^
* r_macro_end r_macro_buffer
*
* During the recording when one macro encounters the end of the
* other macro, the recording is stopped. Apart from this, there
* are no arbitrary limits for the macros' length in relation to
* each other: for example one can either have two medium sized
* macros or one long macro and one short macro. Or even one empty
* and one using the whole buffer.
*/
static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE];
/* Pointer to the first buffer element after the first macro.
* Initially points to the very beginning of the buffer since the
* macro is empty. */
static keyrecord_t *macro_end = macro_buffer;
/* The other end of the macro buffer. Serves as the beginning of
* the second macro. */
static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1;
/* Like macro_end but for the second macro. */
static keyrecord_t *r_macro_end = macro_buffer + DYNAMIC_MACRO_SIZE - 1;
/* A persistent pointer to the current macro position (iterator)
* used during the recording. */
static keyrecord_t *macro_pointer = NULL;
/* 0 - no macro is being recorded right now
* 1,2 - either macro 1 or 2 is being recorded */
static uint8_t macro_id = 0;
/**
* If a dynamic macro is currently being recorded, stop recording.
*/
void dynamic_macro_stop_recording(void) {
switch (macro_id) {
case 1:
dynamic_macro_record_end(macro_buffer, macro_pointer, +1, &macro_end);
break;
case 2:
dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end);
break;
}
macro_id = 0;
}
/* Handle the key events related to the dynamic macros. Should be
* called from process_record_user() like this:
*
@@ -162,62 +232,16 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin
* }
*/
bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
/* Both macros use the same buffer but read/write on different
* ends of it.
*
* Macro1 is written left-to-right starting from the beginning of
* the buffer.
*
* Macro2 is written right-to-left starting from the end of the
* buffer.
*
* &macro_buffer macro_end
* v v
* +------------------------------------------------------------+
* |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<|
* +------------------------------------------------------------+
* ^ ^
* r_macro_end r_macro_buffer
*
* During the recording when one macro encounters the end of the
* other macro, the recording is stopped. Apart from this, there
* are no arbitrary limits for the macros' length in relation to
* each other: for example one can either have two medium sized
* macros or one long macro and one short macro. Or even one empty
* and one using the whole buffer.
*/
static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE];
/* Pointer to the first buffer element after the first macro.
* Initially points to the very beginning of the buffer since the
* macro is empty. */
static keyrecord_t *macro_end = macro_buffer;
/* The other end of the macro buffer. Serves as the beginning of
* the second macro. */
static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1;
/* Like macro_end but for the second macro. */
static keyrecord_t *r_macro_end = r_macro_buffer;
/* A persistent pointer to the current macro position (iterator)
* used during the recording. */
static keyrecord_t *macro_pointer = NULL;
/* 0 - no macro is being recorded right now
* 1,2 - either macro 1 or 2 is being recorded */
static uint8_t macro_id = 0;
if (macro_id == 0) {
/* No macro recording in progress. */
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:
@@ -238,15 +262,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release
* just after the recording
* starts for DM_RSTP. */
switch (macro_id) {
case 1:
dynamic_macro_record_end(macro_buffer, macro_pointer, +1, &macro_end);
break;
case 2:
dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end);
break;
}
macro_id = 0;
dynamic_macro_stop_recording();
}
return false;
#ifdef DYNAMIC_MACRO_NO_NESTING

View File

@@ -18,7 +18,9 @@
/* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
/* May be overridden with a custom value. Be aware that the effective
* macro length is half of this value: each keypress is recorded twice
@@ -35,7 +37,8 @@
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);
void dynamic_macro_stop_recording(void);

View File

@@ -14,8 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quantum.h"
#include "process_dynamic_tapping_term.h"
#include "quantum.h"
#include "keycodes.h"
#include "send_string.h"
#ifndef DYNAMIC_TAPPING_TERM_INCREMENT
# define DYNAMIC_TAPPING_TERM_INCREMENT 5

View File

@@ -16,6 +16,7 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "action.h"

View File

@@ -14,6 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "process_grave_esc.h"
#include "keycodes.h"
#include "modifiers.h"
#include "action_util.h"
/* true if the last press of QK_GRAVE_ESCAPE was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
* Used to ensure that the correct keycode is released if the key is released.

View File

@@ -15,6 +15,8 @@
*/
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_grave_esc(uint16_t keycode, keyrecord_t *record);

View File

@@ -15,6 +15,7 @@
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "action.h"

View File

@@ -17,6 +17,7 @@
#pragma once
#include <stdint.h>
#include "quantum.h"
#include <stdbool.h>
#include "action.h"
bool process_joystick(uint16_t keycode, keyrecord_t *record);

View File

@@ -16,7 +16,9 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
void cancel_key_lock(void);
bool process_key_lock(uint16_t *keycode, keyrecord_t *record);

View File

@@ -15,12 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quantum.h"
#include "process_key_override.h"
#include "report.h"
#include "timer.h"
#include "process_key_override.h"
#include <debug.h>
#include "debug.h"
#include "wait.h"
#include "action_util.h"
#include "quantum.h"
#include "quantum_keycodes.h"
#ifndef KEY_OVERRIDE_REPEAT_DELAY
# define KEY_OVERRIDE_REPEAT_DELAY 500
@@ -322,6 +324,15 @@ static bool try_activating_override(const uint16_t keycode, const uint8_t layer,
clear_active_override(false);
#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
// Send a dummy keycode before unregistering the modifier(s)
// so that suppressing the modifier(s) doesn't falsely get interpreted
// by the host OS as a tap of a modifier key.
// For example, unintended activations of the start menu on Windows when
// using a GUI+<kc> key override with suppressed mods.
neutralize_flashing_modifiers(active_mods);
#endif
active_override = override;
active_override_trigger_is_down = true;

View File

@@ -18,9 +18,8 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "action.h"
#include "action_layer.h"
/**

View File

@@ -16,6 +16,7 @@
#include "process_leader.h"
#include "leader.h"
#include "quantum_keycodes.h"
bool process_leader(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {

View File

@@ -16,6 +16,8 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_leader(uint16_t keycode, keyrecord_t *record);

View File

@@ -14,8 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "process_magic.h"
#include "keycode_config.h"
#include "keycodes.h"
#include "eeconfig.h"
#ifdef AUDIO_ENABLE
# include "audio.h"
# ifndef AG_NORM_SONG
# define AG_NORM_SONG SONG(AG_NORM_SOUND)
# endif

View File

@@ -15,6 +15,8 @@
*/
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_magic(uint16_t keycode, keyrecord_t *record);

View File

@@ -15,12 +15,13 @@
*/
#include "process_midi.h"
#ifdef MIDI_ENABLE
# include <LUFA/Drivers/USB/USB.h>
# include "midi.h"
# include "qmk_midi.h"
#include <LUFA/Drivers/USB/USB.h>
#include "midi.h"
#include "qmk_midi.h"
#include "timer.h"
#include "debug.h"
# ifdef MIDI_BASIC
#ifdef MIDI_BASIC
void process_midi_basic_noteon(uint8_t note) {
midi_send_noteon(&midi_device, 0, note, 127);
@@ -34,12 +35,9 @@ void process_midi_all_notes_off(void) {
midi_send_cc(&midi_device, 0, 0x7B, 0);
}
# endif // MIDI_BASIC
# ifdef MIDI_ADVANCED
# include "timer.h"
#endif // MIDI_BASIC
#ifdef MIDI_ADVANCED
static uint8_t tone_status[2][MIDI_TONE_COUNT];
static uint8_t midi_modulation;
@@ -248,11 +246,11 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) {
return true;
}
# endif // MIDI_ADVANCED
#endif // MIDI_ADVANCED
void midi_task(void) {
midi_device_process(&midi_device);
# ifdef MIDI_ADVANCED
#ifdef MIDI_ADVANCED
if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) return;
midi_modulation_timer = timer_read();
@@ -270,7 +268,5 @@ void midi_task(void) {
if (midi_modulation > 127) midi_modulation = 127;
}
# endif
#endif
}
#endif // MIDI_ENABLE

View File

@@ -16,7 +16,10 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
#include "quantum_keycodes.h"
#ifdef MIDI_ENABLE

View File

@@ -14,8 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "process_music.h"
#include "timer.h"
#ifdef AUDIO_ENABLE
# include "audio.h"
# include "process_audio.h"
#endif
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)

View File

@@ -16,7 +16,9 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include <stdint.h>
#include "quantum.h"
#include <stdbool.h>
#include "action.h"
bool process_programmable_button(uint16_t keycode, keyrecord_t *record);

View File

@@ -0,0 +1,113 @@
// 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"
#include "repeat_key.h"
#include "keycodes.h"
#include "quantum_keycodes.h"
#include "action_util.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,64 @@
// 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 <stdint.h>
#include <stdbool.h>
#include "action.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

@@ -14,6 +14,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "process_rgb.h"
#include "action_util.h"
#ifdef RGB_MATRIX_ENABLE
# include "rgb_matrix.h"
#endif
#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif
typedef void (*rgb_func_pointer)(void);

View File

@@ -15,6 +15,8 @@
*/
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_rgb(const uint16_t keycode, const keyrecord_t *record);

View File

@@ -3,6 +3,7 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "action.h"

View File

@@ -16,6 +16,8 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
bool process_sequencer(uint16_t keycode, keyrecord_t *record);

View File

@@ -13,8 +13,13 @@
* 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 "process_space_cadet.h"
#include "keycodes.h"
#include "timer.h"
#include "action.h"
#include "action_tapping.h"
#include "action_util.h"
// ********** OBSOLETE DEFINES, STOP USING! (pls?) **********
// Shift / paren setup

View File

@@ -15,7 +15,9 @@
*/
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdMod, uint8_t tapMod, uint8_t keycode);
bool process_space_cadet(uint16_t keycode, keyrecord_t *record);

View File

@@ -15,6 +15,7 @@
*/
#include "process_steno.h"
#include "quantum_keycodes.h"
#include "eeconfig.h"
#include "keymap_steno.h"
#include <string.h>
#ifdef VIRTSER_ENABLE
@@ -173,13 +174,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 +194,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

View File

@@ -16,7 +16,9 @@
#pragma once
#include "quantum.h"
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
#define BOLT_STROKE_SIZE 4
#define GEMINI_STROKE_SIZE 6

View File

@@ -13,7 +13,14 @@
* 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 "process_tap_dance.h"
#include "quantum.h"
#include "action_layer.h"
#include "action_tapping.h"
#include "action_util.h"
#include "timer.h"
#include "wait.h"
static uint16_t active_td;
static uint16_t last_tap_time;
@@ -88,6 +95,10 @@ static inline void process_tap_dance_action_on_each_tap(tap_dance_action_t *acti
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap);
}
static inline void process_tap_dance_action_on_each_release(tap_dance_action_t *action) {
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_release);
}
static inline void process_tap_dance_action_on_reset(tap_dance_action_t *action) {
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_reset);
del_weak_mods(action->state.weak_mods);
@@ -151,8 +162,12 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
process_tap_dance_action_on_each_tap(action);
active_td = action->state.finished ? 0 : keycode;
} else {
process_tap_dance_action_on_each_release(action);
if (action->state.finished) {
process_tap_dance_action_on_reset(action);
if (active_td == keycode) {
active_td = 0;
}
}
}

View File

@@ -16,18 +16,17 @@
#pragma once
#ifdef TAP_DANCE_ENABLE
# include <stdbool.h>
# include <inttypes.h>
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
typedef struct {
uint16_t interrupting_keycode;
uint8_t count;
uint8_t weak_mods;
# ifndef NO_ACTION_ONESHOT
#ifndef NO_ACTION_ONESHOT
uint8_t oneshot_mods;
# endif
#endif
bool pressed : 1;
bool finished : 1;
bool interrupted : 1;
@@ -41,6 +40,7 @@ typedef struct {
tap_dance_user_fn_t on_each_tap;
tap_dance_user_fn_t on_dance_finished;
tap_dance_user_fn_t on_reset;
tap_dance_user_fn_t on_each_release;
} fn;
void *user_data;
} tap_dance_action_t;
@@ -56,24 +56,27 @@ typedef struct {
void (*layer_function)(uint8_t);
} tap_dance_dual_role_t;
# define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \
{ .fn = {tap_dance_pair_on_each_tap, tap_dance_pair_finished, tap_dance_pair_reset}, .user_data = (void *)&((tap_dance_pair_t){kc1, kc2}), }
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) \
{ .fn = {tap_dance_pair_on_each_tap, tap_dance_pair_finished, tap_dance_pair_reset, NULL}, .user_data = (void *)&((tap_dance_pair_t){kc1, kc2}), }
# define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) \
{ .fn = {tap_dance_dual_role_on_each_tap, tap_dance_dual_role_finished, tap_dance_dual_role_reset}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_move}), }
#define ACTION_TAP_DANCE_LAYER_MOVE(kc, layer) \
{ .fn = {tap_dance_dual_role_on_each_tap, tap_dance_dual_role_finished, tap_dance_dual_role_reset, NULL}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_move}), }
# define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \
{ .fn = {NULL, tap_dance_dual_role_finished, tap_dance_dual_role_reset}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_invert}), }
#define ACTION_TAP_DANCE_LAYER_TOGGLE(kc, layer) \
{ .fn = {NULL, tap_dance_dual_role_finished, tap_dance_dual_role_reset, NULL}, .user_data = (void *)&((tap_dance_dual_role_t){kc, layer, layer_invert}), }
# define ACTION_TAP_DANCE_FN(user_fn) \
{ .fn = {NULL, user_fn, NULL}, .user_data = NULL, }
#define ACTION_TAP_DANCE_FN(user_fn) \
{ .fn = {NULL, user_fn, NULL, NULL}, .user_data = NULL, }
# define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \
{ .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset}, .user_data = NULL, }
#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset) \
{ .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, NULL}, .user_data = NULL, }
# define TD(n) (QK_TAP_DANCE | TD_INDEX(n))
# define TD_INDEX(code) ((code)&0xFF)
# define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions)
#define ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(user_fn_on_each_tap, user_fn_on_each_release, user_fn_on_dance_finished, user_fn_on_dance_reset) \
{ .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, user_fn_on_each_release}, .user_data = NULL, }
#define TD(n) (QK_TAP_DANCE | TD_INDEX(n))
#define TD_INDEX(code) ((code)&0xFF)
#define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions)
extern tap_dance_action_t tap_dance_actions[];
@@ -92,9 +95,3 @@ void tap_dance_pair_reset(tap_dance_state_t *state, void *user_data);
void tap_dance_dual_role_on_each_tap(tap_dance_state_t *state, void *user_data);
void tap_dance_dual_role_finished(tap_dance_state_t *state, void *user_data);
void tap_dance_dual_role_reset(tap_dance_state_t *state, void *user_data);
#else
# define TD(n) KC_NO
#endif

View File

@@ -3,6 +3,8 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "action.h"
/**

View File

@@ -15,110 +15,30 @@
*/
#include "process_ucis.h"
#include "unicode.h"
#include "keycode.h"
#include "wait.h"
ucis_state_t ucis_state;
void ucis_start(void) {
ucis_state.count = 0;
ucis_state.in_progress = true;
ucis_start_user();
}
__attribute__((weak)) void ucis_start_user(void) {
register_unicode(0x2328); // ⌨
}
__attribute__((weak)) void ucis_success(uint8_t symbol_index) {}
static bool is_uni_seq(char *seq) {
uint8_t i;
for (i = 0; seq[i]; i++) {
uint16_t keycode;
if ('1' <= seq[i] && seq[i] <= '0') {
keycode = seq[i] - '1' + KC_1;
} else {
keycode = seq[i] - 'a' + KC_A;
}
if (i > ucis_state.count || ucis_state.codes[i] != keycode) {
return false;
}
}
return ucis_state.codes[i] == KC_ENTER || ucis_state.codes[i] == KC_SPACE;
}
__attribute__((weak)) void ucis_symbol_fallback(void) {
for (uint8_t i = 0; i < ucis_state.count - 1; i++) {
tap_code(ucis_state.codes[i]);
}
}
__attribute__((weak)) void ucis_cancel(void) {}
void register_ucis(const uint32_t *code_points) {
for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) {
register_unicode(code_points[i]);
}
}
#include "ucis.h"
#include "keycodes.h"
bool process_ucis(uint16_t keycode, keyrecord_t *record) {
if (!ucis_state.in_progress || !record->event.pressed) {
return true;
}
bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE;
if (ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) {
return false;
}
ucis_state.codes[ucis_state.count] = keycode;
ucis_state.count++;
switch (keycode) {
case KC_BACKSPACE:
if (ucis_state.count >= 2) {
ucis_state.count -= 2;
return true;
} else {
ucis_state.count--;
return false;
}
case KC_SPACE:
case KC_ENTER:
case KC_ESCAPE:
for (uint8_t i = 0; i < ucis_state.count; i++) {
tap_code(KC_BACKSPACE);
}
if (keycode == KC_ESCAPE) {
ucis_state.in_progress = false;
ucis_cancel();
return false;
}
uint8_t i;
bool symbol_found = false;
for (i = 0; ucis_symbol_table[i].symbol; i++) {
if (is_uni_seq(ucis_symbol_table[i].symbol)) {
symbol_found = true;
register_ucis(ucis_symbol_table[i].code_points);
break;
}
}
if (symbol_found) {
ucis_success(i);
} else {
ucis_symbol_fallback();
}
ucis_state.in_progress = false;
if (ucis_active() && record->event.pressed) {
bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE;
if (ucis_count() >= UCIS_MAX_INPUT_LENGTH && !special) {
return false;
}
default:
return true;
if (!ucis_add(keycode)) {
switch (keycode) {
case KC_BACKSPACE:
return ucis_remove_last();
case KC_ESCAPE:
ucis_cancel();
return false;
case KC_SPACE:
case KC_ENTER:
ucis_finish();
return false;
}
}
}
return true;
}

View File

@@ -18,48 +18,6 @@
#include <stdbool.h>
#include <stdint.h>
#include "action.h"
#ifndef UCIS_MAX_SYMBOL_LENGTH
# define UCIS_MAX_SYMBOL_LENGTH 32
#endif
#ifndef UCIS_MAX_CODE_POINTS
# define UCIS_MAX_CODE_POINTS 3
#endif
typedef struct {
char * symbol;
uint32_t code_points[UCIS_MAX_CODE_POINTS];
} ucis_symbol_t;
typedef struct {
uint8_t count;
uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
bool in_progress : 1;
} ucis_state_t;
extern ucis_state_t ucis_state;
// clang-format off
#define UCIS_TABLE(...) \
{ \
__VA_ARGS__, \
{ NULL, {} } \
}
#define UCIS_SYM(name, ...) \
{ name, {__VA_ARGS__} }
// clang-format on
extern const ucis_symbol_t ucis_symbol_table[];
void ucis_start(void);
void ucis_start_user(void);
void ucis_symbol_fallback(void);
void ucis_success(uint8_t symbol_index);
void register_ucis(const uint32_t *code_points);
bool process_ucis(uint16_t keycode, keyrecord_t *record);

View File

@@ -16,6 +16,7 @@
#include "process_unicode.h"
#include "unicode.h"
#include "keycodes.h"
#include "quantum_keycodes.h"
bool process_unicode(uint16_t keycode, keyrecord_t *record) {

View File

@@ -18,7 +18,6 @@
#include <stdbool.h>
#include <stdint.h>
#include "action.h"
bool process_unicode(uint16_t keycode, keyrecord_t *record);

View File

@@ -17,7 +17,8 @@
#include "process_unicode_common.h"
#include "unicode.h"
#include "action_util.h"
#include "keycode.h"
#include "keycodes.h"
#include "modifiers.h"
#if defined(UNICODE_ENABLE)
# include "process_unicode.h"
@@ -32,10 +33,18 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
bool shifted = get_mods() & MOD_MASK_SHIFT;
switch (keycode) {
case QK_UNICODE_MODE_NEXT:
cycle_unicode_input_mode(shifted ? -1 : +1);
if (shifted) {
unicode_input_mode_step_reverse();
} else {
unicode_input_mode_step();
}
break;
case QK_UNICODE_MODE_PREVIOUS:
cycle_unicode_input_mode(shifted ? +1 : -1);
if (shifted) {
unicode_input_mode_step();
} else {
unicode_input_mode_step_reverse();
}
break;
case QK_UNICODE_MODE_MACOS:
set_unicode_input_mode(UNICODE_MODE_MACOS);

View File

@@ -18,7 +18,6 @@
#include <stdbool.h>
#include <stdint.h>
#include "action.h"
bool process_unicode_common(uint16_t keycode, keyrecord_t *record);

View File

@@ -15,41 +15,12 @@
*/
#include "process_unicodemap.h"
#include "unicode.h"
#include "quantum_keycodes.h"
#include "keycode.h"
#include "action_util.h"
#include "host.h"
__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
if (keycode >= QK_UNICODEMAP_PAIR) {
// Keycode is a pair: extract index based on Shift / Caps Lock state
uint16_t index;
uint8_t mods = get_mods() | get_weak_mods();
#ifndef NO_ACTION_ONESHOT
mods |= get_oneshot_mods();
#endif
bool shift = mods & MOD_MASK_SHIFT;
bool caps = host_keyboard_led_state().caps_lock;
if (shift ^ caps) {
index = QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(keycode);
} else {
index = QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(keycode);
}
return index;
} else {
// Keycode is a regular index
return QK_UNICODEMAP_GET_INDEX(keycode);
}
}
#include "unicodemap.h"
#include "keycodes.h"
bool process_unicodemap(uint16_t keycode, keyrecord_t *record) {
if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) {
uint32_t code_point = pgm_read_dword(unicode_map + unicodemap_index(keycode));
register_unicode(code_point);
register_unicodemap(unicodemap_index(keycode));
}
return true;
}

View File

@@ -18,11 +18,6 @@
#include <stdbool.h>
#include <stdint.h>
#include "action.h"
#include "progmem.h"
extern const uint32_t unicode_map[] PROGMEM;
uint16_t unicodemap_index(uint16_t keycode);
bool process_unicodemap(uint16_t keycode, keyrecord_t *record);
bool process_unicodemap(uint16_t keycode, keyrecord_t *record);