[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>
This commit is contained in:
parent
9e9b4acbde
commit
4a5bae51cd
14 changed files with 92 additions and 2 deletions
|
@ -52,6 +52,8 @@ enum qk_keycode_ranges {
|
|||
QK_ONE_SHOT_MOD_MAX = 0x52BF,
|
||||
QK_LAYER_TAP_TOGGLE = 0x52C0,
|
||||
QK_LAYER_TAP_TOGGLE_MAX = 0x52DF,
|
||||
QK_PERSISTENT_DEF_LAYER = 0x52E0,
|
||||
QK_PERSISTENT_DEF_LAYER_MAX = 0x52FF,
|
||||
QK_SWAP_HANDS = 0x5600,
|
||||
QK_SWAP_HANDS_MAX = 0x56FF,
|
||||
QK_TAP_DANCE = 0x5700,
|
||||
|
@ -1462,6 +1464,7 @@ enum qk_keycode_defines {
|
|||
#define IS_QK_ONE_SHOT_LAYER(code) ((code) >= QK_ONE_SHOT_LAYER && (code) <= QK_ONE_SHOT_LAYER_MAX)
|
||||
#define IS_QK_ONE_SHOT_MOD(code) ((code) >= QK_ONE_SHOT_MOD && (code) <= QK_ONE_SHOT_MOD_MAX)
|
||||
#define IS_QK_LAYER_TAP_TOGGLE(code) ((code) >= QK_LAYER_TAP_TOGGLE && (code) <= QK_LAYER_TAP_TOGGLE_MAX)
|
||||
#define IS_QK_PERSISTENT_DEF_LAYER(code) ((code) >= QK_PERSISTENT_DEF_LAYER && (code) <= QK_PERSISTENT_DEF_LAYER_MAX)
|
||||
#define IS_QK_SWAP_HANDS(code) ((code) >= QK_SWAP_HANDS && (code) <= QK_SWAP_HANDS_MAX)
|
||||
#define IS_QK_TAP_DANCE(code) ((code) >= QK_TAP_DANCE && (code) <= QK_TAP_DANCE_MAX)
|
||||
#define IS_QK_MAGIC(code) ((code) >= QK_MAGIC && (code) <= QK_MAGIC_MAX)
|
||||
|
|
|
@ -357,6 +357,8 @@ bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) {
|
|||
}
|
||||
// DF ---------------------------------------------------------------------------------------------------------
|
||||
case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:
|
||||
// PDF --------------------------------------------------------------------------------------------------------
|
||||
case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX:
|
||||
# ifndef NO_ACTION_ONESHOT
|
||||
// OSL((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------
|
||||
case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
|
||||
|
|
|
@ -98,6 +98,7 @@ bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record,
|
|||
case QK_TO ... QK_TO_MAX:
|
||||
case QK_MOMENTARY ... QK_MOMENTARY_MAX:
|
||||
case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:
|
||||
case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX:
|
||||
case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
|
||||
case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
|
||||
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
|
||||
|
|
32
quantum/process_keycode/process_default_layer.c
Normal file
32
quantum/process_keycode/process_default_layer.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright 2023 Nebuleon
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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 "process_default_layer.h"
|
||||
#include "quantum.h"
|
||||
#include "quantum_keycodes.h"
|
||||
|
||||
#if !defined(NO_ACTION_LAYER)
|
||||
|
||||
bool process_default_layer(uint16_t keycode, keyrecord_t *record) {
|
||||
if (IS_QK_PERSISTENT_DEF_LAYER(keycode) && !record->event.pressed) {
|
||||
uint8_t layer = QK_PERSISTENT_DEF_LAYER_GET_LAYER(keycode);
|
||||
set_single_persistent_default_layer(layer);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // !defined(NO_ACTION_LAYER)
|
27
quantum/process_keycode/process_default_layer.h
Normal file
27
quantum/process_keycode/process_default_layer.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright 2023 Nebuleon
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "action.h"
|
||||
|
||||
#if !defined(NO_ACTION_LAYER)
|
||||
|
||||
bool process_default_layer(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
#endif // !defined(NO_ACTION_LAYER)
|
|
@ -52,6 +52,10 @@
|
|||
# include "process_midi.h"
|
||||
#endif
|
||||
|
||||
#if !defined(NO_ACTION_LAYER)
|
||||
# include "process_default_layer.h"
|
||||
#endif
|
||||
|
||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||
# include "process_programmable_button.h"
|
||||
#endif
|
||||
|
@ -404,6 +408,9 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
#ifdef TRI_LAYER_ENABLE
|
||||
process_tri_layer(keycode, record) &&
|
||||
#endif
|
||||
#if !defined(NO_ACTION_LAYER)
|
||||
process_default_layer(keycode, record) &&
|
||||
#endif
|
||||
#ifdef LAYER_LOCK_ENABLE
|
||||
process_layer_lock(keycode, record) &&
|
||||
#endif
|
||||
|
|
|
@ -92,6 +92,10 @@
|
|||
#define DF(layer) (QK_DEF_LAYER | ((layer)&0x1F))
|
||||
#define QK_DEF_LAYER_GET_LAYER(kc) ((kc)&0x1F)
|
||||
|
||||
// Set persistent default layer - 32 layer max
|
||||
#define PDF(layer) (QK_PERSISTENT_DEF_LAYER | ((layer)&0x1F))
|
||||
#define QK_PERSISTENT_DEF_LAYER_GET_LAYER(kc) ((kc)&0x1F)
|
||||
|
||||
// Toggle to layer - 32 layer max
|
||||
#define TG(layer) (QK_TOGGLE_LAYER | ((layer)&0x1F))
|
||||
#define QK_TOGGLE_LAYER_GET_LAYER(kc) ((kc)&0x1F)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue