2015-04-09 22:32:04 +06:00
|
|
|
/*
|
|
|
|
Copyright 2013 Jun Wako <wakojun@gmail.com>
|
|
|
|
|
|
|
|
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 "host.h"
|
|
|
|
#include "report.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "action_util.h"
|
2016-05-06 07:41:37 +06:00
|
|
|
#include "action_layer.h"
|
2015-04-09 22:32:04 +06:00
|
|
|
#include "timer.h"
|
2016-09-07 10:19:01 +06:00
|
|
|
#include "keycode_config.h"
|
2021-12-15 00:40:18 +06:00
|
|
|
#include <string.h>
|
2016-09-07 10:19:01 +06:00
|
|
|
|
|
|
|
extern keymap_config_t keymap_config;
|
|
|
|
|
2022-01-25 03:22:20 +06:00
|
|
|
static uint8_t real_mods = 0;
|
|
|
|
static uint8_t weak_mods = 0;
|
2021-07-13 23:13:51 +06:00
|
|
|
#ifdef KEY_OVERRIDE_ENABLE
|
|
|
|
static uint8_t weak_override_mods = 0;
|
|
|
|
static uint8_t suppressed_mods = 0;
|
|
|
|
#endif
|
2015-04-09 22:32:04 +06:00
|
|
|
|
|
|
|
// TODO: pointer variable is not needed
|
2019-08-31 00:19:03 +06:00
|
|
|
// report_keyboard_t keyboard_report = {};
|
2015-04-09 22:32:04 +06:00
|
|
|
report_keyboard_t *keyboard_report = &(report_keyboard_t){};
|
|
|
|
|
2017-06-18 17:39:58 +06:00
|
|
|
extern inline void add_key(uint8_t key);
|
|
|
|
extern inline void del_key(uint8_t key);
|
|
|
|
extern inline void clear_keys(void);
|
|
|
|
|
2015-04-09 22:32:04 +06:00
|
|
|
#ifndef NO_ACTION_ONESHOT
|
2019-08-31 00:19:03 +06:00
|
|
|
static uint8_t oneshot_mods = 0;
|
2019-02-06 00:19:56 +06:00
|
|
|
static uint8_t oneshot_locked_mods = 0;
|
2022-02-13 00:29:31 +06:00
|
|
|
uint8_t get_oneshot_locked_mods(void) {
|
|
|
|
return oneshot_locked_mods;
|
|
|
|
}
|
2023-04-03 11:38:44 +06:00
|
|
|
void add_oneshot_locked_mods(uint8_t mods) {
|
|
|
|
if ((oneshot_locked_mods & mods) != mods) {
|
|
|
|
oneshot_locked_mods |= mods;
|
|
|
|
oneshot_locked_mods_changed_kb(oneshot_locked_mods);
|
|
|
|
}
|
|
|
|
}
|
2022-02-13 00:29:31 +06:00
|
|
|
void set_oneshot_locked_mods(uint8_t mods) {
|
2019-02-06 00:19:56 +06:00
|
|
|
if (mods != oneshot_locked_mods) {
|
|
|
|
oneshot_locked_mods = mods;
|
|
|
|
oneshot_locked_mods_changed_kb(oneshot_locked_mods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void clear_oneshot_locked_mods(void) {
|
|
|
|
if (oneshot_locked_mods) {
|
|
|
|
oneshot_locked_mods = 0;
|
|
|
|
oneshot_locked_mods_changed_kb(oneshot_locked_mods);
|
|
|
|
}
|
|
|
|
}
|
2023-04-03 11:38:44 +06:00
|
|
|
void del_oneshot_locked_mods(uint8_t mods) {
|
|
|
|
if (oneshot_locked_mods & mods) {
|
|
|
|
oneshot_locked_mods &= ~mods;
|
|
|
|
oneshot_locked_mods_changed_kb(oneshot_locked_mods);
|
|
|
|
}
|
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
2019-01-26 02:09:53 +06:00
|
|
|
static uint16_t oneshot_time = 0;
|
2022-02-13 00:29:31 +06:00
|
|
|
bool has_oneshot_mods_timed_out(void) {
|
|
|
|
return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT;
|
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
# else
|
2022-02-13 00:29:31 +06:00
|
|
|
bool has_oneshot_mods_timed_out(void) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
# endif
|
2015-04-09 22:32:04 +06:00
|
|
|
#endif
|
|
|
|
|
2016-05-06 07:41:37 +06:00
|
|
|
/* oneshot layer */
|
|
|
|
#ifndef NO_ACTION_ONESHOT
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief oneshot_layer_data bits
|
|
|
|
* LLLL LSSS
|
|
|
|
* where:
|
|
|
|
* L => are layer bits
|
|
|
|
* S => oneshot state bits
|
|
|
|
*/
|
2016-05-06 07:41:37 +06:00
|
|
|
static int8_t oneshot_layer_data = 0;
|
|
|
|
|
2022-02-13 00:29:31 +06:00
|
|
|
inline uint8_t get_oneshot_layer(void) {
|
|
|
|
return oneshot_layer_data >> 3;
|
|
|
|
}
|
|
|
|
inline uint8_t get_oneshot_layer_state(void) {
|
|
|
|
return oneshot_layer_data & 0b111;
|
|
|
|
}
|
2016-05-06 07:41:37 +06:00
|
|
|
|
2020-05-14 03:36:55 +06:00
|
|
|
# ifdef SWAP_HANDS_ENABLE
|
|
|
|
enum {
|
|
|
|
SHO_OFF,
|
2022-02-13 00:29:31 +06:00
|
|
|
SHO_ACTIVE, // Swap hands button was pressed, and we didn't send any swapped keys yet
|
|
|
|
SHO_PRESSED, // Swap hands button is currently pressed
|
|
|
|
SHO_USED, // Swap hands button is still pressed, and we already sent swapped keys
|
2020-05-14 03:36:55 +06:00
|
|
|
} swap_hands_oneshot = SHO_OFF;
|
|
|
|
# endif
|
|
|
|
|
2019-08-31 00:19:03 +06:00
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
2019-01-26 02:09:53 +06:00
|
|
|
static uint16_t oneshot_layer_time = 0;
|
2023-01-20 22:21:17 +06:00
|
|
|
inline bool has_oneshot_layer_timed_out(void) {
|
2022-02-13 00:29:31 +06:00
|
|
|
return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED);
|
|
|
|
}
|
2020-05-14 03:36:55 +06:00
|
|
|
# ifdef SWAP_HANDS_ENABLE
|
|
|
|
static uint16_t oneshot_swaphands_time = 0;
|
2023-01-20 22:21:17 +06:00
|
|
|
inline bool has_oneshot_swaphands_timed_out(void) {
|
2022-02-13 00:29:31 +06:00
|
|
|
return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && (swap_hands_oneshot == SHO_ACTIVE);
|
|
|
|
}
|
2020-05-14 03:36:55 +06:00
|
|
|
# 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) {
|
|
|
|
if (swap_hands_oneshot == SHO_PRESSED) {
|
|
|
|
swap_hands_oneshot = SHO_ACTIVE;
|
|
|
|
}
|
|
|
|
if (swap_hands_oneshot == SHO_USED) {
|
|
|
|
clear_oneshot_swaphands();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void use_oneshot_swaphands(void) {
|
|
|
|
if (swap_hands_oneshot == SHO_PRESSED) {
|
|
|
|
swap_hands_oneshot = SHO_USED;
|
|
|
|
}
|
|
|
|
if (swap_hands_oneshot == SHO_ACTIVE) {
|
|
|
|
clear_oneshot_swaphands();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-08-31 00:19:03 +06:00
|
|
|
# endif
|
2016-05-06 07:41:37 +06:00
|
|
|
|
2019-08-31 00:19:03 +06:00
|
|
|
/** \brief Set oneshot layer
|
2018-03-22 12:50:38 +06:00
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2019-08-31 00:19:03 +06:00
|
|
|
void set_oneshot_layer(uint8_t layer, uint8_t state) {
|
2022-03-14 07:11:42 +06:00
|
|
|
if (keymap_config.oneshot_enable) {
|
2021-03-01 22:57:02 +06:00
|
|
|
oneshot_layer_data = layer << 3 | state;
|
|
|
|
layer_on(layer);
|
2019-08-31 00:19:03 +06:00
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
2021-03-01 22:57:02 +06:00
|
|
|
oneshot_layer_time = timer_read();
|
2019-08-31 00:19:03 +06:00
|
|
|
# endif
|
2021-03-01 22:57:02 +06:00
|
|
|
oneshot_layer_changed_kb(get_oneshot_layer());
|
|
|
|
} else {
|
|
|
|
layer_on(layer);
|
|
|
|
}
|
2016-05-06 07:41:37 +06:00
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
/** \brief Reset oneshot layer
|
2018-03-22 12:50:38 +06:00
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2016-05-06 07:41:37 +06:00
|
|
|
void reset_oneshot_layer(void) {
|
|
|
|
oneshot_layer_data = 0;
|
2019-08-31 00:19:03 +06:00
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
2016-05-06 07:41:37 +06:00
|
|
|
oneshot_layer_time = 0;
|
2019-08-31 00:19:03 +06:00
|
|
|
# endif
|
2019-02-06 00:19:56 +06:00
|
|
|
oneshot_layer_changed_kb(get_oneshot_layer());
|
2016-05-06 07:41:37 +06:00
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
/** \brief Clear oneshot layer
|
2018-03-22 12:50:38 +06:00
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2019-08-31 00:19:03 +06:00
|
|
|
void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
|
2016-05-06 07:41:37 +06:00
|
|
|
uint8_t start_state = oneshot_layer_data;
|
|
|
|
oneshot_layer_data &= ~state;
|
2022-03-14 07:11:42 +06:00
|
|
|
if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) && keymap_config.oneshot_enable) {
|
2016-05-06 07:41:37 +06:00
|
|
|
layer_off(get_oneshot_layer());
|
2019-02-06 00:19:56 +06:00
|
|
|
reset_oneshot_layer();
|
2016-05-06 07:41:37 +06:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief Is oneshot layer active
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
bool is_oneshot_layer_active(void) {
|
|
|
|
return get_oneshot_layer_state();
|
|
|
|
}
|
2021-03-01 22:57:02 +06:00
|
|
|
|
|
|
|
/** \brief set oneshot
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
|
|
|
void oneshot_set(bool active) {
|
2022-03-14 07:11:42 +06:00
|
|
|
if (keymap_config.oneshot_enable != active) {
|
|
|
|
keymap_config.oneshot_enable = active;
|
2021-03-01 22:57:02 +06:00
|
|
|
eeconfig_update_keymap(keymap_config.raw);
|
2021-11-01 22:41:24 +06:00
|
|
|
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
|
2021-03-01 22:57:02 +06:00
|
|
|
dprintf("Oneshot: active: %d\n", active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief toggle oneshot
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void oneshot_toggle(void) {
|
2022-03-14 07:11:42 +06:00
|
|
|
oneshot_set(!keymap_config.oneshot_enable);
|
2022-02-13 00:29:31 +06:00
|
|
|
}
|
2021-03-01 22:57:02 +06:00
|
|
|
|
|
|
|
/** \brief enable oneshot
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void oneshot_enable(void) {
|
|
|
|
oneshot_set(true);
|
|
|
|
}
|
2021-03-01 22:57:02 +06:00
|
|
|
|
|
|
|
/** \brief disable oneshot
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void oneshot_disable(void) {
|
|
|
|
oneshot_set(false);
|
|
|
|
}
|
2021-03-01 22:57:02 +06:00
|
|
|
|
2022-02-13 00:29:31 +06:00
|
|
|
bool is_oneshot_enabled(void) {
|
2022-03-14 07:11:42 +06:00
|
|
|
return keymap_config.oneshot_enable;
|
2022-02-13 00:29:31 +06:00
|
|
|
}
|
2021-03-01 22:57:02 +06:00
|
|
|
|
2016-05-06 07:41:37 +06:00
|
|
|
#endif
|
2015-04-09 22:32:04 +06:00
|
|
|
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief Send keyboard report
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2015-04-09 22:32:04 +06:00
|
|
|
void send_keyboard_report(void) {
|
2019-08-31 00:19:03 +06:00
|
|
|
keyboard_report->mods = real_mods;
|
2015-04-09 22:32:04 +06:00
|
|
|
keyboard_report->mods |= weak_mods;
|
2021-07-13 23:13:51 +06:00
|
|
|
|
2015-04-09 22:32:04 +06:00
|
|
|
#ifndef NO_ACTION_ONESHOT
|
|
|
|
if (oneshot_mods) {
|
2019-08-31 00:19:03 +06:00
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
2016-05-06 07:41:37 +06:00
|
|
|
if (has_oneshot_mods_timed_out()) {
|
2015-04-09 22:32:04 +06:00
|
|
|
dprintf("Oneshot: timeout\n");
|
|
|
|
clear_oneshot_mods();
|
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
# endif
|
2015-04-09 22:32:04 +06:00
|
|
|
keyboard_report->mods |= oneshot_mods;
|
2017-06-17 18:19:15 +06:00
|
|
|
if (has_anykey(keyboard_report)) {
|
2015-04-09 22:32:04 +06:00
|
|
|
clear_oneshot_mods();
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 07:41:37 +06:00
|
|
|
|
2015-04-09 22:32:04 +06:00
|
|
|
#endif
|
2021-07-13 23:13:51 +06:00
|
|
|
|
|
|
|
#ifdef KEY_OVERRIDE_ENABLE
|
|
|
|
// These need to be last to be able to properly control key overrides
|
|
|
|
keyboard_report->mods &= ~suppressed_mods;
|
|
|
|
keyboard_report->mods |= weak_override_mods;
|
|
|
|
#endif
|
|
|
|
|
2022-03-03 23:24:04 +06:00
|
|
|
#ifdef PROTOCOL_VUSB
|
|
|
|
host_keyboard_send(keyboard_report);
|
|
|
|
#else
|
2021-12-15 00:40:18 +06:00
|
|
|
static report_keyboard_t last_report;
|
|
|
|
|
|
|
|
/* Only send the report if there are changes to propagate to the host. */
|
|
|
|
if (memcmp(keyboard_report, &last_report, sizeof(report_keyboard_t)) != 0) {
|
|
|
|
memcpy(&last_report, keyboard_report, sizeof(report_keyboard_t));
|
|
|
|
host_keyboard_send(keyboard_report);
|
|
|
|
}
|
2022-03-03 23:24:04 +06:00
|
|
|
#endif
|
2015-04-09 22:32:04 +06:00
|
|
|
}
|
|
|
|
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief Get mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
uint8_t get_mods(void) {
|
|
|
|
return real_mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief add mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void add_mods(uint8_t mods) {
|
|
|
|
real_mods |= mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief del mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void del_mods(uint8_t mods) {
|
|
|
|
real_mods &= ~mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief set mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void set_mods(uint8_t mods) {
|
|
|
|
real_mods = mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief clear mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void clear_mods(void) {
|
|
|
|
real_mods = 0;
|
|
|
|
}
|
2015-04-09 22:32:04 +06:00
|
|
|
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief get weak mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
uint8_t get_weak_mods(void) {
|
|
|
|
return weak_mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief add weak mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void add_weak_mods(uint8_t mods) {
|
|
|
|
weak_mods |= mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief del weak mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void del_weak_mods(uint8_t mods) {
|
|
|
|
weak_mods &= ~mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief set weak mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void set_weak_mods(uint8_t mods) {
|
|
|
|
weak_mods = mods;
|
|
|
|
}
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief clear weak mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void clear_weak_mods(void) {
|
|
|
|
weak_mods = 0;
|
|
|
|
}
|
2015-04-09 22:32:04 +06:00
|
|
|
|
2021-07-13 23:13:51 +06:00
|
|
|
#ifdef KEY_OVERRIDE_ENABLE
|
|
|
|
/** \brief set weak mods used by key overrides. DO not call this manually
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void set_weak_override_mods(uint8_t mods) {
|
|
|
|
weak_override_mods = mods;
|
|
|
|
}
|
2021-07-13 23:13:51 +06:00
|
|
|
/** \brief clear weak mods used by key overrides. DO not call this manually
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void clear_weak_override_mods(void) {
|
|
|
|
weak_override_mods = 0;
|
|
|
|
}
|
2021-07-13 23:13:51 +06:00
|
|
|
|
|
|
|
/** \brief set suppressed mods used by key overrides. DO not call this manually
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void set_suppressed_override_mods(uint8_t mods) {
|
|
|
|
suppressed_mods = mods;
|
|
|
|
}
|
2021-07-13 23:13:51 +06:00
|
|
|
/** \brief clear suppressed mods used by key overrides. DO not call this manually
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
void clear_suppressed_override_mods(void) {
|
|
|
|
suppressed_mods = 0;
|
|
|
|
}
|
2021-07-13 23:13:51 +06:00
|
|
|
#endif
|
|
|
|
|
2015-04-09 22:32:04 +06:00
|
|
|
#ifndef NO_ACTION_ONESHOT
|
2020-11-29 02:02:18 +06:00
|
|
|
/** \brief get oneshot mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
uint8_t get_oneshot_mods(void) {
|
|
|
|
return oneshot_mods;
|
|
|
|
}
|
2020-11-29 02:02:18 +06:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief set oneshot mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2019-02-06 00:19:56 +06:00
|
|
|
void set_oneshot_mods(uint8_t mods) {
|
2022-03-14 07:11:42 +06:00
|
|
|
if (keymap_config.oneshot_enable) {
|
2021-03-01 22:57:02 +06:00
|
|
|
if (oneshot_mods != mods) {
|
2019-08-31 00:19:03 +06:00
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
2021-03-01 22:57:02 +06:00
|
|
|
oneshot_time = timer_read();
|
2019-08-31 00:19:03 +06:00
|
|
|
# endif
|
2021-03-01 22:57:02 +06:00
|
|
|
oneshot_mods = mods;
|
|
|
|
oneshot_mods_changed_kb(mods);
|
|
|
|
}
|
2019-08-31 00:19:03 +06:00
|
|
|
}
|
2015-04-09 22:32:04 +06:00
|
|
|
}
|
2021-03-01 22:57:02 +06:00
|
|
|
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief clear oneshot mods
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
|
|
|
*/
|
2019-02-06 00:19:56 +06:00
|
|
|
void clear_oneshot_mods(void) {
|
2019-08-31 00:19:03 +06:00
|
|
|
if (oneshot_mods) {
|
|
|
|
oneshot_mods = 0;
|
|
|
|
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
|
|
|
oneshot_time = 0;
|
|
|
|
# endif
|
|
|
|
oneshot_mods_changed_kb(oneshot_mods);
|
|
|
|
}
|
2015-04-09 22:32:04 +06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-02-06 00:19:56 +06:00
|
|
|
/** \brief Called when the one shot modifiers have been changed.
|
2019-08-31 00:19:03 +06:00
|
|
|
*
|
|
|
|
* \param mods Contains the active modifiers active after the change.
|
2019-02-06 00:19:56 +06:00
|
|
|
*/
|
2019-08-31 00:19:03 +06:00
|
|
|
__attribute__((weak)) void oneshot_locked_mods_changed_user(uint8_t mods) {}
|
2019-02-06 00:19:56 +06:00
|
|
|
|
|
|
|
/** \brief Called when the locked one shot modifiers have been changed.
|
2019-08-31 00:19:03 +06:00
|
|
|
*
|
|
|
|
* \param mods Contains the active modifiers active after the change.
|
2019-02-06 00:19:56 +06:00
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
__attribute__((weak)) void oneshot_locked_mods_changed_kb(uint8_t mods) {
|
|
|
|
oneshot_locked_mods_changed_user(mods);
|
|
|
|
}
|
2019-02-06 00:19:56 +06:00
|
|
|
|
|
|
|
/** \brief Called when the one shot modifiers have been changed.
|
2019-08-31 00:19:03 +06:00
|
|
|
*
|
2019-02-06 00:19:56 +06:00
|
|
|
* \param mods Contains the active modifiers active after the change.
|
|
|
|
*/
|
2019-08-31 00:19:03 +06:00
|
|
|
__attribute__((weak)) void oneshot_mods_changed_user(uint8_t mods) {}
|
2019-02-06 00:19:56 +06:00
|
|
|
|
|
|
|
/** \brief Called when the one shot modifiers have been changed.
|
2019-08-31 00:19:03 +06:00
|
|
|
*
|
2019-02-06 00:19:56 +06:00
|
|
|
* \param mods Contains the active modifiers active after the change.
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
__attribute__((weak)) void oneshot_mods_changed_kb(uint8_t mods) {
|
|
|
|
oneshot_mods_changed_user(mods);
|
|
|
|
}
|
2019-02-06 00:19:56 +06:00
|
|
|
|
|
|
|
/** \brief Called when the one shot layers have been changed.
|
2019-08-31 00:19:03 +06:00
|
|
|
*
|
|
|
|
* \param layer Contains the layer that is toggled on, or zero when toggled off.
|
2019-02-06 00:19:56 +06:00
|
|
|
*/
|
2019-08-31 00:19:03 +06:00
|
|
|
__attribute__((weak)) void oneshot_layer_changed_user(uint8_t layer) {}
|
2019-02-06 00:19:56 +06:00
|
|
|
|
|
|
|
/** \brief Called when the one shot layers have been changed.
|
2019-08-31 00:19:03 +06:00
|
|
|
*
|
2019-02-06 00:19:56 +06:00
|
|
|
* \param layer Contains the layer that is toggled on, or zero when toggled off.
|
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
__attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) {
|
|
|
|
oneshot_layer_changed_user(layer);
|
|
|
|
}
|
2019-02-06 00:19:56 +06:00
|
|
|
|
2018-03-22 12:50:38 +06:00
|
|
|
/** \brief inspect keyboard state
|
|
|
|
*
|
|
|
|
* FIXME: needs doc
|
2015-04-09 22:32:04 +06:00
|
|
|
*/
|
2022-02-13 00:29:31 +06:00
|
|
|
uint8_t has_anymod(void) {
|
|
|
|
return bitpop(real_mods);
|
|
|
|
}
|