]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - keyboard/hhkb/keymap_spacefn.c
ibmpc_usb: Fix Disable/Enable keyboard
[max/tmk_keyboard.git] / keyboard / hhkb / keymap_spacefn.c
1 /*
2  * SpaceFN
3  * http://geekhack.org/index.php?topic=51069.0
4  */
5 #include "keymap_common.h"
6
7
8 const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
9     /* Layer 0: Default Layer
10      * ,-----------------------------------------------------------.
11      * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  `|BSp|
12      * |-----------------------------------------------------------|
13      * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|    \|
14      * |-----------------------------------------------------------|
15      * |Contro|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|Enter   |
16      * |-----------------------------------------------------------|
17      * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift |Fn0|
18      * `-----------------------------------------------------------'
19      *       |Gui|Alt  |         SpaceFN       |Alt  |Gui|
20      *       `-------------------------------------------'
21      */
22     KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, GRV, BSPC,  \
23            TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSLS,       \
24            LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,ENT,             \
25            LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,FN0,             \
26                 LGUI,LALT,          FN1,                RALT,RGUI),
27
28     /* Layer 1: HHKB mode (HHKB Fn)
29      * ,-----------------------------------------------------------.
30      * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
31      * |-----------------------------------------------------------|
32      * |Caps |   |   |   |   |   |   |   |Psc|Slk|Pus|Up |   |Backs|
33      * |-----------------------------------------------------------|
34      * |      |VoD|VoU|Mut|   |   |  *|  /|Hom|PgU|Lef|Rig|Enter   |
35      * |-----------------------------------------------------------|
36      * |        |   |   |   |   |   |  +|  -|End|PgD|Dow|      |   |
37      * `-----------------------------------------------------------'
38      *       |   |     |                       |     |   |
39      *       `-------------------------------------------'
40      */ 
41     KEYMAP(PWR, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,   \
42            CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS, UP, TRNS, BSPC,      \
43            TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,PENT,            \
44            TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,TRNS,TRNS,            \
45                 TRNS,TRNS,          SPC,                TRNS,TRNS),
46
47     /* Layer 2: SpaceFN
48      * ,-----------------------------------------------------------.
49      * |`  | F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|   |Del|
50      * |-----------------------------------------------------------|
51      * |     |   |   |Esc|   |   |   |Hom|Up |End|Psc|Slk|Pau|Ins  |
52      * |-----------------------------------------------------------|
53      * |      |   |   |   |   |   |PgU|Lef|Dow|Rig|   |   |        |
54      * |-----------------------------------------------------------|
55      * |        |   |   |   |   |Spc|PgD|`  |~  |   |   |      |   |
56      * `-----------------------------------------------------------'
57      *       |   |     |                       |     |   |
58      *       `-------------------------------------------'
59      */
60     KEYMAP(GRV, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, TRNS,DEL,   \
61            TRNS,TRNS,TRNS,ESC, TRNS,TRNS,TRNS,HOME,FN3, END, PSCR,SLCK,PAUS,INS,        \
62            TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PGUP,LEFT,DOWN,RGHT,TRNS,TRNS,TRNS,            \
63            TRNS,TRNS,TRNS,TRNS,TRNS,SPC, PGDN,GRV, FN2, TRNS,TRNS,TRNS,NO,              \
64                 TRNS,TRNS,          TRNS,               TRNS,TRNS),
65 };
66
67
68 /*
69  * user defined action function
70  */
71 enum function_id {
72     CTRL_SPACE_I,       // Ctrl + Up(SpaceFN) -> PgUp
73 };
74
75 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
76 {
77 #   define MODS_CTRL_MASK   (MOD_BIT(KC_LCTRL)|MOD_BIT(KC_RCTRL))
78     static uint8_t ctrl_space_i_prev_ctrl;
79
80     switch (id) {
81         // Ctrl + Up(SpaceFN) -> PgUp
82         case CTRL_SPACE_I:
83             ctrl_space_i_prev_ctrl = get_mods()&MODS_CTRL_MASK;
84             if (record->event.pressed) {
85                 if (ctrl_space_i_prev_ctrl) {
86                     del_mods(ctrl_space_i_prev_ctrl);   // remove Ctrl
87                     add_key(KC_PGUP);
88                     send_keyboard_report(); // send PgUp without Ctrl
89                     add_mods(ctrl_space_i_prev_ctrl);   // return Ctrl but not sent
90                 } else {
91                     add_key(KC_UP);
92                     send_keyboard_report();
93                 }
94             } else {
95                 if (ctrl_space_i_prev_ctrl) {
96                     del_key(KC_PGUP);
97                     send_keyboard_report();
98                 } else {
99                     del_key(KC_UP);
100                     send_keyboard_report();
101                 }
102             }
103             break;
104     }
105 }
106
107
108 /*
109  * Fn action definition
110  */
111 const action_t PROGMEM fn_actions[] = {
112     [0] = ACTION_LAYER_MOMENTARY(1),
113     [1] = ACTION_LAYER_TAP_KEY(2, KC_SPACE),
114     [2] = ACTION_MODS_KEY(MOD_LSFT, KC_GRV),    // tilde
115     [3] = ACTION_FUNCTION(CTRL_SPACE_I),        // Ctrl + Up(SpaceFN) -> PgUp
116 };