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:
@@ -13,23 +13,23 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "keycodes.h"
|
#include "action.h"
|
||||||
#include QMK_KEYBOARD_H
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
enum keycodes {
|
enum keycodes {
|
||||||
OS_LSFT = SAFE_RANGE,
|
OS_LSFT = SAFE_RANGE,
|
||||||
OS_LCTL,
|
OS_LCTL,
|
||||||
OS_LALT,
|
OS_LALT,
|
||||||
OS_LGUI,
|
OS_LGUI,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum layers {
|
enum layers {
|
||||||
_COLEMAK_DH = 0,
|
_COLEMAK_DH = 0,
|
||||||
_GAME,
|
_GAME,
|
||||||
_SYM,
|
_SYM,
|
||||||
_NUM,
|
_NUM,
|
||||||
_NAV,
|
_NAV,
|
||||||
_FUN,
|
_FUN,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Aliases for readability
|
// Aliases for readability
|
||||||
@@ -204,6 +204,7 @@ typedef enum {
|
|||||||
os_up_queued,
|
os_up_queued,
|
||||||
os_down_unused,
|
os_down_unused,
|
||||||
os_down_used,
|
os_down_used,
|
||||||
|
os_locked
|
||||||
} oneshot_state_t;
|
} oneshot_state_t;
|
||||||
|
|
||||||
oneshot_state_t oneshot_state[4] = {0};
|
oneshot_state_t oneshot_state[4] = {0};
|
||||||
@@ -227,70 +228,84 @@ bool is_oneshot_ignored_key(uint16_t keycode) {
|
|||||||
|
|
||||||
bool is_oneshot_cancel_key(uint16_t keycode) {
|
bool is_oneshot_cancel_key(uint16_t keycode) {
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case NAV:
|
// case NAV:
|
||||||
case SYM:
|
// case SYM:
|
||||||
case NUM:
|
// case NUM:
|
||||||
case FUN:
|
// case FUN:
|
||||||
|
// return true;
|
||||||
|
case KC_NO:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
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(
|
void update_oneshot(
|
||||||
oneshot_state_t *state,
|
oneshot_state_t *state,
|
||||||
uint16_t mod,
|
uint16_t mod,
|
||||||
uint16_t trigger,
|
uint16_t trigger,
|
||||||
uint16_t keycode,
|
uint16_t keycode,
|
||||||
keyrecord_t *record
|
keyrecord_t *record
|
||||||
) {
|
) {
|
||||||
if (keycode == trigger) {
|
if (keycode == trigger) {
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
// Trigger keydown
|
// Trigger keydown
|
||||||
if (*state == os_up_unqueued) {
|
switch (*state) {
|
||||||
register_code(mod);
|
case os_up_queued:
|
||||||
}
|
*state = os_locked;
|
||||||
*state = os_down_unused;
|
break;
|
||||||
} else {
|
case os_up_unqueued:
|
||||||
// Trigger keyup
|
register_code(mod);
|
||||||
switch (*state) {
|
*state = os_down_unused;
|
||||||
case os_down_unused:
|
break;
|
||||||
// If we didn't use the mod while trigger was held, queue it.
|
case os_locked:
|
||||||
*state = os_up_queued;
|
*state = os_down_used;
|
||||||
break;
|
break;
|
||||||
case os_down_used:
|
default:
|
||||||
// If we did use the mod while trigger was held, unregister it.
|
*state = os_down_unused;
|
||||||
*state = os_up_unqueued;
|
break;
|
||||||
unregister_code(mod);
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (record->event.pressed) {
|
// Trigger keyup
|
||||||
if (is_oneshot_cancel_key(keycode) && *state != os_up_unqueued) {
|
switch (*state) {
|
||||||
// Cancel oneshot on designated cancel keydown.
|
case os_down_unused:
|
||||||
*state = os_up_unqueued;
|
// If we didn't use the mod while trigger was held, queue it.
|
||||||
unregister_code(mod);
|
*state = os_up_queued;
|
||||||
}
|
break;
|
||||||
} else {
|
case os_down_used:
|
||||||
if (!is_oneshot_ignored_key(keycode)) {
|
// If we did use the mod while trigger was held, unregister it.
|
||||||
// On non-ignored keyup, consider the oneshot used.
|
*state = os_up_unqueued;
|
||||||
switch (*state) {
|
unregister_code(mod);
|
||||||
case os_down_unused:
|
break;
|
||||||
*state = os_down_used;
|
default:
|
||||||
break;
|
break;
|
||||||
case os_up_queued:
|
}
|
||||||
*state = os_up_unqueued;
|
|
||||||
unregister_code(mod);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (record->event.pressed) {
|
||||||
|
if (is_oneshot_cancel_key(keycode) && *state != os_up_unqueued) {
|
||||||
|
// Cancel oneshot on designated cancel keydown.
|
||||||
|
*state = os_up_unqueued;
|
||||||
|
unregister_code(mod);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!is_oneshot_ignored_key(keycode)) {
|
||||||
|
// On non-ignored keyup, consider the oneshot used.
|
||||||
|
switch (*state) {
|
||||||
|
case os_down_unused:
|
||||||
|
*state = os_down_used;
|
||||||
|
break;
|
||||||
|
case os_up_queued:
|
||||||
|
*state = os_up_unqueued;
|
||||||
|
unregister_code(mod);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
@@ -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[2], mods[2], OS_LALT, keycode, record);
|
||||||
update_oneshot(&oneshot_state[3], mods[3], OS_LGUI, 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user