keyboard stuff
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Feature] Add keycode PDF(layer) to set the default layer in EEPROM (#24630)

* [Feature] Add keycode PDF(layer) to set the default layer in EEPROM (#21881)

* Apply suggestions from code review

Co-authored-by: Nick Brassel <nick@tzarc.org>

---------

Co-authored-by: Nebuleon <2391500+Nebuleon@users.noreply.github.com>
Co-authored-by: Nick Brassel <nick@tzarc.org>

authored by

Joel Challis
Nick Brassel
Nebuleon
and committed by
GitHub
4a5bae51 9e9b4acb

+92 -2
+1
builddefs/common_features.mk
··· 28 28 $(QUANTUM_DIR)/sync_timer.c \ 29 29 $(QUANTUM_DIR)/logging/debug.c \ 30 30 $(QUANTUM_DIR)/logging/sendchar.c \ 31 + $(QUANTUM_DIR)/process_keycode/process_default_layer.c \ 31 32 32 33 VPATH += $(QUANTUM_DIR)/logging 33 34 # Fall back to lib/printf if there is no platform provided print
+7
data/constants/keycodes/keycodes_0.0.6.hjson
··· 1 + { 2 + "ranges": { 3 + "0x52E0/0x001F": { 4 + "define": "QK_PERSISTENT_DEF_LAYER" 5 + } 6 + } 7 + }
+2 -1
docs/feature_layers.md
··· 8 8 9 9 These functions allow you to activate layers in various ways. Note that layers are not generally independent layouts -- multiple layers can be activated at once, and it's typical for layers to use `KC_TRNS` to allow keypresses to pass through to lower layers. When using momentary layer switching with MO(), LM(), TT(), or LT(), make sure to leave the key on the above layers transparent or it may not work as intended. 10 10 11 - * `DF(layer)` - switches the default layer. The default layer is the always-active base layer that other layers stack on top of. See below for more about the default layer. This might be used to switch from QWERTY to Dvorak layout. (Note that this is a temporary switch that only persists until the keyboard loses power. To modify the default layer in a persistent way requires deeper customization, such as calling the `set_single_persistent_default_layer` function inside of [process_record_user](custom_quantum_functions#programming-the-behavior-of-any-keycode).) 11 + * `DF(layer)` - switches the default layer. The default layer is the always-active base layer that other layers stack on top of. See below for more about the default layer. This might be used to switch from QWERTY to Dvorak layout. Note that this is a temporary switch that only persists until the keyboard loses power. 12 + * `PDF(layer)` - sets a persistent default layer. This switch, which will last through a power loss, might be used to switch from QWERTY to Dvorak layout and only switch again when you want to. 12 13 * `MO(layer)` - momentarily activates *layer*. As soon as you let go of the key, the layer is deactivated. 13 14 * `LM(layer, mod)` - Momentarily activates *layer* (like `MO`), but with modifier(s) *mod* active. Only supports layers 0-15. The modifiers this keycode accept are prefixed with `MOD_`, not `KC_`. These modifiers can be combined using bitwise OR, e.g. `LM(_RAISE, MOD_LCTL | MOD_LALT)`. 14 15 * `LT(layer, kc)` - momentarily activates *layer* when held, and sends *kc* when tapped. Only supports layers 0-15.
+2 -1
docs/keycodes.md
··· 401 401 402 402 |Key |Description | 403 403 |----------------|----------------------------------------------------------------------------------| 404 - |`DF(layer)` |Set the base (default) layer | 404 + |`DF(layer)` |Set the base (default) layer until the keyboard loses power | 405 + |`PDF(layer)` |Set the base (default) layer in EEPROM | 405 406 |`MO(layer)` |Momentarily turn on `layer` when pressed (requires `KC_TRNS` on destination layer)| 406 407 |`OSL(layer)` |Momentarily activates `layer` until a key is pressed. See [One Shot Keys](one_shot_keys) for details. | 407 408 |`LM(layer, mod)`|Momentarily turn on `layer` (like MO) with `mod` active as well. Where `mod` is a mods_bit. Mods can be viewed [here](mod_tap). Example Implementation: `LM(LAYER_1, MOD_LALT)`|
+1
keyboards/zsa/moonlander/moonlander.c
··· 275 275 case QK_TO ... QK_TO_MAX: 276 276 case QK_MOMENTARY ... QK_MOMENTARY_MAX: 277 277 case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: 278 + case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX: 278 279 case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: 279 280 case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: 280 281 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+1
keyboards/zsa/planck_ez/planck_ez.c
··· 237 237 case QK_TO ... QK_TO_MAX: 238 238 case QK_MOMENTARY ... QK_MOMENTARY_MAX: 239 239 case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: 240 + case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX: 240 241 case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: 241 242 case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: 242 243 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+3
quantum/keycodes.h
··· 52 52 QK_ONE_SHOT_MOD_MAX = 0x52BF, 53 53 QK_LAYER_TAP_TOGGLE = 0x52C0, 54 54 QK_LAYER_TAP_TOGGLE_MAX = 0x52DF, 55 + QK_PERSISTENT_DEF_LAYER = 0x52E0, 56 + QK_PERSISTENT_DEF_LAYER_MAX = 0x52FF, 55 57 QK_SWAP_HANDS = 0x5600, 56 58 QK_SWAP_HANDS_MAX = 0x56FF, 57 59 QK_TAP_DANCE = 0x5700, ··· 1462 1464 #define IS_QK_ONE_SHOT_LAYER(code) ((code) >= QK_ONE_SHOT_LAYER && (code) <= QK_ONE_SHOT_LAYER_MAX) 1463 1465 #define IS_QK_ONE_SHOT_MOD(code) ((code) >= QK_ONE_SHOT_MOD && (code) <= QK_ONE_SHOT_MOD_MAX) 1464 1466 #define IS_QK_LAYER_TAP_TOGGLE(code) ((code) >= QK_LAYER_TAP_TOGGLE && (code) <= QK_LAYER_TAP_TOGGLE_MAX) 1467 + #define IS_QK_PERSISTENT_DEF_LAYER(code) ((code) >= QK_PERSISTENT_DEF_LAYER && (code) <= QK_PERSISTENT_DEF_LAYER_MAX) 1465 1468 #define IS_QK_SWAP_HANDS(code) ((code) >= QK_SWAP_HANDS && (code) <= QK_SWAP_HANDS_MAX) 1466 1469 #define IS_QK_TAP_DANCE(code) ((code) >= QK_TAP_DANCE && (code) <= QK_TAP_DANCE_MAX) 1467 1470 #define IS_QK_MAGIC(code) ((code) >= QK_MAGIC && (code) <= QK_MAGIC_MAX)
+2
quantum/pointing_device/pointing_device_auto_mouse.c
··· 357 357 } 358 358 // DF --------------------------------------------------------------------------------------------------------- 359 359 case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: 360 + // PDF -------------------------------------------------------------------------------------------------------- 361 + case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX: 360 362 # ifndef NO_ACTION_ONESHOT 361 363 // OSL((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------ 362 364 case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
+1
quantum/process_keycode/process_autocorrect.c
··· 98 98 case QK_TO ... QK_TO_MAX: 99 99 case QK_MOMENTARY ... QK_MOMENTARY_MAX: 100 100 case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: 101 + case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX: 101 102 case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: 102 103 case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: 103 104 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+32
quantum/process_keycode/process_default_layer.c
··· 1 + /* Copyright 2023 Nebuleon 2 + * 3 + * This program is free software: you can redistribute it and/or modify 4 + * it under the terms of the GNU General Public License as published by 5 + * the Free Software Foundation, either version 2 of the License, or 6 + * (at your option) any later version. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + #include "process_default_layer.h" 17 + #include "quantum.h" 18 + #include "quantum_keycodes.h" 19 + 20 + #if !defined(NO_ACTION_LAYER) 21 + 22 + bool process_default_layer(uint16_t keycode, keyrecord_t *record) { 23 + if (IS_QK_PERSISTENT_DEF_LAYER(keycode) && !record->event.pressed) { 24 + uint8_t layer = QK_PERSISTENT_DEF_LAYER_GET_LAYER(keycode); 25 + set_single_persistent_default_layer(layer); 26 + return false; 27 + } 28 + 29 + return true; 30 + } 31 + 32 + #endif // !defined(NO_ACTION_LAYER)
+27
quantum/process_keycode/process_default_layer.h
··· 1 + /* Copyright 2023 Nebuleon 2 + * 3 + * This program is free software: you can redistribute it and/or modify 4 + * it under the terms of the GNU General Public License as published by 5 + * the Free Software Foundation, either version 2 of the License, or 6 + * (at your option) any later version. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License 14 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + 17 + #pragma once 18 + 19 + #include <stdint.h> 20 + #include <stdbool.h> 21 + #include "action.h" 22 + 23 + #if !defined(NO_ACTION_LAYER) 24 + 25 + bool process_default_layer(uint16_t keycode, keyrecord_t *record); 26 + 27 + #endif // !defined(NO_ACTION_LAYER)
+7
quantum/quantum.c
··· 52 52 # include "process_midi.h" 53 53 #endif 54 54 55 + #if !defined(NO_ACTION_LAYER) 56 + # include "process_default_layer.h" 57 + #endif 58 + 55 59 #ifdef PROGRAMMABLE_BUTTON_ENABLE 56 60 # include "process_programmable_button.h" 57 61 #endif ··· 403 407 #endif 404 408 #ifdef TRI_LAYER_ENABLE 405 409 process_tri_layer(keycode, record) && 410 + #endif 411 + #if !defined(NO_ACTION_LAYER) 412 + process_default_layer(keycode, record) && 406 413 #endif 407 414 #ifdef LAYER_LOCK_ENABLE 408 415 process_layer_lock(keycode, record) &&
+4
quantum/quantum_keycodes.h
··· 92 92 #define DF(layer) (QK_DEF_LAYER | ((layer)&0x1F)) 93 93 #define QK_DEF_LAYER_GET_LAYER(kc) ((kc)&0x1F) 94 94 95 + // Set persistent default layer - 32 layer max 96 + #define PDF(layer) (QK_PERSISTENT_DEF_LAYER | ((layer)&0x1F)) 97 + #define QK_PERSISTENT_DEF_LAYER_GET_LAYER(kc) ((kc)&0x1F) 98 + 95 99 // Toggle to layer - 32 layer max 96 100 #define TG(layer) (QK_TOGGLE_LAYER | ((layer)&0x1F)) 97 101 #define QK_TOGGLE_LAYER_GET_LAYER(kc) ((kc)&0x1F)
+2
tests/test_common/keycode_util.cpp
··· 94 94 s << "MO(" << +QK_MOMENTARY_GET_LAYER(kc) << ")"; 95 95 } else if (IS_QK_DEF_LAYER(kc)) { 96 96 s << "DF(" << +QK_DEF_LAYER_GET_LAYER(kc) << ")"; 97 + } else if (IS_QK_PERSISTENT_DEF_LAYER(kc)) { 98 + s << "PDF(" << +QK_PERSISTENT_DEF_LAYER_GET_LAYER(kc) << ")"; 97 99 } else if (IS_QK_TOGGLE_LAYER(kc)) { 98 100 s << "TG(" << +QK_TOGGLE_LAYER_GET_LAYER(kc) << ")"; 99 101 } else if (IS_QK_LAYER_TAP_TOGGLE(kc)) {