a
This commit is contained in:
parent
6900a49aa1
commit
22f5edcfa9
|
@ -1,23 +1,12 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
// name result chord keys
|
||||||
*
|
COMB(DF_TAB, KC_TAB, KC_D, KC_F)
|
||||||
* This program is free software: you can redistribute it and/or modify
|
COMB(JK_ESC, KC_ESC, KC_J, KC_K)
|
||||||
* it under the terms of the GNU General Public License as published by
|
SUBS(RT_HOME, "~/", KC_R, KC_T)
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
SUBS(YU_UPDIR, "../", KC_Y, KC_U)
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//#include "dictionaries/emerge.def"
|
// name result chord keys
|
||||||
|
SUBS(VI_WRITE, ":w", KC_SCLN, KC_W )
|
||||||
// name result chord keys
|
SUBS(VI_QUIT, ":q", KC_SCLN, KC_Q )
|
||||||
COMB(NE_ESCAPE, KC_ESC, HOME_N, HOME_E)
|
SUBS(VI_WRITE_QUIT, ":wq", KC_SCLN, KC_W, KC_Q)
|
||||||
COMB(SE_CAPSWRD, CW_TOGG, HOME_S, HOME_E)
|
|
||||||
|
|
||||||
/* vim: set filetype=c : */
|
/* vim: set filetype=c : */
|
||||||
|
|
|
@ -1,19 +1,3 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// By default, the firmware does not know which side is which; it needs some help to determine that.
|
// By default, the firmware does not know which side is which; it needs some help to determine that.
|
||||||
|
@ -26,36 +10,40 @@
|
||||||
#define OLED_FONT_H "keyboards/crkbd/lib/glcdfont.c"
|
#define OLED_FONT_H "keyboards/crkbd/lib/glcdfont.c"
|
||||||
|
|
||||||
// Tap-Hold Configuration Options
|
// Tap-Hold Configuration Options
|
||||||
// Configure the global tapping term (default: 200ms)
|
|
||||||
#define TAPPING_TERM 200
|
#define TAPPING_TERM 200
|
||||||
// Activate the modifier when another key is pressed and released while the mod-tap is held.
|
|
||||||
#define PERMISSIVE_HOLD
|
|
||||||
// Makes tap and hold keys (like Layer Tap) work better for fast typists
|
|
||||||
#define HOLD_ON_OTHER_KEY_PRESS
|
|
||||||
// Prevent normal rollover on alphas from accidentally triggering mods.
|
|
||||||
#define IGNORE_MOD_TAP_INTERRUPT
|
|
||||||
// Enable rapid switch from tap to hold, disables double tap hold auto-repeat.
|
|
||||||
#define TAPPING_FORCE_HOLD
|
|
||||||
|
|
||||||
// One Shot Keys
|
// One Shot Keys
|
||||||
#define ONESHOT_TAP_TOGGLE 2
|
#define ONESHOT_TAP_TOGGLE 3
|
||||||
#define ONESHOT_TIMEOUT 2000
|
#define ONESHOT_TIMEOUT 2000
|
||||||
|
|
||||||
// Auto Shift
|
// Auto Shift
|
||||||
#define AUTO_SHIFT_TIMEOUT 175
|
#define AUTO_SHIFT_TIMEOUT 175
|
||||||
#define AUTO_SHIFT_REPEAT
|
|
||||||
#define AUTO_SHIFT_MODIFIERS
|
|
||||||
// Retro Shift
|
|
||||||
#define RETRO_SHIFT 500
|
|
||||||
|
|
||||||
// Caps Word
|
// Caps Word
|
||||||
#define CAPS_WORD_IDLE_TIMEOUT 2000
|
#define CAPS_WORD_IDLE_TIMEOUT 2000
|
||||||
|
|
||||||
// Leader Key
|
// Layer Lock
|
||||||
#define LEADER_TIMEOUT 500
|
#define LAYER_LOCK_IDLE_TIMEOUT 60000
|
||||||
#define LEADER_NO_TIMEOUT
|
|
||||||
#define LEADER_PER_KEY_TIMING
|
|
||||||
|
|
||||||
// Combos
|
// Combos
|
||||||
#define COMBO_TERM 50
|
#define COMBO_TERM 50
|
||||||
|
#define COMBO_ONLY_FROM_LAYER 0
|
||||||
|
|
||||||
|
// RGB
|
||||||
|
#ifdef RGBLIGHT_ENABLE
|
||||||
|
#define RGBLIGHT_SLEEP
|
||||||
|
#define RGBLIGHT_EFFECT_BREATHING
|
||||||
|
#define RGBLIGHT_EFFECT_RAINBOW_MOOD
|
||||||
|
#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
|
||||||
|
#define RGBLIGHT_EFFECT_SNAKE
|
||||||
|
#define RGBLIGHT_EFFECT_KNIGHT
|
||||||
|
#define RGBLIGHT_EFFECT_CHRISTMAS
|
||||||
|
#define RGBLIGHT_EFFECT_STATIC_GRADIENT
|
||||||
|
#define RGBLIGHT_EFFECT_RGB_TEST
|
||||||
|
#define RGBLIGHT_EFFECT_ALTERNATING
|
||||||
|
#define RGBLIGHT_EFFECT_TWINKLE
|
||||||
|
#define RGBLIGHT_LIMIT_VAL 120
|
||||||
|
#define RGBLIGHT_HUE_STEP 10
|
||||||
|
#define RGBLIGHT_SAT_STEP 17
|
||||||
|
#define RGBLIGHT_VAL_STEP 17
|
||||||
|
#endif
|
||||||
|
|
145
keyboards/crkbd/keymaps/sajenim/features/layer_lock.c
Normal file
145
keyboards/crkbd/keymaps/sajenim/features/layer_lock.c
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
// 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 layer_lock.c
|
||||||
|
* @brief Layer Lock implementation
|
||||||
|
*
|
||||||
|
* For full documentation, see
|
||||||
|
* <https://getreuer.info/posts/keyboards/layer-lock>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "layer_lock.h"
|
||||||
|
|
||||||
|
// The current lock state. The kth bit is on if layer k is locked.
|
||||||
|
static layer_state_t locked_layers = 0;
|
||||||
|
|
||||||
|
// Layer Lock timer to disable layer lock after X seconds inactivity
|
||||||
|
#if LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
static uint32_t layer_lock_timer = 0;
|
||||||
|
|
||||||
|
void layer_lock_task(void) {
|
||||||
|
if (locked_layers &&
|
||||||
|
timer_elapsed32(layer_lock_timer) > LAYER_LOCK_IDLE_TIMEOUT) {
|
||||||
|
layer_lock_all_off();
|
||||||
|
layer_lock_timer = timer_read32();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
|
||||||
|
// Handles an event on an `MO` or `TT` layer switch key.
|
||||||
|
static bool handle_mo_or_tt(uint8_t layer, keyrecord_t* record) {
|
||||||
|
if (is_layer_locked(layer)) {
|
||||||
|
if (record->event.pressed) { // On press, unlock the layer.
|
||||||
|
layer_lock_invert(layer);
|
||||||
|
}
|
||||||
|
return false; // Skip default handling.
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_layer_lock(uint16_t keycode, keyrecord_t* record,
|
||||||
|
uint16_t lock_keycode) {
|
||||||
|
#if LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
layer_lock_timer = timer_read32();
|
||||||
|
#endif // LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
|
||||||
|
// The intention is that locked layers remain on. If something outside of
|
||||||
|
// this feature turned any locked layers off, unlock them.
|
||||||
|
if ((locked_layers & ~layer_state) != 0) {
|
||||||
|
layer_lock_set_user(locked_layers &= layer_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keycode == lock_keycode) {
|
||||||
|
if (record->event.pressed) { // The layer lock key was pressed.
|
||||||
|
layer_lock_invert(get_highest_layer(layer_state));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (keycode) {
|
||||||
|
case QK_MOMENTARY ... QK_MOMENTARY_MAX: // `MO(layer)` keys.
|
||||||
|
return handle_mo_or_tt(QK_MOMENTARY_GET_LAYER(keycode), record);
|
||||||
|
|
||||||
|
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: // `TT(layer)`.
|
||||||
|
return handle_mo_or_tt(QK_LAYER_TAP_TOGGLE_GET_LAYER(keycode), record);
|
||||||
|
|
||||||
|
case QK_LAYER_MOD ... QK_LAYER_MOD_MAX: { // `LM(layer, mod)`.
|
||||||
|
uint8_t layer = QK_LAYER_MOD_GET_LAYER(keycode);
|
||||||
|
if (is_layer_locked(layer)) {
|
||||||
|
if (record->event.pressed) { // On press, unlock the layer.
|
||||||
|
layer_lock_invert(layer);
|
||||||
|
} else { // On release, clear the mods.
|
||||||
|
clear_mods();
|
||||||
|
send_keyboard_report();
|
||||||
|
}
|
||||||
|
return false; // Skip default handling.
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
#ifndef NO_ACTION_TAPPING
|
||||||
|
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: // `LT(layer, key)` keys.
|
||||||
|
if (record->tap.count == 0 && !record->event.pressed &&
|
||||||
|
is_layer_locked(QK_LAYER_TAP_GET_LAYER(keycode))) {
|
||||||
|
// Release event on a held layer-tap key where the layer is locked.
|
||||||
|
return false; // Skip default handling so that layer stays on.
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif // NO_ACTION_TAPPING
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_layer_locked(uint8_t layer) {
|
||||||
|
return locked_layers & ((layer_state_t)1 << layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void layer_lock_invert(uint8_t layer) {
|
||||||
|
const layer_state_t mask = (layer_state_t)1 << layer;
|
||||||
|
if ((locked_layers & mask) == 0) { // Layer is being locked.
|
||||||
|
#ifndef NO_ACTION_ONESHOT
|
||||||
|
if (layer == get_oneshot_layer()) {
|
||||||
|
reset_oneshot_layer(); // Reset so that OSL doesn't turn layer off.
|
||||||
|
}
|
||||||
|
#endif // NO_ACTION_ONESHOT
|
||||||
|
layer_on(layer);
|
||||||
|
#if LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
layer_lock_timer = timer_read32();
|
||||||
|
#endif // LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
} else { // Layer is being unlocked.
|
||||||
|
layer_off(layer);
|
||||||
|
}
|
||||||
|
layer_lock_set_user(locked_layers ^= mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement layer_lock_on/off by deferring to layer_lock_invert.
|
||||||
|
void layer_lock_on(uint8_t layer) {
|
||||||
|
if (!is_layer_locked(layer)) {
|
||||||
|
layer_lock_invert(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void layer_lock_off(uint8_t layer) {
|
||||||
|
if (is_layer_locked(layer)) {
|
||||||
|
layer_lock_invert(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void layer_lock_all_off(void) {
|
||||||
|
layer_and(~locked_layers);
|
||||||
|
locked_layers = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak)) void layer_lock_set_user(layer_state_t locked_layers) {}
|
136
keyboards/crkbd/keymaps/sajenim/features/layer_lock.h
Normal file
136
keyboards/crkbd/keymaps/sajenim/features/layer_lock.h
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
// 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 layer_lock.h
|
||||||
|
* @brief Layer Lock, a key to stay in the current layer.
|
||||||
|
*
|
||||||
|
* Overview
|
||||||
|
* --------
|
||||||
|
*
|
||||||
|
* Layers are often accessed by holding a button, e.g. with a momentary layer
|
||||||
|
* switch `MO(layer)` or layer tap `LT(layer, key)` key. But you may sometimes
|
||||||
|
* want to "lock" or "toggle" the layer so that it stays on without having to
|
||||||
|
* hold down a button. One way to do that is with a tap-toggle `TT` layer key,
|
||||||
|
* but here is an alternative.
|
||||||
|
*
|
||||||
|
* This library implements a "Layer Lock key". When tapped, it "locks" the
|
||||||
|
* highest layer to stay active, assuming the layer was activated by one of the
|
||||||
|
* following keys:
|
||||||
|
*
|
||||||
|
* * `MO(layer)` momentary layer switch
|
||||||
|
* * `LT(layer, key)` layer tap
|
||||||
|
* * `OSL(layer)` one-shot layer
|
||||||
|
* * `TT(layer)` layer tap toggle
|
||||||
|
* * `LM(layer, mod)` layer-mod key (the layer is locked, but not the mods)
|
||||||
|
*
|
||||||
|
* Tapping the Layer Lock key again unlocks and turns off the layer.
|
||||||
|
*
|
||||||
|
* @note When a layer is "locked", other layer keys such as `TO(layer)` or
|
||||||
|
* manually calling `layer_off(layer)` will override and unlock the layer.
|
||||||
|
*
|
||||||
|
* Configuration
|
||||||
|
* -------------
|
||||||
|
*
|
||||||
|
* Optionally, a timeout may be defined so that Layer Lock disables
|
||||||
|
* automatically if not keys are pressed for `LAYER_LOCK_IDLE_TIMEOUT`
|
||||||
|
* milliseconds. Define `LAYER_LOCK_IDLE_TIMEOUT` in your config.h, for instance
|
||||||
|
*
|
||||||
|
* #define LAYER_LOCK_IDLE_TIMEOUT 60000 // Turn off after 60 seconds.
|
||||||
|
*
|
||||||
|
* and call `layer_lock_task()` from your `matrix_scan_user()` in keymap.c:
|
||||||
|
*
|
||||||
|
* void matrix_scan_user(void) {
|
||||||
|
* layer_lock_task();
|
||||||
|
* // Other tasks...
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* For full documentation, see
|
||||||
|
* <https://getreuer.info/posts/keyboards/layer-lock>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler function for Layer Lock.
|
||||||
|
*
|
||||||
|
* In your keymap, define a custom keycode to use for Layer Lock. Then handle
|
||||||
|
* Layer Lock from your `process_record_user` function by calling
|
||||||
|
* `process_layer_lock`, passing your custom keycode for the `lock_keycode` arg:
|
||||||
|
*
|
||||||
|
* #include "features/layer_lock.h"
|
||||||
|
*
|
||||||
|
* bool process_record_user(uint16_t keycode, keyrecord_t* record) {
|
||||||
|
* if (!process_layer_lock(keycode, record, LLOCK)) { return false; }
|
||||||
|
* // Your macros ...
|
||||||
|
*
|
||||||
|
* return true;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
bool process_layer_lock(uint16_t keycode, keyrecord_t* record,
|
||||||
|
uint16_t lock_keycode);
|
||||||
|
|
||||||
|
/** Returns true if `layer` is currently locked. */
|
||||||
|
bool is_layer_locked(uint8_t layer);
|
||||||
|
|
||||||
|
/** Locks and turns on `layer`. */
|
||||||
|
void layer_lock_on(uint8_t layer);
|
||||||
|
|
||||||
|
/** Unlocks and turns off `layer`. */
|
||||||
|
void layer_lock_off(uint8_t layer);
|
||||||
|
|
||||||
|
/** Unlocks and turns off all locked layers. */
|
||||||
|
void layer_lock_all_off(void);
|
||||||
|
|
||||||
|
/** Toggles whether `layer` is locked. */
|
||||||
|
void layer_lock_invert(uint8_t layer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional callback that gets called when a layer is locked or unlocked.
|
||||||
|
*
|
||||||
|
* This is useful to represent the current lock state, e.g. by setting an LED or
|
||||||
|
* playing a sound. In your keymap, define
|
||||||
|
*
|
||||||
|
* void layer_lock_set_user(layer_state_t locked_layers) {
|
||||||
|
* // Do something like `set_led(is_layer_locked(NAV));`
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @param locked_layers Bitfield in which the kth bit represents whether the
|
||||||
|
* kth layer is on.
|
||||||
|
*/
|
||||||
|
void layer_lock_set_user(layer_state_t locked_layers);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn layer_lock_task(void)
|
||||||
|
* Matrix task function for Layer Lock.
|
||||||
|
*
|
||||||
|
* If using `LAYER_LOCK_IDLE_TIMEOUT`, call this function from your
|
||||||
|
* `matrix_scan_user()` function in keymap.c. (If no timeout is set, calling
|
||||||
|
* `layer_lock_task()` has no effect.)
|
||||||
|
*/
|
||||||
|
#if LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
void layer_lock_task(void);
|
||||||
|
#else
|
||||||
|
static inline void layer_lock_task(void) {}
|
||||||
|
#endif // LAYER_LOCK_IDLE_TIMEOUT > 0
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
338
keyboards/crkbd/keymaps/sajenim/features/sentence_case.c
Normal file
338
keyboards/crkbd/keymaps/sajenim/features/sentence_case.c
Normal file
|
@ -0,0 +1,338 @@
|
||||||
|
// 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 sentence_case.c
|
||||||
|
* @brief Sentence Case implementation
|
||||||
|
*
|
||||||
|
* For full documentation, see
|
||||||
|
* <https://getreuer.info/posts/keyboards/sentence-case>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sentence_case.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef NO_ACTION_ONESHOT
|
||||||
|
// One-shot keys must be enabled for Sentence Case. One-shot keys are enabled
|
||||||
|
// by default, but are disabled by `#define NO_ACTION_ONESHOT` in config.h. If
|
||||||
|
// your config.h includes such a line, please remove it.
|
||||||
|
#error "Sentence case: Please enable oneshot."
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Number of keys of state history to retain for backspacing.
|
||||||
|
#define STATE_HISTORY_SIZE 6
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
/** States in matching the beginning of a sentence. */
|
||||||
|
enum {
|
||||||
|
STATE_INIT, /**< Initial enabled state. */
|
||||||
|
STATE_WORD, /**< Within a word. */
|
||||||
|
STATE_ABBREV, /**< Within an abbreviation like "e.g.". */
|
||||||
|
STATE_ENDING, /**< Sentence ended. */
|
||||||
|
STATE_PRIMED, /**< "Primed" state, in the space following an ending. */
|
||||||
|
STATE_DISABLED, /**< Sentence Case is disabled. */
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
#if SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
static uint16_t idle_timer = 0;
|
||||||
|
#endif // SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
static uint16_t key_buffer[SENTENCE_CASE_BUFFER_SIZE] = {0};
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
static uint8_t state_history[STATE_HISTORY_SIZE];
|
||||||
|
static uint16_t suppress_key = KC_NO;
|
||||||
|
static uint8_t sentence_state = STATE_INIT;
|
||||||
|
|
||||||
|
// Sets the current state to `new_state`.
|
||||||
|
static void set_sentence_state(uint8_t new_state) {
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
if (debug_enable && sentence_state != new_state) {
|
||||||
|
static const char* state_names[] = {
|
||||||
|
"INIT", "WORD", "ABBREV", "ENDING", "PRIMED", "DISABLED",
|
||||||
|
};
|
||||||
|
dprintf("Sentence case: %s\n", state_names[new_state]);
|
||||||
|
}
|
||||||
|
#endif // NO_DEBUG
|
||||||
|
|
||||||
|
const bool primed = (new_state == STATE_PRIMED);
|
||||||
|
if (primed != (sentence_state == STATE_PRIMED)) {
|
||||||
|
sentence_case_primed(primed);
|
||||||
|
}
|
||||||
|
sentence_state = new_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sentence_case_clear(void) {
|
||||||
|
#if SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
idle_timer = 0;
|
||||||
|
#endif // SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
memset(key_buffer, 0, sizeof(key_buffer));
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
memset(state_history, 0, sizeof(state_history));
|
||||||
|
suppress_key = KC_NO;
|
||||||
|
if (sentence_state != STATE_DISABLED) {
|
||||||
|
set_sentence_state(STATE_INIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sentence_case_on(void) {
|
||||||
|
if (sentence_state == STATE_DISABLED) {
|
||||||
|
sentence_state = STATE_INIT;
|
||||||
|
sentence_case_clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sentence_case_off(void) {
|
||||||
|
if (sentence_state != STATE_DISABLED) {
|
||||||
|
set_sentence_state(STATE_DISABLED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sentence_case_toggle(void) {
|
||||||
|
if (sentence_state != STATE_DISABLED) {
|
||||||
|
sentence_case_off();
|
||||||
|
} else {
|
||||||
|
sentence_case_on();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_sentence_case_on(void) { return sentence_state != STATE_DISABLED; }
|
||||||
|
|
||||||
|
#if SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
#if SENTENCE_CASE_TIMEOUT < 100 || SENTENCE_CASE_TIMEOUT > 30000
|
||||||
|
// Constrain timeout to a sensible range. With the 16-bit timer, the longest
|
||||||
|
// representable timeout is 32768 ms, rounded here to 30000 ms = half a minute.
|
||||||
|
#error "sentence_case: SENTENCE_CASE_TIMEOUT must be between 100 and 30000 ms"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sentence_case_task(void) {
|
||||||
|
if (idle_timer && timer_expired(timer_read(), idle_timer)) {
|
||||||
|
sentence_case_clear(); // Timed out; clear all state.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
|
||||||
|
bool process_sentence_case(uint16_t keycode, keyrecord_t* record) {
|
||||||
|
// Only process while enabled, and only process press events.
|
||||||
|
if (sentence_state == STATE_DISABLED || !record->event.pressed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
idle_timer = (record->event.time + SENTENCE_CASE_TIMEOUT) | 1;
|
||||||
|
#endif // SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
|
||||||
|
switch (keycode) {
|
||||||
|
#ifndef NO_ACTION_TAPPING
|
||||||
|
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||||
|
if (record->tap.count == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
|
||||||
|
break;
|
||||||
|
#ifndef NO_ACTION_LAYER
|
||||||
|
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
|
||||||
|
#endif // NO_ACTION_LAYER
|
||||||
|
if (record->tap.count == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
|
||||||
|
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 true;
|
||||||
|
}
|
||||||
|
keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode);
|
||||||
|
break;
|
||||||
|
#endif // SWAP_HANDS_ENABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keycode == KC_BSPC) {
|
||||||
|
// Backspace key pressed. Rewind the state and key buffers.
|
||||||
|
set_sentence_state(state_history[STATE_HISTORY_SIZE - 1]);
|
||||||
|
|
||||||
|
memmove(state_history + 1, state_history, STATE_HISTORY_SIZE - 1);
|
||||||
|
state_history[0] = STATE_INIT;
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
memmove(key_buffer + 1, key_buffer,
|
||||||
|
(SENTENCE_CASE_BUFFER_SIZE - 1) * sizeof(uint16_t));
|
||||||
|
key_buffer[0] = KC_NO;
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t mods = get_mods() | get_weak_mods() | get_oneshot_mods();
|
||||||
|
uint8_t new_state = STATE_INIT;
|
||||||
|
|
||||||
|
// We search for sentence beginnings using a simple finite state machine. It
|
||||||
|
// matches things like "a. a" and "a. a" but not "a.. a" or "a.a. a". The
|
||||||
|
// state transition matrix is:
|
||||||
|
//
|
||||||
|
// 'a' '.' ' ' '\''
|
||||||
|
// +-------------------------------------
|
||||||
|
// INIT | WORD INIT INIT INIT
|
||||||
|
// WORD | WORD ENDING INIT WORD
|
||||||
|
// ABBREV | ABBREV ABBREV INIT ABBREV
|
||||||
|
// ENDING | ABBREV INIT PRIMED ENDING
|
||||||
|
// PRIMED | match! INIT PRIMED PRIMED
|
||||||
|
char code = sentence_case_press_user(keycode, record, mods);
|
||||||
|
dprintf("Sentence Case: code = '%c' (%d)\n", code, (int)code);
|
||||||
|
switch (code) {
|
||||||
|
case '\0': // Current key should be ignored.
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'a': // Current key is a letter.
|
||||||
|
switch (sentence_state) {
|
||||||
|
case STATE_ABBREV:
|
||||||
|
case STATE_ENDING:
|
||||||
|
new_state = STATE_ABBREV;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_PRIMED:
|
||||||
|
// This is the start of a sentence.
|
||||||
|
if (keycode != suppress_key) {
|
||||||
|
suppress_key = keycode;
|
||||||
|
set_oneshot_mods(MOD_BIT(KC_LSFT)); // Shift mod to capitalize.
|
||||||
|
new_state = STATE_WORD;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
new_state = STATE_WORD;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '.': // Current key is sentence-ending punctuation.
|
||||||
|
switch (sentence_state) {
|
||||||
|
case STATE_WORD:
|
||||||
|
new_state = STATE_ENDING;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
new_state = STATE_ABBREV;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ' ': // Current key is a space.
|
||||||
|
if (sentence_state == STATE_PRIMED ||
|
||||||
|
(sentence_state == STATE_ENDING
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
&& sentence_case_check_ending(key_buffer)
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
)) {
|
||||||
|
new_state = STATE_PRIMED;
|
||||||
|
suppress_key = KC_NO;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\'': // Current key is a quote.
|
||||||
|
new_state = sentence_state;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slide key_buffer and state_history buffers one element to the left.
|
||||||
|
// Optimization note: Using manual loops instead of memmove() here saved
|
||||||
|
// ~100 bytes on AVR.
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
for (int8_t i = 0; i < SENTENCE_CASE_BUFFER_SIZE - 1; ++i) {
|
||||||
|
key_buffer[i] = key_buffer[i + 1];
|
||||||
|
}
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
for (int8_t i = 0; i < STATE_HISTORY_SIZE - 1; ++i) {
|
||||||
|
state_history[i] = state_history[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
key_buffer[SENTENCE_CASE_BUFFER_SIZE - 1] = keycode;
|
||||||
|
if (new_state == STATE_ENDING && !sentence_case_check_ending(key_buffer)) {
|
||||||
|
dprintf("Not a real ending.\n");
|
||||||
|
new_state = STATE_INIT;
|
||||||
|
}
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
state_history[STATE_HISTORY_SIZE - 1] = sentence_state;
|
||||||
|
|
||||||
|
set_sentence_state(new_state);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sentence_case_just_typed_P(const uint16_t* buffer, const uint16_t* pattern,
|
||||||
|
int8_t pattern_len) {
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
buffer += SENTENCE_CASE_BUFFER_SIZE - pattern_len;
|
||||||
|
for (int8_t i = 0; i < pattern_len; ++i) {
|
||||||
|
if (buffer[i] != pgm_read_word(pattern + i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak)) bool sentence_case_check_ending(const uint16_t* buffer) {
|
||||||
|
#if SENTENCE_CASE_BUFFER_SIZE >= 5
|
||||||
|
// Don't consider the abbreviations "vs." and "etc." to end the sentence.
|
||||||
|
if (SENTENCE_CASE_JUST_TYPED(KC_SPC, KC_V, KC_S, KC_DOT) ||
|
||||||
|
SENTENCE_CASE_JUST_TYPED(KC_SPC, KC_E, KC_T, KC_C, KC_DOT)) {
|
||||||
|
return false; // Not a real sentence ending.
|
||||||
|
}
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE >= 5
|
||||||
|
return true; // Real sentence ending; capitalize next letter.
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak)) char sentence_case_press_user(uint16_t keycode,
|
||||||
|
keyrecord_t* record,
|
||||||
|
uint8_t mods) {
|
||||||
|
if ((mods & ~(MOD_MASK_SHIFT | MOD_BIT(KC_RALT))) == 0) {
|
||||||
|
const bool shifted = mods & MOD_MASK_SHIFT;
|
||||||
|
switch (keycode) {
|
||||||
|
case KC_LCTL ... KC_RGUI: // Mod keys.
|
||||||
|
return '\0'; // These keys are ignored.
|
||||||
|
|
||||||
|
case KC_A ... KC_Z:
|
||||||
|
return 'a'; // Letter key.
|
||||||
|
|
||||||
|
case KC_DOT: // . is punctuation, Shift . is a symbol (>)
|
||||||
|
return !shifted ? '.' : '#';
|
||||||
|
case KC_1:
|
||||||
|
case KC_SLSH:
|
||||||
|
return shifted ? '.' : '#';
|
||||||
|
case KC_2 ... KC_0: // 2 3 4 5 6 7 8 9 0
|
||||||
|
case KC_MINS ... KC_SCLN: // - = [ ] ; backslash
|
||||||
|
case KC_GRV:
|
||||||
|
case KC_COMM:
|
||||||
|
return '#'; // Symbol key.
|
||||||
|
|
||||||
|
case KC_SPC:
|
||||||
|
return ' '; // Space key.
|
||||||
|
|
||||||
|
case KC_QUOT:
|
||||||
|
return '\''; // Quote key.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise clear Sentence Case to initial state.
|
||||||
|
sentence_case_clear();
|
||||||
|
return '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak)) void sentence_case_primed(bool primed) {}
|
||||||
|
|
||||||
|
#endif // NO_ACTION_ONESHOT
|
224
keyboards/crkbd/keymaps/sajenim/features/sentence_case.h
Normal file
224
keyboards/crkbd/keymaps/sajenim/features/sentence_case.h
Normal file
|
@ -0,0 +1,224 @@
|
||||||
|
// Copyright 2022 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 sentence_case.h
|
||||||
|
* @brief Sentence case: automatically capitalize the first letter of sentences.
|
||||||
|
*
|
||||||
|
* This library automatically capitalizes the first letter of sentences,
|
||||||
|
* reducing the need to explicitly use shift. To use it, you simply type as
|
||||||
|
* usual but without shifting at the start of sentences. The feature detects
|
||||||
|
* when new sentences begin and capitalizes automatically.
|
||||||
|
*
|
||||||
|
* Sentence Case matches patterns like
|
||||||
|
*
|
||||||
|
* "a. a"
|
||||||
|
* "a. a"
|
||||||
|
* "a? a"
|
||||||
|
* "a!' 'a"
|
||||||
|
*
|
||||||
|
* but not
|
||||||
|
*
|
||||||
|
* "a... a"
|
||||||
|
* "a.a. a"
|
||||||
|
*
|
||||||
|
* Additionally by default, abbreviations "vs." and "etc." are exceptionally
|
||||||
|
* detected as not real sentence endings. You can use the callback
|
||||||
|
* `sentence_case_check_ending()` to define other exceptions.
|
||||||
|
*
|
||||||
|
* @note One-shot keys must be enabled.
|
||||||
|
*
|
||||||
|
* For full documentation, see
|
||||||
|
* <https://getreuer.info/posts/keyboards/sentence-case>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The size of the keycode buffer for `sentence_case_check_ending()`. It must be
|
||||||
|
// at least as large as the longest pattern checked. If less than 2, buffering
|
||||||
|
// is disabled and the callback is not called.
|
||||||
|
#ifndef SENTENCE_CASE_BUFFER_SIZE
|
||||||
|
#define SENTENCE_CASE_BUFFER_SIZE 8
|
||||||
|
#endif // SENTENCE_CASE_BUFFER_SIZE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler function for Sentence Case.
|
||||||
|
*
|
||||||
|
* Call this function from `process_record_user()` to implement Sentence Case.
|
||||||
|
*/
|
||||||
|
bool process_sentence_case(uint16_t keycode, keyrecord_t* record);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn sentence_case_task(void)
|
||||||
|
* Matrix task function for Sentence Case.
|
||||||
|
*
|
||||||
|
* If using `SENTENCE_CASE_TIMEOUT`, call this function from your
|
||||||
|
* `matrix_scan_user()` function in keymap.c. (If no timeout is set, calling
|
||||||
|
* `sentence_case_task()` has no effect.)
|
||||||
|
*/
|
||||||
|
#if SENTENCE_CASE_TIMEOUT > 0
|
||||||
|
void sentence_case_task(void);
|
||||||
|
#else
|
||||||
|
static inline void sentence_case_task(void) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sentence_case_on(void); /**< Enables Sentence Case. */
|
||||||
|
void sentence_case_off(void); /**< Disables Sentence Case. */
|
||||||
|
void sentence_case_toggle(void); /**< Toggles Sentence Case. */
|
||||||
|
bool is_sentence_case_on(void); /**< Gets whether currently enabled. */
|
||||||
|
void sentence_case_clear(void); /**< Clears Sentence Case to initial state. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional callback to indicate primed state.
|
||||||
|
*
|
||||||
|
* This callback gets called when Sentence Case changes to or from a "primed"
|
||||||
|
* state, useful to indicate with an LED or otherwise that the next letter typed
|
||||||
|
* will be capitalized.
|
||||||
|
*/
|
||||||
|
void sentence_case_primed(bool primed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional callback to determine whether there is a real sentence ending.
|
||||||
|
*
|
||||||
|
* When a sentence-ending punctuation key is typed, this callback is called to
|
||||||
|
* determine whether it is a real sentence ending, meaning the first letter of
|
||||||
|
* the following word should be capitalized. For instance, abbreviations like
|
||||||
|
* "vs." are usually not real sentence endings. The input argument is a buffer
|
||||||
|
* of the last SENTENCE_CASE_BUFFER_SIZE keycodes. Returning true means it is a
|
||||||
|
* real sentence ending; returning false means it is not.
|
||||||
|
*
|
||||||
|
* The default implementation checks for the abbreviations "vs." and "etc.":
|
||||||
|
*
|
||||||
|
* bool sentence_case_check_ending(const uint16_t* buffer) {
|
||||||
|
* // Don't consider "vs." and "etc." to end the sentence.
|
||||||
|
* if (SENTENCE_CASE_JUST_TYPED(KC_SPC, KC_V, KC_S, KC_DOT) ||
|
||||||
|
* SENTENCE_CASE_JUST_TYPED(KC_SPC, KC_E, KC_T, KC_C, KC_DOT)) {
|
||||||
|
* return false; // Not a real sentence ending.
|
||||||
|
* }
|
||||||
|
* return true; // Real sentence ending; capitalize next letter.
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @note This callback is used only if `SENTENCE_CASE_BUFFER_SIZE >= 2`.
|
||||||
|
* Otherwise it has no effect.
|
||||||
|
*
|
||||||
|
* @param buffer Buffer of the last `SENTENCE_CASE_BUFFER_SIZE` keycodes.
|
||||||
|
* @return whether there is a real sentence ending.
|
||||||
|
*/
|
||||||
|
bool sentence_case_check_ending(const uint16_t* buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Macro to be used in `sentence_case_check_ending()`.
|
||||||
|
*
|
||||||
|
* Returns true if a given pattern of keys was just typed by comparing with the
|
||||||
|
* keycode buffer. This is useful for defining exceptions in
|
||||||
|
* `sentence_case_check_ending()`.
|
||||||
|
*
|
||||||
|
* For example, `SENTENCE_CASE_JUST_TYPED(KC_SPC, KC_V, KC_S, KC_DOT)` returns
|
||||||
|
* true if " vs." were the last four keys typed.
|
||||||
|
*
|
||||||
|
* @note The pattern must be no longer than `SENTENCE_CASE_BUFFER_SIZE`.
|
||||||
|
*/
|
||||||
|
#define SENTENCE_CASE_JUST_TYPED(...) \
|
||||||
|
({ \
|
||||||
|
static const uint16_t PROGMEM pattern[] = {__VA_ARGS__}; \
|
||||||
|
sentence_case_just_typed_P(buffer, pattern, \
|
||||||
|
sizeof(pattern) / sizeof(uint16_t)); \
|
||||||
|
})
|
||||||
|
bool sentence_case_just_typed_P(const uint16_t* buffer, const uint16_t* pattern,
|
||||||
|
int8_t pattern_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional callback defining which keys are letter, punctuation, etc.
|
||||||
|
*
|
||||||
|
* This callback may be useful if you type non-US letters or have customized the
|
||||||
|
* shift behavior of the punctuation keys. The return value tells Sentence Case
|
||||||
|
* how to interpret the key:
|
||||||
|
*
|
||||||
|
* 'a' Key is a letter, by default KC_A to KC_Z. If occurring at the start of
|
||||||
|
* a sentence, Sentence Case applies shift to capitalize it.
|
||||||
|
*
|
||||||
|
* '.' Key is sentence-ending punctuation. Default: . ? !
|
||||||
|
*
|
||||||
|
* '#' Key types a backspaceable character that isn't part of a word.
|
||||||
|
* Default: - = [ ] ; ' ` , < > / digits backslash
|
||||||
|
*
|
||||||
|
* ' ' Key is a space. Default: KC_SPC
|
||||||
|
*
|
||||||
|
* '\'' Key is a quote or double quote character. Default: KC_QUOT.
|
||||||
|
*
|
||||||
|
* '\0' Sentence Case should ignore this key.
|
||||||
|
*
|
||||||
|
* If a hotkey or navigation key is pressed (or another key that performs an
|
||||||
|
* action that backspace doesn't undo), then the callback should call
|
||||||
|
* `sentence_case_clear()` to clear the state and then return '\0'.
|
||||||
|
*
|
||||||
|
* The default callback is:
|
||||||
|
*
|
||||||
|
* char sentence_case_press_user(uint16_t keycode,
|
||||||
|
* keyrecord_t* record,
|
||||||
|
* uint8_t mods) {
|
||||||
|
* if ((mods & ~(MOD_MASK_SHIFT | MOD_BIT(KC_RALT))) == 0) {
|
||||||
|
* const bool shifted = mods & MOD_MASK_SHIFT;
|
||||||
|
* switch (keycode) {
|
||||||
|
* case KC_LCTL ... KC_RGUI: // Mod keys.
|
||||||
|
* return '\0'; // These keys are ignored.
|
||||||
|
*
|
||||||
|
* case KC_A ... KC_Z:
|
||||||
|
* return 'a'; // Letter key.
|
||||||
|
*
|
||||||
|
* case KC_DOT: // . is punctuation, Shift . is a symbol (>)
|
||||||
|
* return !shifted ? '.' : '#';
|
||||||
|
* case KC_1:
|
||||||
|
* case KC_SLSH:
|
||||||
|
* return shifted ? '.' : '#';
|
||||||
|
* case KC_2 ... KC_0: // 2 3 4 5 6 7 8 9 0
|
||||||
|
* case KC_MINS ... KC_SCLN: // - = [ ] ; backslash
|
||||||
|
* case KC_GRV:
|
||||||
|
* case KC_COMM:
|
||||||
|
* return '#'; // Symbol key.
|
||||||
|
*
|
||||||
|
* case KC_SPC:
|
||||||
|
* return ' '; // Space key.
|
||||||
|
*
|
||||||
|
* case KC_QUOT:
|
||||||
|
* return '\''; // Quote key.
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // Otherwise clear Sentence Case to initial state.
|
||||||
|
* sentence_case_clear();
|
||||||
|
* return '\0';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* To customize, copy the above function into your keymap and add/remove
|
||||||
|
* keycodes to the above cases.
|
||||||
|
*
|
||||||
|
* @param keycode Current keycode.
|
||||||
|
* @param record record_t for the current press event.
|
||||||
|
* @param mods equal to `get_mods() | get_weak_mods() | get_oneshot_mods()`
|
||||||
|
* @return char code 'a', '.', '#', ' ', or '\0' indicating how the key is to be
|
||||||
|
* interpreted as described above.
|
||||||
|
*/
|
||||||
|
char sentence_case_press_user(uint16_t keycode, keyrecord_t* record,
|
||||||
|
uint8_t mods);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -24,32 +24,55 @@
|
||||||
/* Keymaps */
|
/* Keymaps */
|
||||||
|
|
||||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[L_QWERTY] = LAYOUT_split_3x6_3(
|
||||||
|
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
||||||
|
QK_GESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, BSPC_DW,
|
||||||
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
|
TABCTRL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
|
||||||
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
|
OS_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, OS_RSFT,
|
||||||
|
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
||||||
|
GUI_EXT, BAK_LWR, SPC_EXT, ENT_SFT, DEL_RSE, ALT_EXT
|
||||||
|
//`--------------------------' `--------------------------'
|
||||||
|
),
|
||||||
|
|
||||||
[L_CANARY] = LAYOUT_split_3x6_3(
|
[L_CANARY] = LAYOUT_split_3x6_3(
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
||||||
KC_GRV, KC_W, KC_L, KC_Y, KC_P, KC_B, KC_Z, KC_F, KC_O, KC_U, KC_QUOT, XXXXXXX,
|
QK_GESC, KC_W, KC_L, KC_Y, KC_P, KC_B, KC_Z, KC_F, KC_O, KC_U, KC_QUOT, BSPC_DW,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
BAKWORD, HOME_C, HOME_R, HOME_S, HOME_T, KC_G, KC_M, HOME_N, HOME_E, HOME_I, HOME_A, DELWORD,
|
TABCTRL, KC_C, KC_R, KC_S, KC_T, KC_G, KC_M, KC_N, KC_E, KC_I, KC_A, KC_SCLN,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
XXXXXXX, KC_Q, KC_J, KC_V, KC_D, KC_K, KC_X, KC_H, KC_SLSH, KC_COMM, KC_DOT, XXXXXXX,
|
OS_LSFT, KC_Q, KC_J, KC_V, KC_D, KC_K, KC_X, KC_H, KC_SLSH, KC_COMM, KC_DOT, OS_RSFT,
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
||||||
LOWER, FN_PFX, FN_SPC, FN_ENT, FN_LDR, RAISE
|
GUI_EXT, BAK_LWR, SPC_EXT, ENT_SFT, DEL_RSE, ALT_EXT
|
||||||
//`--------------------------' `--------------------------'
|
//`--------------------------' `--------------------------'
|
||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
[L_NAVIGATION] = LAYOUT_split_3x6_3(
|
[L_EXTEND] = LAYOUT_split_3x6_3(
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
||||||
_______, XXXXXXX, XXXXXXX, KC_PGUP, KC_PGDN, XXXXXXX, XXXXXXX, KC_HOME, KC_END, XXXXXXX, XXXXXXX, _______,
|
XXXXXXX, XXXXXXX, XXXXXXX, KC_UP, XXXXXXX, XXXXXXX, KC_PGUP, KC_HOME, KC_UP, KC_END, KC_DEL, BSPC_DW,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
_______, OS_LGUI, OS_LALT, OS_LSFT, OS_LCTL, XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, _______,
|
XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT, XXXXXXX, KC_PGDN, KC_LEFT, KC_DOWN, KC_RGHT, KC_BSPC, KC_COLN,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______,
|
KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_0, KC_1, KC_2, KC_3, KC_4, KC_5,
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
||||||
_______, _______, _______, KC_TAB, _______, _______
|
XXXXXXX, XXXXXXX, XXXXXXX, WZ_CMOD, WZ_COPY, WZ_PSTE
|
||||||
//`--------------------------' `--------------------------'
|
//`--------------------------' `--------------------------'
|
||||||
),
|
),
|
||||||
|
|
||||||
[L_SYMBOLS] = LAYOUT_split_3x6_3(
|
[L_LOWER] = LAYOUT_split_3x6_3(
|
||||||
|
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
||||||
|
KC_VOLU, KC_MNXT, KC_F7, KC_F8, KC_F9, KC_F10, KC_SLSH, KC_7, KC_8, KC_9, KC_MINS, KC_PWR,
|
||||||
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
|
KC_VOLD, KC_MPRV, KC_F4, KC_F5, KC_F6, KC_F11, KC_ASTR, KC_4, KC_5, KC_6, KC_PLUS, KC_SLEP,
|
||||||
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
|
KC_MUTE, KC_MPLY, KC_F1, KC_F2, KC_F3, KC_F12, KC_0, KC_1, KC_2, KC_3, KC_DOT, KC_WAKE,
|
||||||
|
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
||||||
|
XXXXXXX, _______, XXXXXXX, CK_LOCK, _______, XXXXXXX
|
||||||
|
//`--------------------------' `--------------------------'
|
||||||
|
),
|
||||||
|
|
||||||
|
[L_RAISE] = LAYOUT_split_3x6_3(
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
||||||
XXXXXXX, XXXXXXX, KC_LABK, KC_DLR, KC_RABK, XXXXXXX, XXXXXXX, KC_LBRC, KC_UNDS, KC_RBRC, XXXXXXX, XXXXXXX,
|
XXXXXXX, XXXXXXX, KC_LABK, KC_DLR, KC_RABK, XXXXXXX, XXXXXXX, KC_LBRC, KC_UNDS, KC_RBRC, XXXXXXX, XXXXXXX,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
|
@ -57,127 +80,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
XXXXXXX, XXXXXXX, KC_COLN, KC_ASTR, KC_PLUS, XXXXXXX, XXXXXXX, KC_AMPR, KC_CIRC, KC_TILD, XXXXXXX, XXXXXXX,
|
XXXXXXX, XXXXXXX, KC_COLN, KC_ASTR, KC_PLUS, XXXXXXX, XXXXXXX, KC_AMPR, KC_CIRC, KC_TILD, XXXXXXX, XXXXXXX,
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
||||||
_______, _______, _______, _______, _______, _______
|
XXXXXXX, _______, CK_LOCK, XXXXXXX, _______, XXXXXXX
|
||||||
//`--------------------------' `--------------------------'
|
|
||||||
),
|
|
||||||
|
|
||||||
[L_NUMBERS] = LAYOUT_split_3x6_3(
|
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
|
||||||
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_SLSH, KC_7, KC_8, KC_9, KC_MINS, _______,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
_______, OS_LGUI, OS_LALT, OS_LSFT, OS_LCTL, XXXXXXX, KC_ASTR, KC_4, KC_5, KC_6, KC_PLUS, _______,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_DOT, KC_1, KC_2, KC_3, KC_EQL, _______,
|
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
|
||||||
_______, _______, _______, _______, KC_0, _______
|
|
||||||
//`--------------------------' `--------------------------'
|
|
||||||
),
|
|
||||||
|
|
||||||
[L_MACRO] = LAYOUT_split_3x6_3(
|
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
|
||||||
HOME, XXXXXXX, XXXXXXX, YANK, PSTE, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, UPDIR,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, VI_SAVE, VI_EXIT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
|
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
|
||||||
_______, _______, ST_PSTE, _______, _______, _______
|
|
||||||
//`--------------------------' `--------------------------'
|
|
||||||
),
|
|
||||||
|
|
||||||
[L_LOWER] = LAYOUT_split_3x6_3(
|
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
|
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
|
||||||
_______, _______, _______, _______, _______, _______
|
|
||||||
//`--------------------------' `--------------------------'
|
|
||||||
),
|
|
||||||
|
|
||||||
[L_RAISE] = LAYOUT_split_3x6_3(
|
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
|
||||||
KC_MUTE, KC_F1, KC_F2, KC_F3, KC_F4, XXXXXXX, KC_MSEL, KC_MPLY, KC_MSTP, KC_MPRV, KC_MNXT, KC_SLEP,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
KC_VOLU, KC_F5, KC_F6, KC_F7, KC_F8, XXXXXXX, KC_WHOM, KC_WREF, KC_WSTP, KC_WBAK, KC_WFWD, KC_BRIU,
|
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
|
||||||
KC_VOLD, KC_F9, KC_F10, KC_F11, KC_F12, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BRID,
|
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
|
||||||
_______, _______, _______, _______, _______, _______
|
|
||||||
//`--------------------------' `--------------------------'
|
//`--------------------------' `--------------------------'
|
||||||
),
|
),
|
||||||
|
|
||||||
[L_ADJUST] = LAYOUT_split_3x6_3(
|
[L_ADJUST] = LAYOUT_split_3x6_3(
|
||||||
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
//,-----------------------------------------------------. ,-----------------------------------------------------.
|
||||||
QK_BOOT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, AS_TOGG,
|
QK_BOOT, xQWERTY, xCANARY, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, AS_TOGG,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, AC_TOGG,
|
RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, AC_TOGG,
|
||||||
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
|
||||||
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, CM_TOGG,
|
RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, CM_TOGG,
|
||||||
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
|
||||||
_______, _______, _______, _______, _______, _______
|
XXXXXXX, _______, XXXXXXX, XXXXXXX, _______, XXXXXXX
|
||||||
//`--------------------------' `--------------------------'
|
//`--------------------------' `--------------------------'
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Add Home Row Mods to Auto Shift */
|
|
||||||
|
|
||||||
bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
|
|
||||||
switch(keycode) {
|
|
||||||
// Left hand home-row mods
|
|
||||||
case HOME_C:
|
|
||||||
return true;
|
|
||||||
case HOME_R:
|
|
||||||
return true;
|
|
||||||
case HOME_S:
|
|
||||||
return true;
|
|
||||||
case HOME_T:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Right hand home-row mods
|
|
||||||
case HOME_N:
|
|
||||||
return true;
|
|
||||||
case HOME_E:
|
|
||||||
return true;
|
|
||||||
case HOME_I:
|
|
||||||
return true;
|
|
||||||
case HOME_A:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Configure which words are word breaking */
|
|
||||||
bool caps_word_press_user(uint16_t keycode) {
|
|
||||||
switch (keycode) {
|
|
||||||
// Keycodes that continue Caps Word, with shift applied.
|
|
||||||
case KC_A ... KC_Z:
|
|
||||||
case KC_MINS:
|
|
||||||
add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key.
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Keycodes that continue Caps Word, without shifting.
|
|
||||||
case KC_1 ... KC_0:
|
|
||||||
case KC_BSPC:
|
|
||||||
case KC_DEL:
|
|
||||||
case KC_UNDS:
|
|
||||||
// Our custom keys
|
|
||||||
case BAKWORD:
|
|
||||||
case DELWORD:
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false; // Deactivate Caps Word.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Layer Change */
|
/* Layer Change */
|
||||||
|
|
||||||
layer_state_t layer_state_set_user(layer_state_t state) {
|
layer_state_t layer_state_set_user(layer_state_t state) {
|
||||||
|
|
|
@ -1,31 +1,10 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Our layers
|
// Our layers
|
||||||
enum layers {
|
enum layers {
|
||||||
|
L_QWERTY,
|
||||||
L_CANARY,
|
L_CANARY,
|
||||||
|
L_EXTEND,
|
||||||
L_LOWER,
|
L_LOWER,
|
||||||
L_RAISE,
|
L_RAISE,
|
||||||
L_ADJUST,
|
L_ADJUST,
|
||||||
L_NAVIGATION,
|
|
||||||
L_SYMBOLS,
|
|
||||||
L_NUMBERS,
|
|
||||||
L_OPERATORS,
|
|
||||||
L_MACRO,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#include QMK_KEYBOARD_H
|
|
||||||
#include "leader.h"
|
|
||||||
#include "secrets.h"
|
|
||||||
|
|
||||||
LEADER_EXTERNS();
|
|
||||||
|
|
||||||
void matrix_scan_user(void) {
|
|
||||||
LEADER_DICTIONARY() {
|
|
||||||
leading = false;
|
|
||||||
leader_end();
|
|
||||||
|
|
||||||
/* Emerge */
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_S) {
|
|
||||||
SEND_STRING(SEARCH);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_I) {
|
|
||||||
SEND_STRING(INSTALL);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_R) {
|
|
||||||
SEND_STRING(REMOVE);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_U) {
|
|
||||||
SEND_STRING(UPDATE);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_D) {
|
|
||||||
SEND_STRING(DEPCLEAN);
|
|
||||||
}
|
|
||||||
SEQ_THREE_KEYS(KC_E, KC_U, KC_U) {
|
|
||||||
SEND_STRING(UPGRADE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Expansion */
|
|
||||||
SEQ_TWO_KEYS(KC_G, KC_M) {
|
|
||||||
SEND_STRING(GM);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_G, KC_N) {
|
|
||||||
SEND_STRING(GN);
|
|
||||||
}
|
|
||||||
SEQ_FOUR_KEYS(KC_R, KC_T, KC_F, KC_M) {
|
|
||||||
SEND_STRING(RTFM);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Secrets */
|
|
||||||
SEQ_TWO_KEYS(KC_A, KC_H) {
|
|
||||||
SEND_STRING(ADDRESS);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_P, KC_M) {
|
|
||||||
SEND_STRING(PHONE);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_O) {
|
|
||||||
SEND_STRING(OUTLOOK);
|
|
||||||
}
|
|
||||||
SEQ_TWO_KEYS(KC_E, KC_P) {
|
|
||||||
SEND_STRING(PROTON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/* Emerge */
|
|
||||||
#define SEARCH "sudo emerge --search "
|
|
||||||
#define INSTALL "sudo emerge --ask "
|
|
||||||
#define REMOVE "sudo emerge --ask --deselect "
|
|
||||||
#define UPDATE "sudo emerge --sync"
|
|
||||||
#define DEPCLEAN "sudo emerge --ask --depclean"
|
|
||||||
#define UPGRADE "sudo emerge --ask --update --deep --newuse --with-bdeps=y @world"
|
|
||||||
|
|
||||||
/* Expansion */
|
|
||||||
#define GM "Goodmorning friends, I hope we all have/had a wonderfull day. :sunflower:"
|
|
||||||
#define GN "Well i think it's time to hit the hay, farewell comrades. :sleeping:"
|
|
||||||
#define RTFM "Read the fucking manual! :pepedumb:"
|
|
||||||
|
|
|
@ -1,22 +1,5 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include QMK_KEYBOARD_H
|
#include QMK_KEYBOARD_H
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "oled.h"
|
|
||||||
#include "layers.h"
|
#include "layers.h"
|
||||||
|
|
||||||
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
|
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
|
||||||
|
@ -31,6 +14,9 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {
|
||||||
void oled_render_master(void) {
|
void oled_render_master(void) {
|
||||||
// Layer Status
|
// Layer Status
|
||||||
switch (get_highest_layer(layer_state)) {
|
switch (get_highest_layer(layer_state)) {
|
||||||
|
case L_QWERTY:
|
||||||
|
oled_write("QWRTY", false);
|
||||||
|
break;
|
||||||
case L_CANARY:
|
case L_CANARY:
|
||||||
oled_write("CANRY", false);
|
oled_write("CANRY", false);
|
||||||
break;
|
break;
|
||||||
|
@ -43,20 +29,8 @@ void oled_render_master(void) {
|
||||||
case L_ADJUST:
|
case L_ADJUST:
|
||||||
oled_write("ADJST", false);
|
oled_write("ADJST", false);
|
||||||
break;
|
break;
|
||||||
case L_NAVIGATION:
|
case L_EXTEND:
|
||||||
oled_write_ln(" NAV", false);
|
oled_write("EXTND", false);
|
||||||
break;
|
|
||||||
case L_SYMBOLS:
|
|
||||||
oled_write_ln(" SYM", false);
|
|
||||||
break;
|
|
||||||
case L_NUMBERS:
|
|
||||||
oled_write_ln(" NUM", false);
|
|
||||||
break;
|
|
||||||
case L_OPERATORS:
|
|
||||||
oled_write("OPER8", false);
|
|
||||||
break;
|
|
||||||
case L_MACRO:
|
|
||||||
oled_write("MACRO", false);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
oled_write_ln(" UND", false);
|
oled_write_ln(" UND", false);
|
||||||
|
|
|
@ -1,50 +1,46 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "process_record.h"
|
#include "process_record.h"
|
||||||
|
#include "layers.h"
|
||||||
|
#include "features/layer_lock.h"
|
||||||
|
#include "features/sentence_case.h"
|
||||||
|
|
||||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
if (!process_layer_lock(keycode, record, CK_LOCK)) { return false; }
|
||||||
|
if (!process_sentence_case(keycode, record)) { return false; }
|
||||||
|
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case VI_SAVE:
|
case GUI_EXT:
|
||||||
if (record->event.pressed) {
|
if (record->tap.count && record->event.pressed) {
|
||||||
tap_code(KC_ESC);
|
set_oneshot_mods(MOD_BIT(KC_LGUI));
|
||||||
SEND_STRING(":w");
|
return false;
|
||||||
tap_code(KC_ENT);
|
} else if (record->event.pressed) {
|
||||||
}
|
register_mods(MOD_BIT(KC_LGUI));
|
||||||
break;
|
layer_on(L_EXTEND);
|
||||||
|
} else {
|
||||||
|
unregister_mods(MOD_BIT(KC_LGUI));
|
||||||
|
layer_off(L_EXTEND);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
case VI_EXIT:
|
case ALT_EXT:
|
||||||
if (record->event.pressed) {
|
if (record->tap.count && record->event.pressed) {
|
||||||
tap_code(KC_ESC);
|
set_oneshot_mods(MOD_BIT(KC_LALT));
|
||||||
SEND_STRING(":q!");
|
return false;
|
||||||
tap_code(KC_ENT);
|
} else if (record->event.pressed) {
|
||||||
}
|
register_mods(MOD_BIT(KC_LALT));
|
||||||
break;
|
layer_on(L_EXTEND);
|
||||||
|
} else {
|
||||||
|
unregister_mods(MOD_BIT(KC_LALT));
|
||||||
|
layer_off(L_EXTEND);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
case HOME:
|
case BSPC_DW:
|
||||||
if (record->event.pressed) {
|
if (record->tap.count && record ->event.pressed) {
|
||||||
SEND_STRING("~/");
|
tap_code(KC_BSPC);
|
||||||
}
|
} else if (record->event.pressed) {
|
||||||
break;
|
tap_code16(C(KC_W));
|
||||||
|
}
|
||||||
case UPDIR:
|
return false;
|
||||||
if (record->event.pressed) {
|
|
||||||
SEND_STRING("../");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,59 +1,24 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "quantum.h"
|
#include "quantum.h"
|
||||||
#include "tapdance.h"
|
|
||||||
|
|
||||||
// Our custom keycodes
|
// Our custom keycodes
|
||||||
enum custom_keycodes {
|
enum custom_keycodes {
|
||||||
VI_SAVE = SAFE_RANGE,
|
CK_LOCK = SAFE_RANGE,
|
||||||
VI_EXIT,
|
BSPC_DW,
|
||||||
HOME,
|
|
||||||
UPDIR
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Left-hand thumb key layers
|
// Left-hand thumb key layers
|
||||||
#define LOWER MO(L_LOWER)
|
#define GUI_EXT LT(L_EXTEND, KC_LGUI)
|
||||||
#define FN_PFX TD(TD_FNPFX)
|
#define BAK_LWR LT(L_LOWER, KC_BSPC)
|
||||||
#define FN_SPC LT(L_NAVIGATION, KC_SPC)
|
#define SPC_EXT LT(L_EXTEND, KC_SPC)
|
||||||
|
|
||||||
// Right-hand thumb key layers
|
// Right-hand thumb key layers
|
||||||
#define FN_ENT LT(L_MACRO, KC_ENT)
|
#define ENT_SFT MT(MOD_LSFT, KC_ENT)
|
||||||
#define FN_LDR TD(TD_FNLDR)
|
#define DEL_RSE LT(L_RAISE, KC_DEL)
|
||||||
#define RAISE MO(L_RAISE)
|
#define ALT_EXT LT(L_EXTEND, KC_LALT)
|
||||||
|
|
||||||
// Left-hand home row mods
|
|
||||||
#define HOME_C LGUI_T(KC_C)
|
|
||||||
#define HOME_R LALT_T(KC_R)
|
|
||||||
#define HOME_S LSFT_T(KC_S)
|
|
||||||
#define HOME_T LCTL_T(KC_T)
|
|
||||||
|
|
||||||
// Right-hand home row mods
|
|
||||||
#define HOME_N RCTL_T(KC_N)
|
|
||||||
#define HOME_E RSFT_T(KC_E)
|
|
||||||
#define HOME_I RALT_T(KC_I)
|
|
||||||
#define HOME_A RGUI_T(KC_A)
|
|
||||||
|
|
||||||
// One Shot Keys
|
// One Shot Keys
|
||||||
#define OS_MEH OSM(MOD_MEH)
|
|
||||||
#define OS_SUPR OSM(MOD_LGUI)
|
|
||||||
#define OS_HYPR OSM(MOD_HYPR)
|
|
||||||
|
|
||||||
#define OS_LCTL OSM(MOD_LCTL)
|
#define OS_LCTL OSM(MOD_LCTL)
|
||||||
#define OS_LSFT OSM(MOD_LSFT)
|
#define OS_LSFT OSM(MOD_LSFT)
|
||||||
#define OS_LALT OSM(MOD_LALT)
|
#define OS_LALT OSM(MOD_LALT)
|
||||||
|
@ -64,13 +29,16 @@ enum custom_keycodes {
|
||||||
#define OS_RALT OSM(MOD_RALT)
|
#define OS_RALT OSM(MOD_RALT)
|
||||||
#define OS_RGUI OSM(MOD_RGUI)
|
#define OS_RGUI OSM(MOD_RGUI)
|
||||||
|
|
||||||
// Tap Dance
|
// Default Layers
|
||||||
#define YANK TD(TD_YANK)
|
#define xQWERTY DF(L_QWERTY)
|
||||||
#define PSTE TD(TD_PSTE)
|
#define xCANARY DF(L_CANARY)
|
||||||
#define BAKWORD TD(TD_BAKWORD)
|
|
||||||
#define DELWORD TD(TD_DELWORD)
|
|
||||||
|
|
||||||
// Shortcuts
|
// Shortcuts
|
||||||
#define PREFIX LCTL(KC_B)
|
#define WZ_CMOD LCTL(LSFT(KC_X))
|
||||||
#define ST_PSTE LSFT(KC_INSERT)
|
#define WZ_COPY LCTL(LSFT(KC_C))
|
||||||
|
#define WZ_PSTE LCTL(LSFT(KC_V))
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
#define TABCTRL MT(MOD_LCTL, KC_TAB)
|
||||||
|
#define BSPC_DW MT(MOD_LCTL, KC_BSPC)
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,29 @@
|
||||||
# We are using a Splinky RP2040 as a drop-in replacement controller
|
# We are using a Splinky RP2040 as a drop-in replacement controller
|
||||||
CONVERT_TO = promicro_rp2040
|
CONVERT_TO = promicro_rp2040
|
||||||
|
|
||||||
# Bootloader selection
|
|
||||||
BOOTLOADER = rp2040
|
BOOTLOADER = rp2040
|
||||||
|
|
||||||
# Default features
|
# Default features
|
||||||
LTO_ENABLE = yes
|
LTO_ENABLE = yes
|
||||||
OLED_DRIVER = SSD1306
|
|
||||||
|
|
||||||
# Toggleable through keymap
|
|
||||||
AUTO_SHIFT_ENABLE = yes
|
|
||||||
AUTOCORRECT_ENABLE = yes
|
|
||||||
CAPS_WORD_ENABLE = yes
|
|
||||||
|
|
||||||
# Optional features
|
# Optional features
|
||||||
OLED_ENABLE = yes
|
OLED_ENABLE = yes
|
||||||
COMBO_ENABLE = yes
|
RGBLIGHT_ENABLE = yes
|
||||||
TAP_DANCE_ENABLE = yes
|
COMBO_ENABLE = yes
|
||||||
LEADER_ENABLE = yes
|
# Toggleable through keymap
|
||||||
# Only required if OLED_ENABLE = yes
|
AUTO_SHIFT_ENABLE = yes
|
||||||
WPM_ENABLE = yes
|
AUTOCORRECT_ENABLE = yes
|
||||||
|
CAPS_WORD_ENABLE = yes
|
||||||
|
|
||||||
# Source required c files
|
SRC += process_record.c
|
||||||
SRC += ./process_record.c
|
SRC += features/layer_lock.c
|
||||||
|
SRC += features/sentence_case.c
|
||||||
|
|
||||||
# Contitionally source optional c files
|
|
||||||
ifeq ($(OLED_ENABLE),yes)
|
ifeq ($(OLED_ENABLE),yes)
|
||||||
SRC += ./oled.c
|
SRC += ./oled.c
|
||||||
|
OLED_DRIVER = SSD1306
|
||||||
|
WPM_ENABLE = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(COMBO_ENABLE),yes)
|
ifeq ($(COMBO_ENABLE),yes)
|
||||||
VPATH += keyboards/gboards
|
VPATH += keyboards/gboards
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(TAP_DANCE_ENABLE),yes)
|
|
||||||
SRC += ./tapdance.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(LEADER_ENABLE),yes)
|
|
||||||
SRC += ./leader.c
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,350 +0,0 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include QMK_KEYBOARD_H
|
|
||||||
#include "layers.h"
|
|
||||||
#include "tapdance.h"
|
|
||||||
|
|
||||||
/* Return an integer that corresponds to what kind of tap dance should be executed.
|
|
||||||
*
|
|
||||||
* How to figure out tap dance state: interrupted and pressed.
|
|
||||||
*
|
|
||||||
* Interrupted: If the state of a dance is "interrupted", that means that another key has been hit
|
|
||||||
* under the tapping term. This is typically indicitive that you are trying to "tap" the key.
|
|
||||||
*
|
|
||||||
* Pressed: Whether or not the key is still being pressed. If this value is true, that means the tapping term
|
|
||||||
* has ended, but the key is still being pressed down. This generally means the key is being "held".
|
|
||||||
*
|
|
||||||
* One thing that is currenlty not possible with qmk software in regards to tap dance is to mimic the "permissive hold"
|
|
||||||
* feature. In general, advanced tap dances do not work well if they are used with commonly typed letters.
|
|
||||||
* For example "A". Tap dances are best used on non-letter keys that are not hit while typing letters.
|
|
||||||
*
|
|
||||||
* Good places to put an advanced tap dance:
|
|
||||||
* z,q,x,j,k,v,b, any function key, home/end, comma, semi-colon
|
|
||||||
*
|
|
||||||
* Criteria for "good placement" of a tap dance key:
|
|
||||||
* Not a key that is hit frequently in a sentence
|
|
||||||
* Not a key that is used frequently to double tap, for example 'tab' is often double tapped in a terminal, or
|
|
||||||
* in a web form. So 'tab' would be a poor choice for a tap dance.
|
|
||||||
* Letters used in common words as a double. For example 'p' in 'pepper'. If a tap dance function existed on the
|
|
||||||
* letter 'p', the word 'pepper' would be quite frustating to type.
|
|
||||||
*
|
|
||||||
* For the third point, there does exist the 'TD_DOUBLE_SINGLE_TAP', however this is not fully tested
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
td_state_t cur_dance(qk_tap_dance_state_t *state) {
|
|
||||||
if (state->count == 1) {
|
|
||||||
if (state->interrupted || !state->pressed) return TD_SINGLE_TAP;
|
|
||||||
// Key has not been interrupted, but the key is still held. Means you want to send a 'HOLD'.
|
|
||||||
else return TD_SINGLE_HOLD;
|
|
||||||
} else if (state->count == 2) {
|
|
||||||
// TD_DOUBLE_SINGLE_TAP is to distinguish between typing "pepper", and actually wanting a double tap
|
|
||||||
// action when hitting 'pp'. Suggested use case for this return value is when you want to send two
|
|
||||||
// keystrokes of the key, and not the 'double tap' action/macro.
|
|
||||||
if (state->interrupted) return TD_DOUBLE_SINGLE_TAP;
|
|
||||||
else if (state->pressed) return TD_DOUBLE_HOLD;
|
|
||||||
else return TD_DOUBLE_TAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assumes no one is trying to type the same letter three times (at least not quickly).
|
|
||||||
// If your tap dance key is 'KC_W', and you want to type "www." quickly - then you will need to add
|
|
||||||
// an exception here to return a 'TD_TRIPLE_SINGLE_TAP', and define that enum just like 'TD_DOUBLE_SINGLE_TAP'
|
|
||||||
if (state->count == 3) {
|
|
||||||
if (state->interrupted || !state->pressed) return TD_TRIPLE_TAP;
|
|
||||||
else return TD_TRIPLE_HOLD;
|
|
||||||
} else return TD_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Yank:
|
|
||||||
*
|
|
||||||
* Sends <ctrl> + <c> on single tap
|
|
||||||
* Sends <ctrl> + <shft> + <c> on double tap (Commonly used in UNIX terminals)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static td_tap_t yank_tap_state = {
|
|
||||||
.is_press_action = true,
|
|
||||||
.state = TD_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
void yank_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
yank_tap_state.state = cur_dance(state);
|
|
||||||
switch (yank_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
register_code(KC_LCTL);
|
|
||||||
register_code(KC_C);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
register_code(KC_LCTL);
|
|
||||||
register_code(KC_LSFT);
|
|
||||||
register_code(KC_C);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void yank_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
switch (yank_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
unregister_code(KC_LCTL);
|
|
||||||
unregister_code(KC_C);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
unregister_code(KC_LCTL);
|
|
||||||
unregister_code(KC_LSFT);
|
|
||||||
unregister_code(KC_C);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
yank_tap_state.state = TD_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Paste:
|
|
||||||
*
|
|
||||||
* Sends <ctrl> + <v> on single tap
|
|
||||||
* Sends <ctrl> + <shft> + <v> on double tap (Commonly used in UNIX terminals)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static td_tap_t pste_tap_state = {
|
|
||||||
.is_press_action = true,
|
|
||||||
.state = TD_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
void pste_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
pste_tap_state.state = cur_dance(state);
|
|
||||||
switch (pste_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
register_code(KC_LCTL);
|
|
||||||
register_code(KC_V);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
register_code(KC_LCTL);
|
|
||||||
register_code(KC_LSFT);
|
|
||||||
register_code(KC_V);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pste_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
switch (pste_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
unregister_code(KC_LCTL);
|
|
||||||
unregister_code(KC_V);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
unregister_code(KC_LCTL);
|
|
||||||
unregister_code(KC_LSFT);
|
|
||||||
unregister_code(KC_V);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pste_tap_state.state = TD_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Delete word:
|
|
||||||
*
|
|
||||||
* Sends delete on single tap or hold
|
|
||||||
* Sends <esc> + "daw" on double tap (Vim: delete the word under the cursor)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static td_tap_t delword_tap_state = {
|
|
||||||
.is_press_action = true,
|
|
||||||
.state = TD_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
void delword_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
delword_tap_state.state = cur_dance(state);
|
|
||||||
switch (delword_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
register_code(KC_DEL);
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
register_code(KC_DEL);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
tap_code(KC_ESC);
|
|
||||||
SEND_STRING("daw");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void delword_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
switch (delword_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
unregister_code(KC_DEL);
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
unregister_code(KC_DEL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
delword_tap_state.state = TD_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Back word:
|
|
||||||
*
|
|
||||||
* Sends bacspace on single tap or hold
|
|
||||||
* Sends <ctrl> + <w> on double tap (Bash: remove the command/argument before the cursor)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static td_tap_t backword_tap_state = {
|
|
||||||
.is_press_action = true,
|
|
||||||
.state = TD_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
void bakword_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
backword_tap_state.state = cur_dance(state);
|
|
||||||
switch (backword_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
register_code(KC_BSPC);
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
register_code(KC_BSPC);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
register_code(KC_LCTL);
|
|
||||||
register_code(KC_W);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bakword_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
switch (backword_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
unregister_code(KC_BSPC);
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
unregister_code(KC_BSPC);
|
|
||||||
break;
|
|
||||||
case TD_DOUBLE_TAP:
|
|
||||||
unregister_code(KC_LCTL);
|
|
||||||
unregister_code(KC_W);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
backword_tap_state.state = TD_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Function prefix:
|
|
||||||
*
|
|
||||||
* Send tmux prefix on tap <ctrl> + <b>.
|
|
||||||
* Enable function layer on hold.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static td_tap_t fnpfx_tap_state = {
|
|
||||||
.is_press_action = true,
|
|
||||||
.state = TD_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
void fnpfx_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
fnpfx_tap_state.state = cur_dance(state);
|
|
||||||
switch (fnpfx_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
register_code(KC_LCTL);
|
|
||||||
register_code(KC_B);
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
layer_on(L_NUMBERS);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fnpfx_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
switch (fnpfx_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
unregister_code(KC_LCTL);
|
|
||||||
unregister_code(KC_B);
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
layer_off(L_NUMBERS);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fnpfx_tap_state.state = TD_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Function leader:
|
|
||||||
*
|
|
||||||
* Send leader key on tap.
|
|
||||||
* Enable function layer on hold.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
static td_tap_t fnldr_tap_state = {
|
|
||||||
.is_press_action = true,
|
|
||||||
.state = TD_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
void fnldr_finished(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
fnldr_tap_state.state = cur_dance(state);
|
|
||||||
switch (fnldr_tap_state.state) {
|
|
||||||
case TD_SINGLE_TAP:
|
|
||||||
qk_leader_start();
|
|
||||||
break;
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
layer_on(L_SYMBOLS);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fnldr_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
||||||
switch (fnldr_tap_state.state) {
|
|
||||||
case TD_SINGLE_HOLD:
|
|
||||||
layer_off(L_SYMBOLS);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fnldr_tap_state.state = TD_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define `ACTION_TAP_DANCE_FN_ADVANCED()` for each tapdance keycode, passing in `finished` and `reset` functions
|
|
||||||
qk_tap_dance_action_t tap_dance_actions[] = {
|
|
||||||
[TD_YANK] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, yank_finished, yank_reset),
|
|
||||||
[TD_PSTE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, pste_finished, pste_reset),
|
|
||||||
[TD_DELWORD] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, delword_finished, delword_reset),
|
|
||||||
[TD_BAKWORD] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, bakword_finished, bakword_reset),
|
|
||||||
[TD_FNPFX] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, fnpfx_finished, fnpfx_reset),
|
|
||||||
[TD_FNLDR] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, fnldr_finished, fnldr_reset)
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
/* Copyright 2022 @ sajenim (https://github.com/sajenim)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Our tapdance keycodes
|
|
||||||
enum td_keycodes {
|
|
||||||
TD_YANK,
|
|
||||||
TD_PSTE,
|
|
||||||
TD_BAKWORD,
|
|
||||||
TD_DELWORD,
|
|
||||||
TD_FNPFX,
|
|
||||||
TD_FNLDR
|
|
||||||
};
|
|
||||||
|
|
||||||
// Define a type containing as many tapdance states as we need
|
|
||||||
typedef enum {
|
|
||||||
TD_NONE,
|
|
||||||
TD_UNKNOWN,
|
|
||||||
TD_SINGLE_TAP,
|
|
||||||
TD_SINGLE_HOLD,
|
|
||||||
TD_DOUBLE_TAP,
|
|
||||||
TD_DOUBLE_HOLD,
|
|
||||||
TD_DOUBLE_SINGLE_TAP, // Send two single taps
|
|
||||||
TD_TRIPLE_TAP,
|
|
||||||
TD_TRIPLE_HOLD
|
|
||||||
} td_state_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool is_press_action;
|
|
||||||
td_state_t state;
|
|
||||||
} td_tap_t;
|
|
||||||
|
|
||||||
// Declare our tapdance functions:
|
|
||||||
|
|
||||||
// Function to determine the current tapdance state
|
|
||||||
td_state_t cur_dance(qk_tap_dance_state_t *state);
|
|
||||||
|
|
||||||
// `finished` and `reset` functions for each tapdance keycode
|
|
||||||
void yank_finished(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
void yank_reset(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
|
|
||||||
void pste_finished(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
void pste_reset(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
|
|
||||||
void delword_finished(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
void delword_reset(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
|
|
||||||
void bakword_finished(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
void bakword_reset(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
|
|
||||||
void fnpfx_finished(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
void fnpfx_reset(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
|
|
||||||
void fnldr_finished(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
void fnldr_reset(qk_tap_dance_state_t *state, void *user_data);
|
|
||||||
|
|
Loading…
Reference in a new issue