Formatting
This commit is contained in:
@@ -13,7 +13,7 @@ AlwaysBreakAfterReturnType: None
|
|||||||
AlwaysBreakBeforeMultilineStrings: 'false'
|
AlwaysBreakBeforeMultilineStrings: 'false'
|
||||||
BinPackArguments: 'true'
|
BinPackArguments: 'true'
|
||||||
BinPackParameters: 'true'
|
BinPackParameters: 'true'
|
||||||
ColumnLimit: '1000'
|
ColumnLimit: '100'
|
||||||
IndentCaseLabels: 'true'
|
IndentCaseLabels: 'true'
|
||||||
IndentPPDirectives: AfterHash
|
IndentPPDirectives: AfterHash
|
||||||
IndentWidth: '4'
|
IndentWidth: '4'
|
||||||
|
|||||||
@@ -16,19 +16,19 @@
|
|||||||
#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 {
|
||||||
_TYPE = 0,
|
_TYPE = 0,
|
||||||
_GAME,
|
_GAME,
|
||||||
_SYM,
|
_SYM,
|
||||||
_NUM,
|
_NUM,
|
||||||
_NAV,
|
_NAV,
|
||||||
_FUN,
|
_FUN,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Aliases for readability
|
// Aliases for readability
|
||||||
@@ -91,10 +91,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|||||||
// _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
|
// _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
|
||||||
// ),
|
// ),
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void keyboard_pre_init_user(void) {
|
void keyboard_pre_init_user(void) {
|
||||||
setPinOutput(24);
|
setPinOutput(24);
|
||||||
writePinHigh(24);
|
writePinHigh(24);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -106,131 +107,120 @@ typedef enum {
|
|||||||
} oneshot_mode_t;
|
} oneshot_mode_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t time;
|
uint16_t time;
|
||||||
uint16_t mod;
|
uint16_t mod;
|
||||||
uint16_t trigger;
|
uint16_t trigger;
|
||||||
oneshot_mode_t mode;
|
oneshot_mode_t mode;
|
||||||
} oneshot_state_t;
|
} oneshot_state_t;
|
||||||
|
|
||||||
oneshot_state_t oneshot_state[4] = {
|
oneshot_state_t oneshot_state[4] = {{0, KC_LSFT, OS_LSFT, os_up_unqueued},
|
||||||
{ 0, KC_LSFT, OS_LSFT, os_up_unqueued },
|
{0, KC_LCTL, OS_LCTL, os_up_unqueued},
|
||||||
{ 0, KC_LCTL, OS_LCTL, os_up_unqueued },
|
{0, KC_LALT, OS_LALT, os_up_unqueued},
|
||||||
{ 0, KC_LALT, OS_LALT, os_up_unqueued },
|
{0, KC_LGUI, OS_LGUI, os_up_unqueued}};
|
||||||
{ 0, KC_LGUI, OS_LGUI, os_up_unqueued }
|
|
||||||
};
|
|
||||||
|
|
||||||
bool is_oneshot_ignored_key(uint16_t keycode) {
|
bool is_oneshot_ignored_key(uint16_t keycode) {
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case OS_LSFT:
|
case OS_LSFT:
|
||||||
case OS_LCTL:
|
case OS_LCTL:
|
||||||
case OS_LALT:
|
case OS_LALT:
|
||||||
case OS_LGUI:
|
case OS_LGUI:
|
||||||
case NAV:
|
case NAV:
|
||||||
case SYM:
|
case SYM:
|
||||||
case NUM:
|
case NUM:
|
||||||
case FUN:
|
case FUN:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_oneshot_cancel_key(uint16_t keycode) {
|
bool is_oneshot_cancel_key(uint16_t keycode) {
|
||||||
switch (keycode) {
|
return keycode == KC_NO;
|
||||||
case KC_NO:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on https://github.com/qmk/qmk_firmware/blob/user-keymaps-still-present/users/callum/oneshot.c
|
// Based on
|
||||||
void update_oneshot(
|
// https://github.com/qmk/qmk_firmware/blob/user-keymaps-still-present/users/callum/oneshot.c
|
||||||
oneshot_state_t *state,
|
void update_oneshot(oneshot_state_t *state, uint16_t keycode, keyrecord_t *record) {
|
||||||
uint16_t keycode,
|
if (keycode == state->trigger) {
|
||||||
keyrecord_t *record
|
if (record->event.pressed) {
|
||||||
) {
|
// Trigger keydown
|
||||||
if (keycode == state->trigger) {
|
switch (state->mode) {
|
||||||
if (record->event.pressed) {
|
case os_up_queued:
|
||||||
// Trigger keydown
|
state->mode = os_locked;
|
||||||
switch (state->mode) {
|
break;
|
||||||
case os_up_queued:
|
case os_up_unqueued:
|
||||||
state->mode = os_locked;
|
register_code(state->mod);
|
||||||
break;
|
state->time = timer_read();
|
||||||
case os_up_unqueued:
|
state->mode = os_down_unused;
|
||||||
register_code(state->mod);
|
break;
|
||||||
state->time = timer_read();
|
case os_locked:
|
||||||
state->mode = os_down_unused;
|
state->mode = os_down_used;
|
||||||
break;
|
break;
|
||||||
case os_locked:
|
default:
|
||||||
state->mode = os_down_used;
|
state->mode = os_down_unused;
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
state->mode = os_down_unused;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Trigger keyup
|
|
||||||
switch (state->mode) {
|
|
||||||
case os_down_unused:
|
|
||||||
// If we didn't use the mod while trigger was held, queue it.
|
|
||||||
if (timer_elapsed(state->time) < 1000) {
|
|
||||||
state->mode = os_up_queued;
|
|
||||||
} else {
|
} else {
|
||||||
state->mode = os_up_unqueued;
|
// Trigger keyup
|
||||||
unregister_code(state->mod);
|
switch (state->mode) {
|
||||||
|
case os_down_unused:
|
||||||
|
// If we didn't use the mod while trigger was held, queue it.
|
||||||
|
if (timer_elapsed(state->time) < 1000) {
|
||||||
|
state->mode = os_up_queued;
|
||||||
|
} else {
|
||||||
|
state->mode = os_up_unqueued;
|
||||||
|
unregister_code(state->mod);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case os_down_used:
|
||||||
|
// If we did use the mod while trigger was held, unregister it.
|
||||||
|
state->mode = os_up_unqueued;
|
||||||
|
unregister_code(state->mod);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case os_down_used:
|
|
||||||
// If we did use the mod while trigger was held, unregister it.
|
|
||||||
state->mode = os_up_unqueued;
|
|
||||||
unregister_code(state->mod);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (record->event.pressed) {
|
|
||||||
if (is_oneshot_cancel_key(keycode) && state->mode != os_up_unqueued) {
|
|
||||||
// Cancel oneshot on designated cancel keydown.
|
|
||||||
state->mode = os_up_unqueued;
|
|
||||||
unregister_code(state->mod);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!is_oneshot_ignored_key(keycode)) {
|
if (record->event.pressed) {
|
||||||
// On non-ignored keyup, consider the oneshot used.
|
if (is_oneshot_cancel_key(keycode) && state->mode != os_up_unqueued) {
|
||||||
switch (state->mode) {
|
// Cancel oneshot on designated cancel keydown.
|
||||||
case os_down_unused:
|
state->mode = os_up_unqueued;
|
||||||
state->mode = os_down_used;
|
unregister_code(state->mod);
|
||||||
break;
|
}
|
||||||
case os_up_queued:
|
} else {
|
||||||
state->mode = os_up_unqueued;
|
if (!is_oneshot_ignored_key(keycode)) {
|
||||||
unregister_code(state->mod);
|
// On non-ignored keyup, consider the oneshot used.
|
||||||
break;
|
switch (state->mode) {
|
||||||
default:
|
case os_down_unused:
|
||||||
break;
|
state->mode = os_down_used;
|
||||||
|
break;
|
||||||
|
case os_up_queued:
|
||||||
|
state->mode = os_up_unqueued;
|
||||||
|
unregister_code(state->mod);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
update_oneshot(&oneshot_state[0], keycode, record);
|
update_oneshot(&oneshot_state[0], keycode, record);
|
||||||
update_oneshot(&oneshot_state[1], keycode, record);
|
update_oneshot(&oneshot_state[1], keycode, record);
|
||||||
update_oneshot(&oneshot_state[2], keycode, record);
|
update_oneshot(&oneshot_state[2], keycode, record);
|
||||||
update_oneshot(&oneshot_state[3], keycode, record);
|
update_oneshot(&oneshot_state[3], keycode, record);
|
||||||
|
|
||||||
if (oneshot_state[0].mode == os_locked && keycode == KC_SPACE) {
|
if (oneshot_state[0].mode == os_locked && keycode == KC_SPACE) {
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
register_code(KC_MINUS);
|
register_code(KC_MINUS);
|
||||||
} else {
|
} else {
|
||||||
unregister_code(KC_MINUS);
|
unregister_code(KC_MINUS);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user