]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - keyboard/hhkb/unimap_hasu.c
core: Clean up code of Locking key support
[max/tmk_keyboard.git] / keyboard / hhkb / unimap_hasu.c
1 /*
2 Copyright 2016 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "unimap_trans.h"
18
19
20 /* id for user defined functions */
21 enum function_id {
22     LSHIFT_LPAREN,
23 };
24
25 enum macro_id {
26     HELLO,
27     VOLUP,
28     ALT_TAB,
29 };
30
31 #define AC_L1      ACTION_LAYER_MOMENTARY(1)
32 #define AC_SLS2    ACTION_LAYER_TAP_KEY(2, KC_SLSH)
33 #define AC_SCL3    ACTION_LAYER_TAP_KEY(3, KC_SCLN)
34 #define AC_SPC4    ACTION_LAYER_TAP_KEY(4, KC_SPC)
35 #define AC_APSW    ACTION_MACRO(ALT_TAB)
36 #define AC_BACK    ACTION_MODS_KEY(MOD_LALT, KC_LEFT)
37 #define AC_FRWD    ACTION_MODS_KEY(MOD_LALT, KC_RIGHT)
38 #define AC_ENT_    ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT)
39
40 // Display Brightness Control
41 // https://github.com/tmk/tmk_keyboard/issues/370#issuecomment-279113313
42 // BRTI(increment) and BRTD(decrement) are defined in actionmap.h
43
44 // Function: LShift with tap '('
45 #define AC_LPRN     ACTION_FUNCTION_TAP(LSHIFT_LPAREN)
46 // Macro: say hello
47 #define AC_HELO     ACTION_MACRO(HELLO)
48
49
50 #ifdef KEYMAP_SECTION_ENABLE
51 const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
52 #else
53 const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = {
54 #endif
55     [0] = UNIMAP_HHKB(
56     ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSLS,GRV ,
57     TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,     BSPC,
58     LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,          ENT_,
59     LSFT,     Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLS2,     RSFT,L1,
60          LGUI,LALT,               SPC4,                    RALT,RGUI),
61
62     [1] = UNIMAP_HHKB(
63     PWR, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,
64     CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP,  TRNS,     TRNS,
65     TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,          PENT,
66     TRNS,     BRTD,BRTI,SLEP,WAKE,TRNS,PPLS,PMNS,END, PGDN,DOWN,     TRNS,TRNS,
67          TRNS,TRNS,               TRNS,                    TRNS,TRNS),
68
69     [2] = UNIMAP_HHKB(
70     GRV, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,
71     TAB, HOME,PGDN,UP,  PGUP,END, HOME,PGDN,PGUP,END, NO,  NO,  NO,       BSPC,
72     LCTL,NO,  LEFT,DOWN,RGHT,NO,  LEFT,DOWN,UP,  RGHT,NO,  NO,            ENT,
73     LSFT,     NO,  NO,  NO,  NO,  NO,  HOME,PGDN,PGUP,END, TRNS,     RSFT,TRNS,
74          LGUI,LALT,               SPC,                     RALT,RGUI),
75
76     [3] = UNIMAP_HHKB(
77     GRV, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,
78     TAB, NO,  NO,  NO,  NO,  NO,  WH_L,WH_D,MS_U,WH_U,WH_R,BACK,FRWD,     TAB,
79     LCTL,ACL0,ACL1,ACL2,ACL2,NO,  NO,  MS_L,MS_D,MS_R,TRNS,NO,            ENT,
80     LSFT,     NO,  NO,  NO,  NO,  BTN3,BTN2,BTN1,BACK,FRWD,NO,       RSFT,TRNS,
81          LGUI,LALT,               BTN1,                    TRNS,TRNS),
82
83     [4] = UNIMAP_HHKB(
84     GRV, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,
85     TAB, NO,  NO,  NO,  NO,  NO,  WH_L,WH_D,MS_U,WH_U,WH_R,BTN4,BTN5,     TAB,
86     LCTL,VOLD,VOLU,MUTE,NO,  NO,  NO,  MS_L,MS_D,MS_R,BTN1,NO,            ENT,
87     LSFT,     NO,  NO,  NO,  NO,  BTN3,BTN2,BTN1,BACK,FRWD,NO,       RSFT,TRNS,
88          TRNS,TRNS,               TRNS,                    TRNS,TRNS),
89 };
90
91
92
93 /*
94  * Macro definition
95  */
96 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
97 {
98     switch (id) {
99         case HELLO:
100             return (record->event.pressed ?
101                     MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
102                     MACRO_NONE );
103         case VOLUP:
104             return (record->event.pressed ?
105                     MACRO( D(VOLU), U(VOLU), END ) :
106                     MACRO_NONE );
107         case ALT_TAB:
108             // XXX: doesn't work after stuck key fix
109             return (record->event.pressed ?
110                     MACRO( D(LALT), D(TAB), END ) :
111                     MACRO( U(TAB), END ));
112     }
113     return MACRO_NONE;
114 }
115
116
117
118 /*
119  * user defined action function
120  */
121 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
122 {
123     if (record->event.pressed) dprint("P"); else dprint("R");
124     dprintf("%d", record->tap.count);
125     if (record->tap.interrupted) dprint("i");
126     dprint("\n");
127
128     switch (id) {
129         case LSHIFT_LPAREN:
130             // XXX: doesn't work with other tap key. iffy at least
131             // Shift parentheses example: LShft + tap '('
132             // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
133             // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
134             if (record->event.pressed) {
135                 if (record->tap.count > 0 && !record->tap.interrupted) {
136                     if (record->tap.interrupted) {
137                         dprint("tap interrupted\n");
138                         register_mods(MOD_BIT(KC_LSHIFT));
139                     }
140                 } else {
141                     register_mods(MOD_BIT(KC_LSHIFT));
142                 }
143             } else {
144                 if (record->tap.count > 0 && !(record->tap.interrupted)) {
145                     add_weak_mods(MOD_BIT(KC_LSHIFT));
146                     send_keyboard_report();
147                     register_code(KC_9);
148                     unregister_code(KC_9);
149                     del_weak_mods(MOD_BIT(KC_LSHIFT));
150                     send_keyboard_report();
151                     record->tap.count = 0;  // ad hoc: cancel tap
152                 } else {
153                     unregister_mods(MOD_BIT(KC_LSHIFT));
154                 }
155             }
156             break;
157     }
158 }