2017-09-17 05:33:28 +00:00
|
|
|
/* Copyright 2017 Jeremy Cowgar
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef AUTO_SHIFT_ENABLE
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
# include <stdio.h>
|
2017-09-17 05:33:28 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
# include "process_auto_shift.h"
|
2017-09-17 05:33:28 +00:00
|
|
|
|
2019-11-03 17:52:01 +00:00
|
|
|
static bool autoshift_enabled = true;
|
|
|
|
static uint16_t autoshift_time = 0;
|
|
|
|
static uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
|
|
|
|
static uint16_t autoshift_lastkey = KC_NO;
|
2017-09-17 05:33:28 +00:00
|
|
|
|
|
|
|
void autoshift_flush(void) {
|
2019-08-30 18:19:03 +00:00
|
|
|
if (autoshift_lastkey != KC_NO) {
|
|
|
|
uint16_t elapsed = timer_elapsed(autoshift_time);
|
2017-09-17 05:33:28 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
if (elapsed > autoshift_timeout) {
|
2019-11-03 17:52:01 +00:00
|
|
|
tap_code16(LSFT(autoshift_lastkey));
|
|
|
|
} else {
|
|
|
|
tap_code(autoshift_lastkey);
|
2019-08-30 18:19:03 +00:00
|
|
|
}
|
2017-09-17 05:33:28 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
autoshift_time = 0;
|
|
|
|
autoshift_lastkey = KC_NO;
|
|
|
|
}
|
2017-09-17 05:33:28 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 20:55:13 +00:00
|
|
|
void autoshift_on(uint16_t keycode) {
|
2020-08-29 22:57:48 +00:00
|
|
|
autoshift_time = timer_read();
|
|
|
|
autoshift_lastkey = keycode;
|
2020-08-15 20:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void autoshift_toggle(void) {
|
2020-08-29 22:57:48 +00:00
|
|
|
if (autoshift_enabled) {
|
|
|
|
autoshift_enabled = false;
|
|
|
|
autoshift_flush();
|
|
|
|
} else {
|
|
|
|
autoshift_enabled = true;
|
|
|
|
}
|
2017-12-19 18:37:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 20:55:13 +00:00
|
|
|
void autoshift_enable(void) { autoshift_enabled = true; }
|
|
|
|
void autoshift_disable(void) {
|
2020-08-29 22:57:48 +00:00
|
|
|
autoshift_enabled = false;
|
|
|
|
autoshift_flush();
|
2017-12-19 18:37:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 22:57:48 +00:00
|
|
|
# ifndef AUTO_SHIFT_NO_SETUP
|
2020-08-15 20:55:13 +00:00
|
|
|
void autoshift_timer_report(void) {
|
2020-08-29 22:57:48 +00:00
|
|
|
char display[8];
|
2020-08-15 20:55:13 +00:00
|
|
|
|
2020-08-29 22:57:48 +00:00
|
|
|
snprintf(display, 8, "\n%d\n", autoshift_timeout);
|
2020-08-15 20:55:13 +00:00
|
|
|
|
2020-08-29 22:57:48 +00:00
|
|
|
send_string((const char *)display);
|
2020-08-15 20:55:13 +00:00
|
|
|
}
|
2020-08-29 22:57:48 +00:00
|
|
|
# endif
|
2020-08-15 20:55:13 +00:00
|
|
|
|
2019-11-03 17:52:01 +00:00
|
|
|
bool get_autoshift_state(void) { return autoshift_enabled; }
|
2017-12-19 18:06:22 +00:00
|
|
|
|
2019-11-03 17:52:01 +00:00
|
|
|
uint16_t get_autoshift_timeout(void) { return autoshift_timeout; }
|
2019-08-30 18:19:03 +00:00
|
|
|
|
2019-11-03 17:52:01 +00:00
|
|
|
void set_autoshift_timeout(uint16_t timeout) { autoshift_timeout = timeout; }
|
|
|
|
|
|
|
|
bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
|
2019-08-30 18:19:03 +00:00
|
|
|
if (record->event.pressed) {
|
|
|
|
switch (keycode) {
|
|
|
|
case KC_ASTG:
|
|
|
|
autoshift_toggle();
|
2019-11-03 17:52:01 +00:00
|
|
|
return true;
|
2020-08-15 20:55:13 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
case KC_ASON:
|
|
|
|
autoshift_enable();
|
2019-11-03 17:52:01 +00:00
|
|
|
return true;
|
2019-08-30 18:19:03 +00:00
|
|
|
case KC_ASOFF:
|
|
|
|
autoshift_disable();
|
2019-11-03 17:52:01 +00:00
|
|
|
return true;
|
2019-08-30 18:19:03 +00:00
|
|
|
|
2020-08-15 20:55:13 +00:00
|
|
|
# ifndef AUTO_SHIFT_NO_SETUP
|
2020-08-29 22:57:48 +00:00
|
|
|
case KC_ASUP:
|
2020-08-15 20:55:13 +00:00
|
|
|
autoshift_timeout += 5;
|
|
|
|
return true;
|
2020-08-29 22:57:48 +00:00
|
|
|
case KC_ASDN:
|
2020-08-15 20:55:13 +00:00
|
|
|
autoshift_timeout -= 5;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KC_ASRP:
|
|
|
|
autoshift_timer_report();
|
|
|
|
return true;
|
|
|
|
# endif
|
2019-08-30 18:19:03 +00:00
|
|
|
# ifndef NO_AUTO_SHIFT_ALPHA
|
2019-11-03 17:52:01 +00:00
|
|
|
case KC_A ... KC_Z:
|
2019-08-30 18:19:03 +00:00
|
|
|
# endif
|
|
|
|
# ifndef NO_AUTO_SHIFT_NUMERIC
|
2019-11-03 17:52:01 +00:00
|
|
|
case KC_1 ... KC_0:
|
2019-08-30 18:19:03 +00:00
|
|
|
# endif
|
|
|
|
# ifndef NO_AUTO_SHIFT_SPECIAL
|
|
|
|
case KC_TAB:
|
2019-11-03 17:52:01 +00:00
|
|
|
case KC_MINUS ... KC_SLASH:
|
2019-08-30 18:19:03 +00:00
|
|
|
case KC_NONUS_BSLASH:
|
|
|
|
# endif
|
|
|
|
autoshift_flush();
|
|
|
|
if (!autoshift_enabled) return true;
|
|
|
|
|
|
|
|
# ifndef AUTO_SHIFT_MODIFIERS
|
2019-11-03 17:52:01 +00:00
|
|
|
if (get_mods()) {
|
2019-08-30 18:19:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
autoshift_on(keycode);
|
2019-11-03 17:52:01 +00:00
|
|
|
|
|
|
|
// 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
|
2019-08-30 18:19:03 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
autoshift_flush();
|
|
|
|
return true;
|
2017-09-17 05:33:28 +00:00
|
|
|
}
|
2019-08-30 18:19:03 +00:00
|
|
|
} else {
|
2017-09-17 05:33:28 +00:00
|
|
|
autoshift_flush();
|
|
|
|
}
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
return true;
|
2017-09-17 05:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|