Further OSM improvements:

locking support (double-tap to lock, tap to unlock or use KC_NO)
 includes word-lock (shift-lock: ' ' -> _)
This commit is contained in:
bluepython508
2024-03-05 22:05:50 +00:00
parent c65beba3bb
commit 373ccbec40

View File

@@ -13,7 +13,7 @@
* 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 "keycodes.h"
#include "action.h"
#include QMK_KEYBOARD_H
enum keycodes {
@@ -204,6 +204,7 @@ typedef enum {
os_up_queued,
os_down_unused,
os_down_used,
os_locked
} oneshot_state_t;
oneshot_state_t oneshot_state[4] = {0};
@@ -227,16 +228,19 @@ bool is_oneshot_ignored_key(uint16_t keycode) {
bool is_oneshot_cancel_key(uint16_t keycode) {
switch (keycode) {
case NAV:
case SYM:
case NUM:
case FUN:
// case NAV:
// case SYM:
// case NUM:
// case FUN:
// return true;
case KC_NO:
return true;
default:
return false;
}
}
// From https://github.com/qmk/qmk_firmware/blob/user-keymaps-still-present/users/callum/oneshot.c
// Based on https://github.com/qmk/qmk_firmware/blob/user-keymaps-still-present/users/callum/oneshot.c
void update_oneshot(
oneshot_state_t *state,
uint16_t mod,
@@ -247,10 +251,21 @@ void update_oneshot(
if (keycode == trigger) {
if (record->event.pressed) {
// Trigger keydown
if (*state == os_up_unqueued) {
switch (*state) {
case os_up_queued:
*state = os_locked;
break;
case os_up_unqueued:
register_code(mod);
}
*state = os_down_unused;
break;
case os_locked:
*state = os_down_used;
break;
default:
*state = os_down_unused;
break;
}
} else {
// Trigger keyup
switch (*state) {
@@ -299,6 +314,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
update_oneshot(&oneshot_state[2], mods[2], OS_LALT, keycode, record);
update_oneshot(&oneshot_state[3], mods[3], OS_LGUI, keycode, record);
if (oneshot_state[0] == os_locked && keycode == KC_SPACE) {
if (record->event.pressed) {
register_code(KC_MINUS);
} else {
unregister_code(KC_MINUS);
}
return false;
}
return true;
}