aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/command.c22
-rw-r--r--common/layer_stack.c18
-rw-r--r--common/layer_stack.h1
3 files changed, 26 insertions, 15 deletions
diff --git a/common/command.c b/common/command.c
index 4c874b109..c5b9f0431 100644
--- a/common/command.c
+++ b/common/command.c
@@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include "keyboard.h" 27#include "keyboard.h"
28#include "bootloader.h" 28#include "bootloader.h"
29#include "command.h" 29#include "command.h"
30#include "layer_stack.h"
31
30#ifdef MOUSEKEY_ENABLE 32#ifdef MOUSEKEY_ENABLE
31#include "mousekey.h" 33#include "mousekey.h"
32#endif 34#endif
@@ -53,7 +55,7 @@ static void mousekey_console_help(void);
53#endif 55#endif
54 56
55static uint8_t numkey2num(uint8_t code); 57static uint8_t numkey2num(uint8_t code);
56static void switch_layer(uint8_t layer); 58static void switch_default_layer(uint8_t layer);
57 59
58 60
59typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; 61typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
@@ -264,16 +266,13 @@ static bool command_common(uint8_t code)
264 case KC_ESC: 266 case KC_ESC:
265 case KC_GRV: 267 case KC_GRV:
266 case KC_0: 268 case KC_0:
267 clear_keyboard(); 269 switch_default_layer(0);
268 switch_layer(0);
269 break; 270 break;
270 case KC_1 ... KC_9: 271 case KC_1 ... KC_9:
271 clear_keyboard(); 272 switch_default_layer((code - KC_1) + 1);
272 switch_layer((code - KC_1) + 1);
273 break; 273 break;
274 case KC_F1 ... KC_F12: 274 case KC_F1 ... KC_F12:
275 clear_keyboard(); 275 switch_default_layer((code - KC_F1) + 1);
276 switch_layer((code - KC_F1) + 1);
277 break; 276 break;
278 default: 277 default:
279 print("?"); 278 print("?");
@@ -542,11 +541,14 @@ static uint8_t numkey2num(uint8_t code)
542 return 0; 541 return 0;
543} 542}
544 543
545static void switch_layer(uint8_t layer) 544static void switch_default_layer(uint8_t layer)
546{ 545{
547 print_val_hex8(current_layer); 546 print_val_hex8(current_layer);
548 print_val_hex8(default_layer); 547 print_val_hex8(default_layer);
549 default_layer = layer;
550 current_layer = 0;
551 print("switch to "); print_val_hex8(layer); 548 print("switch to "); print_val_hex8(layer);
549
550 default_layer = layer;
551 current_layer = 0; /* 0 means default_layer */
552 layer_stack_clear();
553 clear_keyboard();
552} 554}
diff --git a/common/layer_stack.c b/common/layer_stack.c
index 07c84870c..0076bf779 100644
--- a/common/layer_stack.c
+++ b/common/layer_stack.c
@@ -9,13 +9,23 @@ static uint8_t top_layer = 0;
9/* [0] always works as sentinel and not used for store.*/ 9/* [0] always works as sentinel and not used for store.*/
10static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; 10static layer_item_t layer_stack[LAYER_STACK_SIZE] = {};
11 11
12
13void layer_stack_clear(void)
14{
15 for (uint8_t i = 0; i < LAYER_STACK_SIZE; i++) {
16 layer_stack[i] = (layer_item_t){ .layer = 0,
17 .next = 0,
18 .used = false };
19 }
20}
21
12bool layer_stack_push(uint8_t layer) 22bool layer_stack_push(uint8_t layer)
13{ 23{
14 for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { 24 for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) {
15 if (!layer_stack[i].used) { 25 if (!layer_stack[i].used) {
16 layer_stack[i] = (layer_item_t){ .layer = layer, 26 layer_stack[i] = (layer_item_t){ .layer = layer,
17 .next = top_layer, 27 .next = top_layer,
18 .used = true }; 28 .used = true };
19 top_layer = i; 29 top_layer = i;
20 return true; 30 return true;
21 } 31 }
@@ -73,14 +83,12 @@ void layer_stack_debug(void)
73 layer_item_t item = layer_stack[top_layer]; 83 layer_item_t item = layer_stack[top_layer];
74 while (item.used) { 84 while (item.used) {
75 debug_dec(item.layer); 85 debug_dec(item.layer);
76 debug("["); debug_dec(item.next); debug("]"); 86 debug("["); debug_dec(item.next); debug("] ");
77 item = layer_stack[item.next]; 87 item = layer_stack[item.next];
78 } 88 }
79 debug("\n"); 89 debug("\n");
80} 90}
81 91
82
83
84action_t layer_stack_get_action(key_t key) 92action_t layer_stack_get_action(key_t key)
85{ 93{
86 action_t action; 94 action_t action;
diff --git a/common/layer_stack.h b/common/layer_stack.h
index c88eaffc4..25bf37a5b 100644
--- a/common/layer_stack.h
+++ b/common/layer_stack.h
@@ -32,6 +32,7 @@ typedef struct {
32} layer_item_t; 32} layer_item_t;
33 33
34 34
35void layer_stack_clear(void);
35bool layer_stack_push(uint8_t layer); 36bool layer_stack_push(uint8_t layer);
36bool layer_stack_pop(void); 37bool layer_stack_pop(void);
37bool layer_stack_remove(uint8_t layer); 38bool layer_stack_remove(uint8_t layer);