summaryrefslogtreecommitdiffstats
path: root/quantum/process_keycode/process_caps_word.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_caps_word.c')
-rw-r--r--quantum/process_keycode/process_caps_word.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_caps_word.c b/quantum/process_keycode/process_caps_word.c
index 94302b29ae..8f2ee1db8b 100644
--- a/quantum/process_keycode/process_caps_word.c
+++ b/quantum/process_keycode/process_caps_word.c
@@ -14,6 +14,54 @@
#include "process_caps_word.h"
+#ifdef CAPS_WORD_INVERT_ON_SHIFT
+static uint8_t held_mods = 0;
+
+static bool handle_shift(uint16_t keycode, keyrecord_t* record) {
+ switch (keycode) {
+ case OSM(MOD_LSFT):
+ keycode = KC_LSFT;
+ break;
+ case OSM(MOD_RSFT):
+ keycode = KC_RSFT;
+ break;
+
+# ifndef NO_ACTION_TAPPING
+ case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+ if (record->tap.count == 0) { // Mod-tap key is held.
+ switch (QK_MOD_TAP_GET_MODS(keycode)) {
+ case MOD_LSFT:
+ keycode = KC_LSFT;
+ break;
+ case MOD_RSFT:
+ keycode = KC_RSFT;
+ break;
+ }
+ }
+# endif // NO_ACTION_TAPPING
+ }
+
+ if (keycode == KC_LSFT || keycode == KC_RSFT) {
+ const uint8_t mod = MOD_BIT(keycode);
+
+ if (is_caps_word_on()) {
+ if (record->event.pressed) {
+ held_mods |= mod;
+ } else {
+ held_mods &= ~mod;
+ }
+ return false;
+ } else if ((held_mods & mod) != 0) {
+ held_mods &= ~mod;
+ del_mods(mod);
+ return record->event.pressed;
+ }
+ }
+
+ return true;
+}
+#endif // CAPS_WORD_INVERT_ON_SHIFT
+
bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
if (keycode == QK_CAPS_WORD_TOGGLE) {
if (record->event.pressed) {
@@ -21,6 +69,11 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
}
return false;
}
+#ifdef CAPS_WORD_INVERT_ON_SHIFT
+ if (!handle_shift(keycode, record)) {
+ return false;
+ }
+#endif // CAPS_WORD_INVERT_ON_SHIFT
#ifndef NO_ACTION_ONESHOT
const uint8_t mods = get_mods() | get_oneshot_mods();
@@ -111,12 +164,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 +179,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 +221,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;
}