qmk_settings: wrap one shot keys
This commit is contained in:
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "action_layer.h"
|
||||
#include "timer.h"
|
||||
#include "keycode_config.h"
|
||||
#include "qmk_settings.h"
|
||||
|
||||
extern keymap_config_t keymap_config;
|
||||
|
||||
@ -62,12 +63,8 @@ void clear_oneshot_locked_mods(void) {
|
||||
oneshot_locked_mods_changed_kb(oneshot_locked_mods);
|
||||
}
|
||||
}
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
static uint16_t oneshot_time = 0;
|
||||
bool has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; }
|
||||
# else
|
||||
bool has_oneshot_mods_timed_out(void) { return false; }
|
||||
# endif
|
||||
bool has_oneshot_mods_timed_out(void) { return QS_oneshot_timeout > 0 && TIMER_DIFF_16(timer_read(), oneshot_time) >= QS_oneshot_timeout; }
|
||||
#endif
|
||||
|
||||
/* oneshot layer */
|
||||
@ -92,26 +89,22 @@ enum {
|
||||
} swap_hands_oneshot = SHO_OFF;
|
||||
# endif
|
||||
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
static uint16_t oneshot_layer_time = 0;
|
||||
inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); }
|
||||
inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= QS_oneshot_timeout && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); }
|
||||
# ifdef SWAP_HANDS_ENABLE
|
||||
static uint16_t oneshot_swaphands_time = 0;
|
||||
inline bool has_oneshot_swaphands_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && (swap_hands_oneshot == SHO_ACTIVE); }
|
||||
inline bool has_oneshot_swaphands_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= QS_oneshot_timeout && (swap_hands_oneshot == SHO_ACTIVE); }
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef SWAP_HANDS_ENABLE
|
||||
|
||||
void set_oneshot_swaphands(void) {
|
||||
swap_hands_oneshot = SHO_PRESSED;
|
||||
swap_hands = true;
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_swaphands_time = timer_read();
|
||||
if (oneshot_layer_time != 0) {
|
||||
oneshot_layer_time = oneshot_swaphands_time;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
void release_oneshot_swaphands(void) {
|
||||
@ -135,9 +128,7 @@ void use_oneshot_swaphands(void) {
|
||||
void clear_oneshot_swaphands(void) {
|
||||
swap_hands_oneshot = SHO_OFF;
|
||||
swap_hands = false;
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_swaphands_time = 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
# endif
|
||||
@ -150,9 +141,7 @@ void set_oneshot_layer(uint8_t layer, uint8_t state) {
|
||||
if (!keymap_config.oneshot_disable) {
|
||||
oneshot_layer_data = layer << 3 | state;
|
||||
layer_on(layer);
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_layer_time = timer_read();
|
||||
# endif
|
||||
oneshot_layer_changed_kb(get_oneshot_layer());
|
||||
} else {
|
||||
layer_on(layer);
|
||||
@ -164,9 +153,7 @@ void set_oneshot_layer(uint8_t layer, uint8_t state) {
|
||||
*/
|
||||
void reset_oneshot_layer(void) {
|
||||
oneshot_layer_data = 0;
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_layer_time = 0;
|
||||
# endif
|
||||
oneshot_layer_changed_kb(get_oneshot_layer());
|
||||
}
|
||||
/** \brief Clear oneshot layer
|
||||
@ -231,12 +218,10 @@ void send_keyboard_report(void) {
|
||||
keyboard_report->mods |= macro_mods;
|
||||
#ifndef NO_ACTION_ONESHOT
|
||||
if (oneshot_mods) {
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
if (has_oneshot_mods_timed_out()) {
|
||||
if (QS_oneshot_timeout > 0 && has_oneshot_mods_timed_out()) {
|
||||
dprintf("Oneshot: timeout\n");
|
||||
clear_oneshot_mods();
|
||||
}
|
||||
# endif
|
||||
keyboard_report->mods |= oneshot_mods;
|
||||
if (has_anykey(keyboard_report)) {
|
||||
clear_oneshot_mods();
|
||||
@ -335,9 +320,7 @@ uint8_t get_oneshot_mods(void) { return oneshot_mods; }
|
||||
|
||||
void add_oneshot_mods(uint8_t mods) {
|
||||
if ((oneshot_mods & mods) != mods) {
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_time = timer_read();
|
||||
# endif
|
||||
oneshot_mods |= mods;
|
||||
oneshot_mods_changed_kb(mods);
|
||||
}
|
||||
@ -346,9 +329,7 @@ void add_oneshot_mods(uint8_t mods) {
|
||||
void del_oneshot_mods(uint8_t mods) {
|
||||
if (oneshot_mods & mods) {
|
||||
oneshot_mods &= ~mods;
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_time = oneshot_mods ? timer_read() : 0;
|
||||
# endif
|
||||
oneshot_mods_changed_kb(oneshot_mods);
|
||||
}
|
||||
}
|
||||
@ -360,9 +341,7 @@ void del_oneshot_mods(uint8_t mods) {
|
||||
void set_oneshot_mods(uint8_t mods) {
|
||||
if (!keymap_config.oneshot_disable) {
|
||||
if (oneshot_mods != mods) {
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_time = timer_read();
|
||||
# endif
|
||||
oneshot_mods = mods;
|
||||
oneshot_mods_changed_kb(mods);
|
||||
}
|
||||
@ -376,9 +355,7 @@ void set_oneshot_mods(uint8_t mods) {
|
||||
void clear_oneshot_mods(void) {
|
||||
if (oneshot_mods) {
|
||||
oneshot_mods = 0;
|
||||
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||
oneshot_time = 0;
|
||||
# endif
|
||||
oneshot_mods_changed_kb(oneshot_mods);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user