Fix switch_default_layer command
This commit is contained in:
parent
0c1d98bd3c
commit
2b811352a1
@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "bootloader.h"
|
#include "bootloader.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
#include "layer_stack.h"
|
||||||
|
|
||||||
#ifdef MOUSEKEY_ENABLE
|
#ifdef MOUSEKEY_ENABLE
|
||||||
#include "mousekey.h"
|
#include "mousekey.h"
|
||||||
#endif
|
#endif
|
||||||
@ -53,7 +55,7 @@ static void mousekey_console_help(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint8_t numkey2num(uint8_t code);
|
static uint8_t numkey2num(uint8_t code);
|
||||||
static void switch_layer(uint8_t layer);
|
static void switch_default_layer(uint8_t layer);
|
||||||
|
|
||||||
|
|
||||||
typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
|
typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
|
||||||
@ -264,16 +266,13 @@ static bool command_common(uint8_t code)
|
|||||||
case KC_ESC:
|
case KC_ESC:
|
||||||
case KC_GRV:
|
case KC_GRV:
|
||||||
case KC_0:
|
case KC_0:
|
||||||
clear_keyboard();
|
switch_default_layer(0);
|
||||||
switch_layer(0);
|
|
||||||
break;
|
break;
|
||||||
case KC_1 ... KC_9:
|
case KC_1 ... KC_9:
|
||||||
clear_keyboard();
|
switch_default_layer((code - KC_1) + 1);
|
||||||
switch_layer((code - KC_1) + 1);
|
|
||||||
break;
|
break;
|
||||||
case KC_F1 ... KC_F12:
|
case KC_F1 ... KC_F12:
|
||||||
clear_keyboard();
|
switch_default_layer((code - KC_F1) + 1);
|
||||||
switch_layer((code - KC_F1) + 1);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print("?");
|
print("?");
|
||||||
@ -542,11 +541,14 @@ static uint8_t numkey2num(uint8_t code)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void switch_layer(uint8_t layer)
|
static void switch_default_layer(uint8_t layer)
|
||||||
{
|
{
|
||||||
print_val_hex8(current_layer);
|
print_val_hex8(current_layer);
|
||||||
print_val_hex8(default_layer);
|
print_val_hex8(default_layer);
|
||||||
default_layer = layer;
|
|
||||||
current_layer = 0;
|
|
||||||
print("switch to "); print_val_hex8(layer);
|
print("switch to "); print_val_hex8(layer);
|
||||||
|
|
||||||
|
default_layer = layer;
|
||||||
|
current_layer = 0; /* 0 means default_layer */
|
||||||
|
layer_stack_clear();
|
||||||
|
clear_keyboard();
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,23 @@ static uint8_t top_layer = 0;
|
|||||||
/* [0] always works as sentinel and not used for store.*/
|
/* [0] always works as sentinel and not used for store.*/
|
||||||
static layer_item_t layer_stack[LAYER_STACK_SIZE] = {};
|
static layer_item_t layer_stack[LAYER_STACK_SIZE] = {};
|
||||||
|
|
||||||
|
|
||||||
|
void layer_stack_clear(void)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < LAYER_STACK_SIZE; i++) {
|
||||||
|
layer_stack[i] = (layer_item_t){ .layer = 0,
|
||||||
|
.next = 0,
|
||||||
|
.used = false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool layer_stack_push(uint8_t layer)
|
bool layer_stack_push(uint8_t layer)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) {
|
for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) {
|
||||||
if (!layer_stack[i].used) {
|
if (!layer_stack[i].used) {
|
||||||
layer_stack[i] = (layer_item_t){ .layer = layer,
|
layer_stack[i] = (layer_item_t){ .layer = layer,
|
||||||
.next = top_layer,
|
.next = top_layer,
|
||||||
.used = true };
|
.used = true };
|
||||||
top_layer = i;
|
top_layer = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -73,14 +83,12 @@ void layer_stack_debug(void)
|
|||||||
layer_item_t item = layer_stack[top_layer];
|
layer_item_t item = layer_stack[top_layer];
|
||||||
while (item.used) {
|
while (item.used) {
|
||||||
debug_dec(item.layer);
|
debug_dec(item.layer);
|
||||||
debug("["); debug_dec(item.next); debug("]");
|
debug("["); debug_dec(item.next); debug("] ");
|
||||||
item = layer_stack[item.next];
|
item = layer_stack[item.next];
|
||||||
}
|
}
|
||||||
debug("\n");
|
debug("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
action_t layer_stack_get_action(key_t key)
|
action_t layer_stack_get_action(key_t key)
|
||||||
{
|
{
|
||||||
action_t action;
|
action_t action;
|
||||||
|
@ -32,6 +32,7 @@ typedef struct {
|
|||||||
} layer_item_t;
|
} layer_item_t;
|
||||||
|
|
||||||
|
|
||||||
|
void layer_stack_clear(void);
|
||||||
bool layer_stack_push(uint8_t layer);
|
bool layer_stack_push(uint8_t layer);
|
||||||
bool layer_stack_pop(void);
|
bool layer_stack_pop(void);
|
||||||
bool layer_stack_remove(uint8_t layer);
|
bool layer_stack_remove(uint8_t layer);
|
||||||
|
Loading…
Reference in New Issue
Block a user