2015-04-09 16:32:04 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "action.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "action_layer.h"
|
2016-04-21 05:35:48 +00:00
|
|
|
#include "hook.h"
|
2015-04-09 16:32:04 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ACTION
|
|
|
|
#include "debug.h"
|
|
|
|
#else
|
|
|
|
#include "nodebug.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default Layer State
|
|
|
|
*/
|
|
|
|
uint32_t default_layer_state = 0;
|
|
|
|
|
|
|
|
static void default_layer_state_set(uint32_t state)
|
|
|
|
{
|
|
|
|
debug("default_layer_state: ");
|
|
|
|
default_layer_debug(); debug(" to ");
|
|
|
|
default_layer_state = state;
|
2016-05-22 13:49:29 +00:00
|
|
|
hook_default_layer_change(default_layer_state);
|
2015-04-09 16:32:04 +00:00
|
|
|
default_layer_debug(); debug("\n");
|
|
|
|
clear_keyboard_but_mods(); // To avoid stuck keys
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_layer_debug(void)
|
|
|
|
{
|
|
|
|
dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state));
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_layer_set(uint32_t state)
|
|
|
|
{
|
|
|
|
default_layer_state_set(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NO_ACTION_LAYER
|
|
|
|
void default_layer_or(uint32_t state)
|
|
|
|
{
|
|
|
|
default_layer_state_set(default_layer_state | state);
|
|
|
|
}
|
|
|
|
void default_layer_and(uint32_t state)
|
|
|
|
{
|
|
|
|
default_layer_state_set(default_layer_state & state);
|
|
|
|
}
|
|
|
|
void default_layer_xor(uint32_t state)
|
|
|
|
{
|
|
|
|
default_layer_state_set(default_layer_state ^ state);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef NO_ACTION_LAYER
|
|
|
|
/*
|
|
|
|
* Keymap Layer State
|
|
|
|
*/
|
|
|
|
uint32_t layer_state = 0;
|
|
|
|
|
|
|
|
static void layer_state_set(uint32_t state)
|
|
|
|
{
|
|
|
|
dprint("layer_state: ");
|
|
|
|
layer_debug(); dprint(" to ");
|
|
|
|
layer_state = state;
|
2016-04-21 05:35:48 +00:00
|
|
|
hook_layer_change(layer_state);
|
2015-04-09 16:32:04 +00:00
|
|
|
layer_debug(); dprintln();
|
|
|
|
clear_keyboard_but_mods(); // To avoid stuck keys
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_clear(void)
|
|
|
|
{
|
|
|
|
layer_state_set(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_move(uint8_t layer)
|
|
|
|
{
|
|
|
|
layer_state_set(1UL<<layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_on(uint8_t layer)
|
|
|
|
{
|
|
|
|
layer_state_set(layer_state | (1UL<<layer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_off(uint8_t layer)
|
|
|
|
{
|
|
|
|
layer_state_set(layer_state & ~(1UL<<layer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_invert(uint8_t layer)
|
|
|
|
{
|
|
|
|
layer_state_set(layer_state ^ (1UL<<layer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_or(uint32_t state)
|
|
|
|
{
|
|
|
|
layer_state_set(layer_state | state);
|
|
|
|
}
|
|
|
|
void layer_and(uint32_t state)
|
|
|
|
{
|
|
|
|
layer_state_set(layer_state & state);
|
|
|
|
}
|
|
|
|
void layer_xor(uint32_t state)
|
|
|
|
{
|
|
|
|
layer_state_set(layer_state ^ state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer_debug(void)
|
|
|
|
{
|
|
|
|
dprintf("%08lX(%u)", layer_state, biton32(layer_state));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
action_t layer_switch_get_action(keypos_t key)
|
|
|
|
{
|
2016-03-29 18:37:57 +00:00
|
|
|
action_t action = ACTION_TRANSPARENT;
|
2015-04-09 16:32:04 +00:00
|
|
|
|
|
|
|
#ifndef NO_ACTION_LAYER
|
|
|
|
uint32_t layers = layer_state | default_layer_state;
|
|
|
|
/* check top layer first */
|
|
|
|
for (int8_t i = 31; i >= 0; i--) {
|
|
|
|
if (layers & (1UL<<i)) {
|
|
|
|
action = action_for_key(i, key);
|
2016-03-29 18:37:57 +00:00
|
|
|
if (action.code != (action_t)ACTION_TRANSPARENT.code) {
|
2015-04-09 16:32:04 +00:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* fall back to layer 0 */
|
|
|
|
action = action_for_key(0, key);
|
|
|
|
return action;
|
|
|
|
#else
|
|
|
|
action = action_for_key(biton32(default_layer_state), key);
|
|
|
|
return action;
|
|
|
|
#endif
|
|
|
|
}
|