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