Smallish overhaul of Auto-Shift feature (#67)
* Fix edge case when using One Shot Layer with Auto Shift, and it not triggering the cleanup * Remove junk code (no longer used) * Replace `(un)register_code` calls with `tap_code` where appropriate * Fixed up Switch check to be more readable (less verbose) * Simplified modifier check (if it comes back non-zero, there are mods) * Add additional function calls for autoshift settings * Made all variables static, since there are function calls to get their status * Fixed up documentation
This commit is contained in:
committed by
Florian Didron
parent
524e2b9487
commit
028d02d1f1
@@ -26,4 +26,5 @@
|
|||||||
05-26-2019 - Add Solus support for Linux install script
|
05-26-2019 - Add Solus support for Linux install script
|
||||||
05-29-2019 - Fix TO() and DF() calling layer_state_set_[kb,user] twice (qmk#6003)
|
05-29-2019 - Fix TO() and DF() calling layer_state_set_[kb,user] twice (qmk#6003)
|
||||||
05-29-2019 - Fixing matrix_scan so it properly returns changed status
|
05-29-2019 - Fixing matrix_scan so it properly returns changed status
|
||||||
05-29-2019 - Add belgian layour for sendstring (qmk#6008)
|
05-29-2019 - Add belgian layour for sendstring (qmk#6008)
|
||||||
|
06-03-2019 - Overhaul of AutoShift feature (qmk#6067)
|
||||||
|
|||||||
@@ -20,191 +20,132 @@
|
|||||||
|
|
||||||
#include "process_auto_shift.h"
|
#include "process_auto_shift.h"
|
||||||
|
|
||||||
#define TAP(key) \
|
static bool autoshift_enabled = true;
|
||||||
register_code(key); \
|
static uint16_t autoshift_time = 0;
|
||||||
unregister_code(key)
|
static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
|
||||||
|
static uint16_t autoshift_lastkey = KC_NO;
|
||||||
#define TAP_WITH_MOD(mod, key) \
|
|
||||||
register_code(mod); \
|
|
||||||
register_code(key); \
|
|
||||||
unregister_code(key); \
|
|
||||||
unregister_code(mod)
|
|
||||||
|
|
||||||
uint16_t autoshift_time = 0;
|
|
||||||
uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
|
|
||||||
uint16_t autoshift_lastkey = KC_NO;
|
|
||||||
|
|
||||||
void autoshift_timer_report(void) {
|
void autoshift_timer_report(void) {
|
||||||
char display[8];
|
char display[8];
|
||||||
|
|
||||||
snprintf(display, 8, "\n%d\n", autoshift_timeout);
|
snprintf(display, 8, "\n%d\n", autoshift_timeout);
|
||||||
|
|
||||||
send_string((const char *)display);
|
send_string((const char *)display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoshift_on(uint16_t keycode) {
|
void autoshift_on(uint16_t keycode) {
|
||||||
autoshift_time = timer_read();
|
autoshift_time = timer_read();
|
||||||
autoshift_lastkey = keycode;
|
autoshift_lastkey = keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoshift_flush(void) {
|
void autoshift_flush(void) {
|
||||||
if (autoshift_lastkey != KC_NO) {
|
if (autoshift_lastkey != KC_NO) {
|
||||||
uint16_t elapsed = timer_elapsed(autoshift_time);
|
uint16_t elapsed = timer_elapsed(autoshift_time);
|
||||||
|
|
||||||
if (elapsed > autoshift_timeout) {
|
if (elapsed > autoshift_timeout) {
|
||||||
register_code(KC_LSFT);
|
tap_code16(LSFT(autoshift_lastkey));
|
||||||
|
} else {
|
||||||
|
tap_code(autoshift_lastkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
autoshift_time = 0;
|
||||||
|
autoshift_lastkey = KC_NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
register_code(autoshift_lastkey);
|
|
||||||
unregister_code(autoshift_lastkey);
|
|
||||||
|
|
||||||
if (elapsed > autoshift_timeout) {
|
|
||||||
unregister_code(KC_LSFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
autoshift_time = 0;
|
|
||||||
autoshift_lastkey = KC_NO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool autoshift_enabled = true;
|
|
||||||
|
|
||||||
void autoshift_enable(void) {
|
void autoshift_enable(void) {
|
||||||
autoshift_enabled = true;
|
autoshift_enabled = true;
|
||||||
}
|
}
|
||||||
void autoshift_disable(void) {
|
void autoshift_disable(void) {
|
||||||
autoshift_enabled = false;
|
autoshift_enabled = false;
|
||||||
autoshift_flush();
|
autoshift_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoshift_toggle(void) {
|
void autoshift_toggle(void) {
|
||||||
if (autoshift_enabled) {
|
if (autoshift_enabled) {
|
||||||
autoshift_enabled = false;
|
autoshift_enabled = false;
|
||||||
autoshift_flush();
|
autoshift_flush();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
autoshift_enabled = true;
|
autoshift_enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool autoshift_state(void) {
|
bool get_autoshift_state(void) {
|
||||||
return autoshift_enabled;
|
return autoshift_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t get_autoshift_timeout(void) {
|
||||||
|
return autoshift_timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_autoshift_timeout(uint16_t timeout) {
|
||||||
|
autoshift_timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
|
bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
|
||||||
#ifndef AUTO_SHIFT_MODIFIERS
|
|
||||||
static uint8_t any_mod_pressed;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case KC_ASUP:
|
case KC_ASUP:
|
||||||
autoshift_timeout += 5;
|
autoshift_timeout += 5;
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
case KC_ASDN:
|
case KC_ASDN:
|
||||||
autoshift_timeout -= 5;
|
autoshift_timeout -= 5;
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
case KC_ASRP:
|
case KC_ASRP:
|
||||||
autoshift_timer_report();
|
autoshift_timer_report();
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
case KC_ASTG:
|
case KC_ASTG:
|
||||||
autoshift_toggle();
|
autoshift_toggle();
|
||||||
return false;
|
return true;
|
||||||
case KC_ASON:
|
case KC_ASON:
|
||||||
autoshift_enable();
|
autoshift_enable();
|
||||||
return false;
|
return true;
|
||||||
case KC_ASOFF:
|
case KC_ASOFF:
|
||||||
autoshift_disable();
|
autoshift_disable();
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
#ifndef NO_AUTO_SHIFT_ALPHA
|
#ifndef NO_AUTO_SHIFT_ALPHA
|
||||||
case KC_A:
|
case KC_A ... KC_Z:
|
||||||
case KC_B:
|
|
||||||
case KC_C:
|
|
||||||
case KC_D:
|
|
||||||
case KC_E:
|
|
||||||
case KC_F:
|
|
||||||
case KC_G:
|
|
||||||
case KC_H:
|
|
||||||
case KC_I:
|
|
||||||
case KC_J:
|
|
||||||
case KC_K:
|
|
||||||
case KC_L:
|
|
||||||
case KC_M:
|
|
||||||
case KC_N:
|
|
||||||
case KC_O:
|
|
||||||
case KC_P:
|
|
||||||
case KC_Q:
|
|
||||||
case KC_R:
|
|
||||||
case KC_S:
|
|
||||||
case KC_T:
|
|
||||||
case KC_U:
|
|
||||||
case KC_V:
|
|
||||||
case KC_W:
|
|
||||||
case KC_X:
|
|
||||||
case KC_Y:
|
|
||||||
case KC_Z:
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_AUTO_SHIFT_NUMERIC
|
#ifndef NO_AUTO_SHIFT_NUMERIC
|
||||||
case KC_1:
|
case KC_1 ... KC_0:
|
||||||
case KC_2:
|
|
||||||
case KC_3:
|
|
||||||
case KC_4:
|
|
||||||
case KC_5:
|
|
||||||
case KC_6:
|
|
||||||
case KC_7:
|
|
||||||
case KC_8:
|
|
||||||
case KC_9:
|
|
||||||
case KC_0:
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_AUTO_SHIFT_SPECIAL
|
#ifndef NO_AUTO_SHIFT_SPECIAL
|
||||||
case KC_MINUS:
|
case KC_MINUS ... KC_SLASH:
|
||||||
case KC_EQL:
|
|
||||||
case KC_TAB:
|
|
||||||
case KC_LBRC:
|
|
||||||
case KC_RBRC:
|
|
||||||
case KC_BSLS:
|
|
||||||
case KC_SCLN:
|
|
||||||
case KC_QUOT:
|
|
||||||
case KC_COMM:
|
|
||||||
case KC_DOT:
|
|
||||||
case KC_SLSH:
|
|
||||||
case KC_GRAVE:
|
|
||||||
case KC_NONUS_BSLASH:
|
|
||||||
case KC_NONUS_HASH:
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
autoshift_flush();
|
autoshift_flush();
|
||||||
if (!autoshift_enabled) return true;
|
if (!autoshift_enabled) return true;
|
||||||
|
|
||||||
#ifndef AUTO_SHIFT_MODIFIERS
|
#ifndef AUTO_SHIFT_MODIFIERS
|
||||||
any_mod_pressed = get_mods() & (
|
if (get_mods()) {
|
||||||
MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
|
return true;
|
||||||
MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
|
}
|
||||||
MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
|
|
||||||
MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (any_mod_pressed) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
autoshift_on(keycode);
|
autoshift_on(keycode);
|
||||||
return false;
|
|
||||||
|
|
||||||
default:
|
// We need some extra handling here for OSL edge cases
|
||||||
|
#if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
|
||||||
|
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
autoshift_flush();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
autoshift_flush();
|
autoshift_flush();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
autoshift_flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,13 +14,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PROCESS_AUTO_SHIFT_H
|
#pragma once
|
||||||
#define PROCESS_AUTO_SHIFT_H
|
|
||||||
|
|
||||||
#include "quantum.h"
|
#include "quantum.h"
|
||||||
|
|
||||||
#ifndef AUTO_SHIFT_TIMEOUT
|
#ifndef AUTO_SHIFT_TIMEOUT
|
||||||
#define AUTO_SHIFT_TIMEOUT 175
|
# define AUTO_SHIFT_TIMEOUT 175
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool process_auto_shift(uint16_t keycode, keyrecord_t *record);
|
bool process_auto_shift(uint16_t keycode, keyrecord_t *record);
|
||||||
@@ -28,6 +27,6 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record);
|
|||||||
void autoshift_enable(void);
|
void autoshift_enable(void);
|
||||||
void autoshift_disable(void);
|
void autoshift_disable(void);
|
||||||
void autoshift_toggle(void);
|
void autoshift_toggle(void);
|
||||||
bool autoshift_state(void);
|
bool get_autoshift_state(void);
|
||||||
|
uint16_t get_autoshift_timeout(void);
|
||||||
#endif
|
void set_autoshift_timeout(uint16_t timeout);
|
||||||
|
|||||||
Reference in New Issue
Block a user