Skip to content

Commit

Permalink
PD(): Move processing to process_default_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebuleon committed May 18, 2024
1 parent 8a35f22 commit 4d477bd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 14 deletions.
1 change: 1 addition & 0 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ QUANTUM_SRC += \
$(QUANTUM_DIR)/sync_timer.c \
$(QUANTUM_DIR)/logging/debug.c \
$(QUANTUM_DIR)/logging/sendchar.c \
$(QUANTUM_DIR)/process_keycode/process_default_layer.c \

VPATH += $(QUANTUM_DIR)/logging
# Fall back to lib/printf if there is no platform provided print
Expand Down
5 changes: 0 additions & 5 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,6 @@ void process_action(keyrecord_t *record, action_t action) {
}
# endif // !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
break;
case OP_EE_DEFAULT:
if (!event.pressed) {
set_single_persistent_default_layer(action.layer_tap.val);
}
break;
default:
# ifndef NO_ACTION_TAPPING /* tap key */
if (event.pressed) {
Expand Down
5 changes: 1 addition & 4 deletions quantum/action_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 101E|LLLL|1111 0010 Off/On (0xF2) [NOT TAP]
* 101E|LLLL|1111 0011 Set/Clear (0xF3) [NOT TAP]
* 101E|LLLL|1111 0100 One Shot Layer (0xF4) [TAP]
/ 101E|LLLL|1111 0101 Default EEPROM Layer (0xF5) [NOT TAP]
* 101E|LLLL|1111 xxxx Reserved (0xF6-FF)
* 101E|LLLL|1111 xxxx Reserved (0xF5-FF)
* ELLLL: layer 0-31(E: extra bit for layer 16-31)
*/
enum action_kind_id {
Expand Down Expand Up @@ -210,7 +209,6 @@ enum layer_param_tap_op {
OP_OFF_ON,
OP_SET_CLEAR,
OP_ONESHOT,
OP_EE_DEFAULT,
};
#define ACTION_LAYER_BITOP(op, part, bits, on) ACTION(ACT_LAYER, (op) << 10 | (on) << 8 | (part) << 5 | ((bits)&0x1f))
#define ACTION_LAYER_TAP(layer, key) ACTION(ACT_LAYER_TAP, (layer) << 8 | (key))
Expand All @@ -229,7 +227,6 @@ enum layer_param_tap_op {
#define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON)
#define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR)
#define ACTION_LAYER_ONESHOT(layer) ACTION_LAYER_TAP((layer), OP_ONESHOT)
#define ACTION_LAYER_EE_DEFAULT(layer) ACTION_LAYER_TAP((layer), OP_EE_DEFAULT)
#define ACTION_LAYER_MODS(layer, mods) ACTION(ACT_LAYER_MODS, (layer) << 8 | (mods))
/* With Tapping */
#define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key))
Expand Down
5 changes: 0 additions & 5 deletions quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ action_t action_for_keycode(uint16_t keycode) {
action_layer = QK_DEF_LAYER_GET_LAYER(keycode);
action.code = ACTION_DEFAULT_LAYER_SET(action_layer);
break;
case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX:;
// Set default action_layer in EEPROM
action_layer = QK_PERSISTENT_DEF_LAYER_GET_LAYER(keycode);
action.code = ACTION_LAYER_EE_DEFAULT(action_layer);
break;
case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:;
// Set toggle
action_layer = QK_TOGGLE_LAYER_GET_LAYER(keycode);
Expand Down
32 changes: 32 additions & 0 deletions quantum/process_keycode/process_default_layer.c
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions quantum/process_keycode/process_default_layer.h
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -393,6 +397,9 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
#ifdef TRI_LAYER_ENABLE
process_tri_layer(keycode, record) &&
#endif
#if !defined(NO_ACTION_LAYER)
process_default_layer(keycode, record) &&
#endif
true)) {
return false;
Expand Down

0 comments on commit 4d477bd

Please sign in to comment.