summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sandiford <ms@mcdev.com.au>2018-04-27 05:40:03 +0930
committerJack Humbert <jack.humb@gmail.com>2018-04-26 16:10:03 -0400
commit66e40529aa9271c76d207fb8190ad76bb5cf8d6b (patch)
tree6c4a1e185cc268b2c16236339a23b4ea8fb05b49
parent80ccbc7b547d07236f302af830be75e646b7848f (diff)
Change handling of adjust layer to make it more LT(...) friendly. (#1625)
* Change handling of adjust layer to make it more LT(...) friendly. * Update based on feedback from drashna. * Change handling of adjust layer to make it more LT(...) friendly. This reworks handling to make it a little more friendly to include in keymaps.
-rw-r--r--keyboards/planck/keymaps/default/keymap.c29
-rw-r--r--quantum/quantum.c12
-rw-r--r--quantum/quantum.h1
3 files changed, 15 insertions, 27 deletions
diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c
index 04fc33640d..b13557eee2 100644
--- a/keyboards/planck/keymaps/default/keymap.c
+++ b/keyboards/planck/keymaps/default/keymap.c
@@ -34,12 +34,13 @@ enum planck_keycodes {
COLEMAK,
DVORAK,
PLOVER,
- LOWER,
- RAISE,
BACKLIT,
EXT_PLV
};
+#define LOWER MO(_LOWER)
+#define RAISE MO(_RAISE)
+
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Qwerty
@@ -177,6 +178,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
#endif
+uint32_t layer_state_set_user(uint32_t state) {
+ return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
+}
+
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QWERTY:
@@ -198,26 +203,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
return false;
break;
- case LOWER:
- if (record->event.pressed) {
- layer_on(_LOWER);
- update_tri_layer(_LOWER, _RAISE, _ADJUST);
- } else {
- layer_off(_LOWER);
- update_tri_layer(_LOWER, _RAISE, _ADJUST);
- }
- return false;
- break;
- case RAISE:
- if (record->event.pressed) {
- layer_on(_RAISE);
- update_tri_layer(_LOWER, _RAISE, _ADJUST);
- } else {
- layer_off(_RAISE);
- update_tri_layer(_LOWER, _RAISE, _ADJUST);
- }
- return false;
- break;
case BACKLIT:
if (record->event.pressed) {
register_code(KC_RSFT);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 5a2a73d4a2..2662e5ef1c 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -780,12 +780,14 @@ void set_single_persistent_default_layer(uint8_t default_layer) {
default_layer_set(1U<<default_layer);
}
+uint32_t update_tri_layer_state(uint32_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
+ uint32_t mask12 = (1UL << layer1) | (1UL << layer2);
+ uint32_t mask3 = 1UL << layer3;
+ return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
+}
+
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
- if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
- layer_on(layer3);
- } else {
- layer_off(layer3);
- }
+ layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3));
}
void tap_random_base64(void) {
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 80a606f091..195f578de9 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -142,6 +142,7 @@ void send_char(char ascii_code);
// For tri-layer
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
+uint32_t update_tri_layer_state(uint32_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
void set_single_persistent_default_layer(uint8_t default_layer);