Implemented Callum's oneshot functionality.

This commit is contained in:
sheldonmlee 2021-08-03 15:20:17 +08:00
parent 3b3e683da8
commit fd7f66167c
2 changed files with 58 additions and 4 deletions

View File

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
#include "oneshot.h"
enum tap_dance{ enum tap_dance{
GUI_ALT GUI_ALT
@ -30,6 +31,10 @@ enum keycodes {
DL_COLE = SAFE_RANGE, DL_COLE = SAFE_RANGE,
DL_QWER, DL_QWER,
DL_GAME, DL_GAME,
OS_GUI,
OS_CTRL,
OS_ALT,
OS_SHFT,
}; };
enum layers { enum layers {
@ -106,8 +111,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, KC_UNDS, KC_LBRC, KC_LCBR, KC_LPRN,KC_MINUS, KC_PLUS, KC_RPRN, KC_RCBR, KC_RBRC, KC_EQL, _______, _______, KC_UNDS, KC_LBRC, KC_LCBR, KC_LPRN,KC_MINUS, KC_PLUS, KC_RPRN, KC_RCBR, KC_RBRC, KC_EQL, _______,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, KC_PIPE, OSM(MOD_LCTL), OSM(MOD_LALT), _______, KC_PIPE, OS_CTRL, OS_ALT, OS_GUI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BSLS, _______,
OSM(MOD_LGUI), XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BSLS, _______,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
_______, _______, _______, MO(L3), _______, _______ _______, _______, _______, MO(L3), _______, _______
//`--------------------------' `--------------------------' //`--------------------------' `--------------------------'
@ -123,8 +127,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, KC_CAPS, KC_HOME, KC_PGUP, KC_PGDN, KC_END, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, XXXXXXX, KC_ENT, _______, KC_CAPS, KC_HOME, KC_PGUP, KC_PGDN, KC_END, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, XXXXXXX, KC_ENT,
//|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, OSM(MOD_RGUI), OSM(MOD_RALT), _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, OS_GUI, OS_ALT, OS_CTRL, XXXXXXX, _______,
OSM(MOD_RCTL), XXXXXXX, _______,
//|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
_______, _______, MO(L3), _______, _______, _______ _______, _______, MO(L3), _______, _______, _______
//`--------------------------' `--------------------------' //`--------------------------' `--------------------------'
@ -143,6 +146,39 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
) )
}; };
// Callum's one shot functionality
bool is_oneshot_cancel_key(uint16_t keycode) {
switch (keycode) {
case MO(L1):
case MO(L2):
return true;
default:
return false;
}
}
bool is_oneshot_ignored_key(uint16_t keycode) {
switch (keycode) {
case MO(L1):
case MO(L2):
case KC_LSFT:
case KC_RSFT:
case OS_SHFT:
case OS_CTRL:
case OS_ALT:
case OS_GUI:
return true;
default:
return false;
}
}
// one shot states
oneshot_state os_shft_state = os_up_unqueued;
oneshot_state os_ctrl_state = os_up_unqueued;
oneshot_state os_alt_state = os_up_unqueued;
oneshot_state os_cmd_state = os_up_unqueued;
#ifdef OLED_DRIVER_ENABLE #ifdef OLED_DRIVER_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) { oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!is_master) { if (!is_master) {
@ -240,6 +276,22 @@ void oled_task_user(void) {
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
update_oneshot(
&os_shft_state, KC_LSFT, OS_SHFT,
keycode, record
);
update_oneshot(
&os_ctrl_state, KC_LCTL, OS_CTRL,
keycode, record
);
update_oneshot(
&os_alt_state, KC_LALT, OS_ALT,
keycode, record
);
update_oneshot(
&os_cmd_state, KC_LGUI, OS_GUI,
keycode, record
);
switch (keycode) { switch (keycode) {
case DL_COLE: case DL_COLE:
if (record->event.pressed) { if (record->event.pressed) {
@ -266,4 +318,5 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true; return true;
} }
} }
#endif // OLED_DRIVER_ENABLE #endif // OLED_DRIVER_ENABLE

View File

@ -1,2 +1,3 @@
SRC += oneshot.c
OLED_DRIVER_ENABLE = yes OLED_DRIVER_ENABLE = yes
TAP_DANCE_ENABLE = yes TAP_DANCE_ENABLE = yes