]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/ergotravel/keymaps/viet/keymap.c
Merge branch 'master' of github.com:qmk/qmk_firmware into hf/shinydox
[qmk_firmware.git] / keyboards / ergotravel / keymaps / viet / keymap.c
1 #include "ergotravel.h"
2 #include "action_layer.h"
3 #include "eeconfig.h"
4 #include "mousekey.h"
5 #include "process_unicode.h"
6 extern keymap_config_t keymap_config;
7
8 #define _QWERTY 0
9 #define _NUMBERS 1
10 #define _SYMBOLS 2
11 #define _CODING 3
12 #define _NAVIGATION 4
13 #define _ADJUST 16
14
15 enum custom_keycodes {
16   QWERTY = SAFE_RANGE,
17   ADJUST,
18   CODING_SPACE,
19   NUMBERS_SPACE,
20   SYMBOLS_SPACE,
21   NAVIGATE_SPACE,
22   TABLE_FLIP,
23   RESET_TABLE,
24   SHRUG,
25   LOOK_OF_DISAPPROVAL
26 };
27
28 #define KC_ KC_TRNS
29 #define _______ KC_TRNS
30
31 #define KC_ADJT MO(_ADJUST)
32 #define KC_RST RESET
33 #define KC_BL_S BL_STEP
34 #define KC_DBUG DEBUG
35 #define KC_RTOG RGB_TOG
36 #define KC_RMOD RGB_MOD
37 #define KC_RHUI RGB_HUI
38 #define KC_RHUD RGB_HUD
39 #define KC_RSAI RGB_SAI
40 #define KC_RSAD RGB_SAD
41 #define KC_RVAI RGB_VAI
42 #define KC_RVAD RGB_VAD
43
44 #define KC_RSEN MT(MOD_RSFT, KC_ENT) // Tap for enter, hold for right shift
45
46 #define KC_LCCA MT(MOD_LCTL, KC_CAPS)  // Tap for caps lock, hold for left control
47 #define KC_SHDE MT(MOD_LSFT, KC_DEL) // Tap for delete, hold for left shift
48
49 #define KC_NAVI MO(_NAVIGATION)
50
51 #define KC_COSP CODING_SPACE
52 #define KC_NUSP NUMBERS_SPACE
53 #define KC_SYSP SYMBOLS_SPACE
54 #define KC_NASP NAVIGATE_SPACE
55
56 #define KC_FLIP TABLE_FLIP
57 #define KC_TSET RESET_TABLE
58 #define KC_SRUG SHRUG
59 #define KC_DISA LOOK_OF_DISAPPROVAL
60 #define KC_RST RESET
61
62 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
63
64   [_QWERTY] = LAYOUT_kc(
65     //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
66        TAB , Q  , W  , E  , R  , T  ,HOME,      PGUP, Y  , U  , I  , O  , P  ,BSPC,
67     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
68        LCCA, A  , S  , D  , F  , G  ,END ,      PGDN, H  , J  , K  , L  ,SCLN,QUOT,
69     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
70        SHDE, Z  , X  , C  , V  , B  ,LGUI,      RALT, N  , M  ,COMM,DOT ,SLSH,RSEN,
71     //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
72        ESC ,ADJT,LALT,ENT ,NUSP,NASP,                SYSP,COSP,RCTL,NAVI,ADJT,DEL
73     //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
74   ),
75
76   [_NUMBERS] = LAYOUT_kc(
77     //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
78       GRAVE, 1  , 2  , 3  , 4  , 5  ,MPLY,      VOLU,  6  , 7  , 8  , 9  , 0 ,    ,
79     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
80            ,    ,    ,    ,    ,    ,MNXT,      VOLD,FLIP,TSET,SRUG,DISA,    ,    ,
81     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
82            ,    ,    ,    ,    ,    ,    ,          ,    ,    ,    ,    ,    ,    ,
83     //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
84            ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
85     //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
86   ),
87
88   [_SYMBOLS] = LAYOUT_kc(
89     //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
90       GRAVE,EXLM, AT ,HASH,DLR ,PERC,MPLY,      VOLU,CIRC,AMPR,ASTR,LPRN,RPRN,BSLS,
91     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
92            ,    ,    ,    ,    ,    ,MNXT,      VOLD,    ,    ,    ,    ,    ,    ,
93     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
94            ,    ,    ,    ,    ,    ,    ,          ,    ,    ,    ,    ,    ,    ,
95     //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
96            ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
97     //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
98   ),
99
100   [_CODING] = LAYOUT_kc(
101     //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
102            ,    ,    ,LCBR,RCBR,    ,MPLY,      VOLU,    ,AMPR,PIPE,DLR ,    ,    ,
103     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
104            ,    ,    ,LPRN,RPRN,    ,MNXT,      VOLD,    ,UNDS,MINS,ASTR,    ,    ,
105     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
106            ,    ,    ,LBRC,RBRC,    ,    ,          ,    ,PLUS,EQL ,    ,    ,    ,
107     //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
108            ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
109     //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
110   ),
111
112   [_NAVIGATION] = LAYOUT_kc(
113     //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
114            ,    ,    , UP ,    ,    ,MPLY,      VOLU,WH_U,BTN1,MS_U,BTN1,    ,    ,
115     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
116            ,    ,LEFT,DOWN,RGHT,    ,MNXT,      VOLD,WH_D,MS_L,MS_D,MS_R,    ,    ,
117     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
118            ,    ,    ,    ,    ,    ,    ,          ,    ,    ,    ,    ,    ,    ,
119     //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
120            ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
121     //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
122   ),
123
124   [_ADJUST] = LAYOUT_kc(
125     //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
126        F1  ,F2  ,F3  ,F4  ,F5  ,F6  ,    ,          ,F7  ,F8  ,F9  ,F10 ,F11 ,F12 ,
127     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
128            ,RTOG,RVAI,RHUI,RSAI,    ,    ,          ,    ,    ,    ,    ,    ,    ,
129     //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
130            ,RMOD,RVAD,RHUD,RSAD,    ,    ,          ,RST ,    ,    ,    ,    ,    ,
131     //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
132            ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
133     //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
134   )
135
136 };
137
138
139 #ifdef AUDIO_ENABLE
140 float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
141 #endif
142
143 void persistent_default_layer_set(uint16_t default_layer) {
144   eeconfig_update_default_layer(default_layer);
145   default_layer_set(default_layer);
146 }
147
148 uint16_t custom_lt_timer;
149 keypos_t prv_key_pressed;
150 // Runs just one time when the keyboard initializes.
151 void matrix_init_user(void) {
152 //    set_unicode_input_mode(UC_LNX); // Linux
153     set_unicode_input_mode(UC_OSX); // Mac OSX
154 //    set_unicode_input_mode(UC_WIN); // Windows (with registry key, see wiki)
155     //set_unicode_input_mode(UC_WINC); // Windows (with WinCompose, see wiki)
156 };
157
158 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
159
160   if(record->event.pressed) prv_key_pressed = record->event.key;
161     #define IS_KEYPOS_SAME(keyone,keytwo)  ((keyone.col==keytwo.col)&&(keyone.row==keytwo.row))
162     #define ANOTHER_KEY_PRESSED (!IS_KEYPOS_SAME(prv_key_pressed, record->event.key))
163
164   inline void tap(uint16_t keycode) {
165     register_code(keycode);
166     unregister_code(keycode);
167   };
168
169   inline void swapInput(void) {
170     register_code(KC_LGUI);
171     tap(KC_SPC);
172     unregister_code(KC_LGUI);
173   };
174
175   switch (keycode) {
176     case QWERTY:
177       if (record->event.pressed) {
178         #ifdef AUDIO_ENABLE
179           PLAY_SONG(tone_qwerty);
180         #endif
181         persistent_default_layer_set(1UL<<_QWERTY);
182       }
183       return false;
184       break;
185     case CODING_SPACE:
186       if (record->event.pressed) {
187         custom_lt_timer = timer_read();
188         layer_on(_CODING);
189       } else {
190         layer_off(_CODING);
191         if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
192           register_code(KC_SPC);
193           unregister_code(KC_SPC);
194         }
195       }
196       return false;
197       break;
198     case NUMBERS_SPACE:
199       if (record->event.pressed) {
200         custom_lt_timer = timer_read();
201         layer_on(_NUMBERS);
202       } else {
203         layer_off(_NUMBERS);
204         if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
205           register_code(KC_SPC);
206           unregister_code(KC_SPC);
207         }
208       }
209       return false;
210       break;
211     case SYMBOLS_SPACE:
212       if (record->event.pressed) {
213         custom_lt_timer = timer_read();
214         layer_on(_SYMBOLS);
215       } else {
216         layer_off(_SYMBOLS);
217         if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
218           register_code(KC_SPC);
219           unregister_code(KC_SPC);
220         }
221       }
222       return false;
223       break;
224     case NAVIGATE_SPACE:
225       if (record->event.pressed) {
226         custom_lt_timer = timer_read();
227         layer_on(_NAVIGATION);
228       } else {
229         layer_off(_NAVIGATION);
230         if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
231           register_code(KC_SPC);
232           unregister_code(KC_SPC);
233         }
234       }
235       return false;
236       break;
237     case TABLE_FLIP:
238       if (record->event.pressed) {
239         swapInput();
240
241         register_code(KC_RSFT);
242         tap(KC_9);
243         unregister_code(KC_RSFT);
244         process_unicode((0x256F|QK_UNICODE), record);   // Arm
245         process_unicode((0x00B0|QK_UNICODE), record);   // Eye
246         process_unicode((0x25A1|QK_UNICODE), record);   // Mouth
247         process_unicode((0x00B0|QK_UNICODE), record);   // Eye
248         register_code(KC_RSFT);
249         tap(KC_0);
250         unregister_code(KC_RSFT);
251         process_unicode((0x256F|QK_UNICODE), record);   // Arm
252         tap(KC_SPC);
253         process_unicode((0x0361|QK_UNICODE), record);   // Flippy
254         tap(KC_SPC);
255         process_unicode((0x253B|QK_UNICODE), record);   // Table
256         process_unicode((0x2501|QK_UNICODE), record);   // Table
257         process_unicode((0x253B|QK_UNICODE), record);   // Table
258
259         swapInput();
260       }
261       return false;
262       break;
263     case RESET_TABLE: // ┬──┬ ノ( ゜-゜ノ)
264       if (record->event.pressed) {
265         swapInput();
266
267         process_unicode((0x252C|QK_UNICODE), record);   // Table
268         process_unicode((0x2500|QK_UNICODE), record);   // Table
269         process_unicode((0x2500|QK_UNICODE), record);   // Table
270         process_unicode((0x252C|QK_UNICODE), record);   // Table
271         tap(KC_SPC);
272         process_unicode((0x30CE|QK_UNICODE), record);   // Arm
273         register_code(KC_RSFT);
274         tap(KC_9);
275         unregister_code(KC_RSFT);
276         tap(KC_SPC);
277         process_unicode((0x309C|QK_UNICODE), record);   // Eye
278         tap(KC_MINS);
279         process_unicode((0x309C|QK_UNICODE), record);   // Eye
280         process_unicode((0x30CE|QK_UNICODE), record);   // Arm
281         register_code(KC_RSFT);
282         tap(KC_0);
283         unregister_code(KC_RSFT);
284
285         swapInput();
286       }
287       return false;
288       break;
289     case SHRUG: // ¯\_(ツ)_/¯
290       if (record->event.pressed) {
291         swapInput();
292
293         process_unicode((0x00AF|QK_UNICODE), record);   // Hand
294         tap(KC_BSLS);                                   // Arm
295         register_code(KC_RSFT);
296         tap(KC_UNDS);                                   // Arm
297         tap(KC_LPRN);                                   // Head
298         unregister_code(KC_RSFT);
299         process_unicode((0x30C4|QK_UNICODE), record);   // Face
300         register_code(KC_RSFT);
301         tap(KC_RPRN);                                   // Head
302         tap(KC_UNDS);                                   // Arm
303         unregister_code(KC_RSFT);
304         tap(KC_SLSH);                                   // Arm
305         process_unicode((0x00AF|QK_UNICODE), record);   // Hand
306
307         swapInput();
308       }
309       return false;
310       break;
311     case LOOK_OF_DISAPPROVAL:       // ಠ_ಠ
312       if(record->event.pressed){
313         swapInput();
314
315         process_unicode((0x0CA0|QK_UNICODE), record);   // Eye
316         register_code(KC_RSFT);
317         tap(KC_MINS);
318         unregister_code(KC_RSFT);
319         process_unicode((0x0CA0|QK_UNICODE), record);   // Eye
320
321         swapInput();
322       }
323       return false;
324       break;
325   }
326   return true;
327 }