@ -1,108 +0,0 @@ | |||
#include <stdint.h> | |||
#include "keyboard.h" | |||
#include "layer_stack.h" | |||
#include "debug.h" | |||
static uint8_t top_layer = 0; | |||
/* [0] always works as sentinel and not used for store.*/ | |||
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) | |||
{ | |||
for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { | |||
if (!layer_stack[i].used) { | |||
layer_stack[i] = (layer_item_t){ .layer = layer, | |||
.next = top_layer, | |||
.used = true }; | |||
top_layer = i; | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
bool layer_stack_pop(void) | |||
{ | |||
if (layer_stack[top_layer].used) { | |||
uint8_t popped = top_layer; | |||
top_layer = layer_stack[popped].next; | |||
layer_stack[popped] = (layer_item_t){}; | |||
return true; | |||
} | |||
return false; | |||
} | |||
bool layer_stack_remove(uint8_t layer) | |||
{ | |||
if (layer_stack[top_layer].used && layer_stack[top_layer].layer == layer) { | |||
layer_stack_pop(); | |||
debug("layer_stack_remove: top_layer\n"); | |||
return true; | |||
} | |||
for (uint8_t i = top_layer; layer_stack[i].used; i = layer_stack[i].next) { | |||
debug("layer_stack_remove: ["); debug_dec(i); debug("]"); | |||
debug_dec(layer_stack[i].layer); debug("\n"); | |||
uint8_t removed = layer_stack[i].next; | |||
if (layer_stack[removed].used && layer_stack[removed].layer == layer) { | |||
layer_stack[i].next = layer_stack[removed].next; | |||
layer_stack[removed] = (layer_item_t){}; | |||
debug("layer_stack_remove: removed.\n"); | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
bool layer_stack_remove_then_push(uint8_t layer) | |||
{ | |||
layer_stack_remove(layer); | |||
return layer_stack_push(layer); | |||
} | |||
bool layer_stack_remove_or_push(uint8_t layer) | |||
{ | |||
return (layer_stack_remove(layer)) || layer_stack_push(layer); | |||
} | |||
void layer_stack_debug(void) | |||
{ | |||
debug("layer_stack: "); | |||
layer_item_t item = layer_stack[top_layer]; | |||
while (item.used) { | |||
debug_dec(item.layer); | |||
debug("["); debug_dec(item.next); debug("] "); | |||
item = layer_stack[item.next]; | |||
} | |||
debug("\n"); | |||
} | |||
action_t layer_stack_get_action(key_t key) | |||
{ | |||
action_t action; | |||
action.code = ACTION_TRANSPARENT; | |||
/* layer stack */ | |||
for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) { | |||
action = action_for_key(i.layer, key); | |||
if (action.code != ACTION_TRANSPARENT) { | |||
layer_stack_debug(); | |||
debug("layer_stack: used. "); debug_dec(i.layer); debug("\n"); | |||
return action; | |||
} | |||
debug("layer_stack: through. "); debug_dec(i.layer); debug("\n"); | |||
} | |||
return action; | |||
} |
@ -1,45 +0,0 @@ | |||
/* | |||
Copyright 2013 Jun Wako <wakojun@gmail.com> | |||
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/>. | |||
*/ | |||
#ifndef LAYER_STACK_H | |||
#define LAYER_STACK_H | |||
#include <stdint.h> | |||
#include "action.h" | |||
/* | |||
* Layer stack | |||
*/ | |||
#define LAYER_STACK_SIZE 8 | |||
typedef struct { | |||
uint8_t layer:4; | |||
uint8_t next:3; | |||
bool used; | |||
} layer_item_t; | |||
void layer_stack_clear(void); | |||
bool layer_stack_push(uint8_t layer); | |||
bool layer_stack_pop(void); | |||
bool layer_stack_remove(uint8_t layer); | |||
bool layer_stack_remove_then_push(uint8_t layer); | |||
bool layer_stack_remove_or_push(uint8_t layer); | |||
void layer_stack_debug(void); | |||
action_t layer_stack_get_action(key_t key); | |||
#endif | |||
@ -0,0 +1,104 @@ | |||
#include <stdint.h> | |||
#include "keyboard.h" | |||
#include "action.h" | |||
#include "debug.h" | |||
#include "util.h" | |||
#include "layer_switch.h" | |||
uint8_t default_layer = 0; | |||
uint16_t layer_switch_stat = 0; | |||
uint16_t layer_switch_get_stat(void) | |||
{ | |||
return layer_switch_stat; | |||
} | |||
/* return highest layer whose state is on */ | |||
uint8_t layer_switch_get_layer(void) | |||
{ | |||
return biton16(layer_switch_stat); | |||
} | |||
static inline void stat_set(uint16_t stat) | |||
{ | |||
debug("layer_switch: "); | |||
layer_switch_debug(); debug(" to "); | |||
layer_switch_stat = stat; | |||
layer_switch_debug(); debug("\n"); | |||
clear_keyboard_but_mods(); // To avoid stuck keys | |||
} | |||
void layer_switch_clear(void) | |||
{ | |||
stat_set(0); | |||
} | |||
void layer_switch_set(uint16_t stat) | |||
{ | |||
stat_set(stat); | |||
} | |||
void layer_switch_move(uint8_t layer) | |||
{ | |||
if (layer) | |||
stat_set(1<<layer); | |||
else | |||
stat_set(0); // fall back to default layer | |||
} | |||
void layer_switch_on(uint8_t layer) | |||
{ | |||
stat_set(layer_switch_stat | (1<<layer)); | |||
} | |||
void layer_switch_off(uint8_t layer) | |||
{ | |||
stat_set(layer_switch_stat & ~(1<<layer)); | |||
} | |||
void layer_switch_invert(uint8_t layer) | |||
{ | |||
stat_set(layer_switch_stat ^ (1<<layer)); | |||
} | |||
void layer_switch_or(uint16_t stat) | |||
{ | |||
stat_set(layer_switch_stat | stat); | |||
} | |||
void layer_switch_and(uint16_t stat) | |||
{ | |||
stat_set(layer_switch_stat & stat); | |||
} | |||
void layer_switch_xor(uint16_t stat) | |||
{ | |||
stat_set(layer_switch_stat ^ stat); | |||
} | |||
void layer_switch_debug(void) | |||
{ | |||
debug_hex16(layer_switch_stat); debug("("); debug_dec(layer_switch_get_layer()); debug(")"); | |||
} | |||
action_t layer_switch_get_action(key_t key) | |||
{ | |||
action_t action; | |||
action.code = ACTION_TRANSPARENT; | |||
/* higher layer first */ | |||
for (int8_t i = 15; i >= 0; i--) { | |||
if (layer_switch_stat & (1<<i)) { | |||
action = action_for_key(i, key); | |||
if (action.code != ACTION_TRANSPARENT) { | |||
return action; | |||
} | |||
} | |||
} | |||
return action; | |||
} |
@ -0,0 +1,59 @@ | |||
/* | |||
Copyright 2013 Jun Wako <wakojun@gmail.com> | |||
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/>. | |||
*/ | |||
#ifndef LAYER_SWITCH_H | |||
#define LAYER_SWITCH_H | |||
#include <stdint.h> | |||
#include "keyboard.h" | |||
#include "action.h" | |||
/* base layer to fall back */ | |||
extern uint8_t default_layer; | |||
/* layer status */ | |||
extern uint16_t layer_switch_stat; | |||
/* return layer status */ | |||
uint16_t layer_switch_get_stat(void); | |||
/* return current active layer */ | |||
uint8_t layer_switch_get_layer(void); | |||
/* switch off all layers */ | |||
void layer_switch_clear(void); | |||
/* set layer status */ | |||
void layer_switch_set(uint16_t stat); | |||
/* move to layer */ | |||
void layer_switch_move(uint8_t layer); | |||
/* switch on layer */ | |||
void layer_switch_on(uint8_t layer); | |||
/* switch off layer */ | |||
void layer_switch_off(uint8_t layer); | |||
/* switch state of layer */ | |||
void layer_switch_invert(uint8_t layer); | |||
/* bitwise operation against layer status */ | |||
void layer_switch_or(uint16_t stat); | |||
void layer_switch_and(uint16_t stat); | |||
void layer_switch_xor(uint16_t stat); | |||
void layer_switch_debug(void); | |||
/* return action depending on current layer status */ | |||
action_t layer_switch_get_action(key_t key); | |||
#endif |
@ -0,0 +1,110 @@ | |||
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
/* Poker Default Layer | |||
* ,-----------------------------------------------------------. | |||
* | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | | |||
* |-----------------------------------------------------------| | |||
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| | |||
* |-----------------------------------------------------------| | |||
* |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return | | |||
* |-----------------------------------------------------------| | |||
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | | |||
* |-----------------------------------------------------------| | |||
* |Ctrl|Gui |Alt | Space |Fn |Gui |App |Ctrl| | |||
* `-----------------------------------------------------------' | |||
*/ | |||
/* Layer 0: qwerty */ | |||
KEYMAP_ANSI( | |||
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ | |||
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ | |||
LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ | |||
LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ | |||
LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), | |||
/* Layer 1: colemak */ | |||
KEYMAP_ANSI( | |||
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ | |||
TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, \ | |||
BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, \ | |||
LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, \ | |||
LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), | |||
/* Layer 2: dvorak */ | |||
KEYMAP_ANSI( | |||
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, \ | |||
TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, \ | |||
CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, \ | |||
LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, \ | |||
LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), | |||
/* Layer3: workman */ | |||
KEYMAP_ANSI( | |||
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ | |||
TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, \ | |||
BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, \ | |||
LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, \ | |||
LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), | |||
/* Layer 4: Poker with Arrow */ | |||
KEYMAP_ANSI( | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ | |||
TRNS,TRNS,TRNS, TRNS, FN1, LEFT,DOWN,RGHT), | |||
/* Layer 5: Poker with Esc */ | |||
KEYMAP_ANSI( | |||
ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | |||
TRNS,TRNS,TRNS, TRNS, FN2, TRNS,TRNS,TRNS), | |||
/* Layer 6: Poker with Arrow and Esc */ | |||
KEYMAP_ANSI( | |||
ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ | |||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ | |||
TRNS,TRNS,TRNS, TRNS, FN3, LEFT,DOWN,RGHT), | |||
/* Layer 7: Poker Fn'd */ | |||
KEYMAP_ANSI( | |||
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | |||
TRNS,FN6, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | |||
TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ | |||
TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ | |||
TRNS,TRNS,TRNS, FN5, FN4, TRNS,TRNS,TRNS), | |||
/* Layer 8: Poker Fn'd arrow */ | |||
KEYMAP_ANSI( | |||
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | |||
TRNS,FN7, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | |||
TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ | |||
TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \ | |||
TRNS,TRNS,TRNS, FN4, FN5, HOME,PGDN,END), | |||
/* Layer 9: Poker Fn'd Esc */ | |||
KEYMAP_ANSI( | |||
GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | |||
TRNS,FN4, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | |||
TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ | |||
TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ | |||
TRNS,TRNS,TRNS, FN7, FN6, TRNS,TRNS,TRNS), | |||
/* Layer 10: Poker Fn'd Arrow + Esc */ | |||
KEYMAP_ANSI( | |||
GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ | |||
TRNS,FN5, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ | |||
TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ | |||
TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \ | |||
TRNS,TRNS,TRNS, FN6, FN7, HOME,PGDN,END), | |||
}; | |||
/* | |||
* Fn action definition | |||
*/ | |||
static const uint16_t PROGMEM fn_actions[] = { | |||
/* Poker Layout */ | |||
[0] = ACTION_LAYER_SET_P(7), // FN0 move to Fn'd when press | |||
[1] = ACTION_LAYER_SET_P(8), // FN1 move to Fn'd arrow when press | |||
[2] = ACTION_LAYER_SET_P(9), // FN2 move to Fn'd Esc when press | |||
[3] = ACTION_LAYER_SET_P(10), // FN3 move to Fn'd arrow + Esc when press | |||
[4] = ACTION_LAYER_SET_R(0), // FN4 move to default when release | |||
[5] = ACTION_LAYER_SET_R(4), // FN5 move to arrow when release | |||
[6] = ACTION_LAYER_SET_R(5), // FN6 move to Esc when release | |||
[7] = ACTION_LAYER_SET_R(6), // FN7 move to arrow + Esc when release | |||
[8] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN8 Task(RControl,RShift+Esc) | |||
}; |