From fd7f66167c04fa19c70f891dfa8269522edbfd82 Mon Sep 17 00:00:00 2001 From: sheldonmlee Date: Tue, 3 Aug 2021 15:20:17 +0800 Subject: [PATCH] Implemented Callum's oneshot functionality. --- keymap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- rules.mk | 1 + 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/keymap.c b/keymap.c index c041303..714e041 100755 --- a/keymap.c +++ b/keymap.c @@ -17,6 +17,7 @@ along with this program. If not, see . */ #include QMK_KEYBOARD_H +#include "oneshot.h" enum tap_dance{ GUI_ALT @@ -30,6 +31,10 @@ enum keycodes { DL_COLE = SAFE_RANGE, DL_QWER, DL_GAME, + OS_GUI, + OS_CTRL, + OS_ALT, + OS_SHFT, }; 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_PIPE, OSM(MOD_LCTL), OSM(MOD_LALT), - OSM(MOD_LGUI), XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BSLS, _______, + _______, KC_PIPE, OS_CTRL, OS_ALT, OS_GUI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BSLS, _______, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| _______, _______, _______, 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, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| - _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, OSM(MOD_RGUI), OSM(MOD_RALT), - OSM(MOD_RCTL), XXXXXXX, _______, + _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, OS_GUI, OS_ALT, OS_CTRL, XXXXXXX, _______, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| _______, _______, 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 oled_rotation_t oled_init_user(oled_rotation_t rotation) { if (!is_master) { @@ -240,6 +276,22 @@ void oled_task_user(void) { } 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) { case DL_COLE: if (record->event.pressed) { @@ -266,4 +318,5 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } } + #endif // OLED_DRIVER_ENABLE diff --git a/rules.mk b/rules.mk index 31b8525..5a47a59 100755 --- a/rules.mk +++ b/rules.mk @@ -1,2 +1,3 @@ +SRC += oneshot.c OLED_DRIVER_ENABLE = yes TAP_DANCE_ENABLE = yes