aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/ergotravel/keymaps/viet/keymap.c
blob: dd7fffcc69e0bf7b23901f29288dbba27a70d28e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "ergotravel.h"
#include "action_layer.h"
#include "eeconfig.h"
#include "mousekey.h"
#include "process_unicode.h"
extern keymap_config_t keymap_config;

#define _QWERTY 0
#define _NUMBERS 1
#define _SYMBOLS 2
#define _CODING 3
#define _NAVIGATION 4
#define _ADJUST 16

enum custom_keycodes {
  QWERTY = SAFE_RANGE,
  ADJUST,
  CODING_SPACE,
  NUMBERS_SPACE,
  SYMBOLS_SPACE,
  NAVIGATE_SPACE,
  TABLE_FLIP,
  RESET_TABLE,
  SHRUG,
  LOOK_OF_DISAPPROVAL
};

#define KC_ KC_TRNS

#define KC_ADJT MO(_ADJUST)
#define KC_RST RESET
#define KC_BL_S BL_STEP
#define KC_DBUG DEBUG
#define KC_RTOG RGB_TOG
#define KC_RMOD RGB_MOD
#define KC_RHUI RGB_HUI
#define KC_RHUD RGB_HUD
#define KC_RSAI RGB_SAI
#define KC_RSAD RGB_SAD
#define KC_RVAI RGB_VAI
#define KC_RVAD RGB_VAD

#define KC_RSEN MT(MOD_RSFT, KC_ENT) // Tap for enter, hold for right shift

#define KC_LCCA MT(MOD_LCTL, KC_CAPS)  // Tap for caps lock, hold for left control
#define KC_SHDE MT(MOD_LSFT, KC_DEL) // Tap for delete, hold for left shift

#define KC_NAVI MO(_NAVIGATION)

#define KC_COSP CODING_SPACE
#define KC_NUSP NUMBERS_SPACE
#define KC_SYSP SYMBOLS_SPACE
#define KC_NASP NAVIGATE_SPACE

#define KC_FLIP TABLE_FLIP
#define KC_TSET RESET_TABLE
#define KC_SRUG SHRUG
#define KC_DISA LOOK_OF_DISAPPROVAL
#define KC_RST RESET

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

  [_QWERTY] = LAYOUT_kc(
    //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
       TAB , Q  , W  , E  , R  , T  ,HOME,      PGUP, Y  , U  , I  , O  , P  ,BSPC,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
       LCCA, A  , S  , D  , F  , G  ,END ,      PGDN, H  , J  , K  , L  ,SCLN,QUOT,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
       SHDE, Z  , X  , C  , V  , B  ,LGUI,      RALT, N  , M  ,COMM,DOT ,SLSH,RSEN,
    //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
       ESC ,ADJT,LALT,ENT ,NUSP,NASP,                SYSP,COSP,RCTL,NAVI,ADJT,DEL
    //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
  ),

  [_NUMBERS] = LAYOUT_kc(
    //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
      GRAVE, 1  , 2  , 3  , 4  , 5  ,MPLY,      VOLU,  6  , 7  , 8  , 9  , 0 ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,MNXT,      VOLD,FLIP,TSET,SRUG,DISA,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,    ,          ,    ,    ,    ,    ,    ,    ,
    //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
    //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
  ),

  [_SYMBOLS] = LAYOUT_kc(
    //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
      GRAVE,EXLM, AT ,HASH,DLR ,PERC,MPLY,      VOLU,CIRC,AMPR,ASTR,LPRN,RPRN,BSLS,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,MNXT,      VOLD,    ,    ,    ,    ,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,    ,          ,    ,    ,    ,    ,    ,    ,
    //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
    //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
  ),

  [_CODING] = LAYOUT_kc(
    //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
           ,    ,    ,LCBR,RCBR,    ,MPLY,      VOLU,    ,AMPR,PIPE,DLR ,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,LPRN,RPRN,    ,MNXT,      VOLD,    ,UNDS,MINS,ASTR,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,LBRC,RBRC,    ,    ,          ,    ,PLUS,EQL ,    ,    ,    ,
    //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
    //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
  ),

  [_NAVIGATION] = LAYOUT_kc(
    //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
           ,    ,    , UP ,    ,    ,MPLY,      VOLU,WH_U,BTN1,MS_U,BTN1,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,LEFT,DOWN,RGHT,    ,MNXT,      VOLD,WH_D,MS_L,MS_D,MS_R,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,    ,          ,    ,    ,    ,    ,    ,    ,
    //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
    //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
  ),

  [_ADJUST] = LAYOUT_kc(
    //,----+----+----+----+----+----+----.     ,----+----+----+----+----+----+----.
       F1  ,F2  ,F3  ,F4  ,F5  ,F6  ,    ,          ,F7  ,F8  ,F9  ,F10 ,F11 ,F12 ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,RTOG,RVAI,RHUI,RSAI,    ,    ,          ,    ,    ,    ,    ,    ,    ,
    //|----+----+----+----+----+----+----|     |----+----+----+----+----+----+----|
           ,RMOD,RVAD,RHUD,RSAD,    ,    ,          ,RST ,    ,    ,    ,    ,    ,
    //|----+----+----+----+----+----+----.     .----+----+----+----+----+----+----|
           ,    ,    ,    ,    ,    ,                    ,    ,    ,    ,    ,
    //`----+----+----+--+-+----/----/               \----\----+----+----+----+----'
  )

};


#ifdef AUDIO_ENABLE
float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
#endif

void persistent_default_layer_set(uint16_t default_layer) {
  eeconfig_update_default_layer(default_layer);
  default_layer_set(default_layer);
}

uint16_t custom_lt_timer;
keypos_t prv_key_pressed;
// Runs just one time when the keyboard initializes.
void matrix_init_user(void) {
//    set_unicode_input_mode(UC_LNX); // Linux
    set_unicode_input_mode(UC_OSX); // Mac OSX
//    set_unicode_input_mode(UC_WIN); // Windows (with registry key, see wiki)
    //set_unicode_input_mode(UC_WINC); // Windows (with WinCompose, see wiki)
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {

  if(record->event.pressed) prv_key_pressed = record->event.key;
    #define IS_KEYPOS_SAME(keyone,keytwo)  ((keyone.col==keytwo.col)&&(keyone.row==keytwo.row))
    #define ANOTHER_KEY_PRESSED (!IS_KEYPOS_SAME(prv_key_pressed, record->event.key))

  inline void tap(uint16_t keycode) {
    register_code(keycode);
    unregister_code(keycode);
  };

  inline void swapInput(void) {
    register_code(KC_LGUI);
    tap(KC_SPC);
    unregister_code(KC_LGUI);
  };

  switch (keycode) {
    case QWERTY:
      if (record->event.pressed) {
        #ifdef AUDIO_ENABLE
          PLAY_SONG(tone_qwerty);
        #endif
        persistent_default_layer_set(1UL<<_QWERTY);
      }
      return false;
      break;
    case CODING_SPACE:
      if (record->event.pressed) {
        custom_lt_timer = timer_read();
        layer_on(_CODING);
      } else {
        layer_off(_CODING);
        if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
        }
      }
      return false;
      break;
    case NUMBERS_SPACE:
      if (record->event.pressed) {
        custom_lt_timer = timer_read();
        layer_on(_NUMBERS);
      } else {
        layer_off(_NUMBERS);
        if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
        }
      }
      return false;
      break;
    case SYMBOLS_SPACE:
      if (record->event.pressed) {
        custom_lt_timer = timer_read();
        layer_on(_SYMBOLS);
      } else {
        layer_off(_SYMBOLS);
        if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
        }
      }
      return false;
      break;
    case NAVIGATE_SPACE:
      if (record->event.pressed) {
        custom_lt_timer = timer_read();
        layer_on(_NAVIGATION);
      } else {
        layer_off(_NAVIGATION);
        if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
        }
      }
      return false;
      break;
    case TABLE_FLIP:
      if (record->event.pressed) {
        swapInput();

        register_code(KC_RSFT);
        tap(KC_9);
        unregister_code(KC_RSFT);
        process_unicode((0x256F|QK_UNICODE), record);   // Arm
        process_unicode((0x00B0|QK_UNICODE), record);   // Eye
        process_unicode((0x25A1|QK_UNICODE), record);   // Mouth
        process_unicode((0x00B0|QK_UNICODE), record);   // Eye
        register_code(KC_RSFT);
        tap(KC_0);
        unregister_code(KC_RSFT);
        process_unicode((0x256F|QK_UNICODE), record);   // Arm
        tap(KC_SPC);
        process_unicode((0x0361|QK_UNICODE), record);   // Flippy
        tap(KC_SPC);
        process_unicode((0x253B|QK_UNICODE), record);   // Table
        process_unicode((0x2501|QK_UNICODE), record);   // Table
        process_unicode((0x253B|QK_UNICODE), record);   // Table

        swapInput();
      }
      return false;
      break;
    case RESET_TABLE: // ┬──┬ ノ( ゜-゜ノ)
      if (record->event.pressed) {
        swapInput();

        process_unicode((0x252C|QK_UNICODE), record);   // Table
        process_unicode((0x2500|QK_UNICODE), record);   // Table
        process_unicode((0x2500|QK_UNICODE), record);   // Table
        process_unicode((0x252C|QK_UNICODE), record);   // Table
        tap(KC_SPC);
        process_unicode((0x30CE|QK_UNICODE), record);   // Arm
        register_code(KC_RSFT);
        tap(KC_9);
        unregister_code(KC_RSFT);
        tap(KC_SPC);
        process_unicode((0x309C|QK_UNICODE), record);   // Eye
        tap(KC_MINS);
        process_unicode((0x309C|QK_UNICODE), record);   // Eye
        process_unicode((0x30CE|QK_UNICODE), record);   // Arm
        register_code(KC_RSFT);
        tap(KC_0);
        unregister_code(KC_RSFT);

        swapInput();
      }
      return false;
      break;
    case SHRUG: // ¯\_(ツ)_/¯
      if (record->event.pressed) {
        swapInput();

        process_unicode((0x00AF|QK_UNICODE), record);   // Hand
        tap(KC_BSLS);                                   // Arm
        register_code(KC_RSFT);
        tap(KC_UNDS);                                   // Arm
        tap(KC_LPRN);                                   // Head
        unregister_code(KC_RSFT);
        process_unicode((0x30C4|QK_UNICODE), record);   // Face
        register_code(KC_RSFT);
        tap(KC_RPRN);                                   // Head
        tap(KC_UNDS);                                   // Arm
        unregister_code(KC_RSFT);
        tap(KC_SLSH);                                   // Arm
        process_unicode((0x00AF|QK_UNICODE), record);   // Hand

        swapInput();
      }
      return false;
      break;
    case LOOK_OF_DISAPPROVAL:       // ಠ_ಠ
      if(record->event.pressed){
        swapInput();

        process_unicode((0x0CA0|QK_UNICODE), record);   // Eye
        register_code(KC_RSFT);
        tap(KC_MINS);
        unregister_code(KC_RSFT);
        process_unicode((0x0CA0|QK_UNICODE), record);   // Eye

        swapInput();
      }
      return false;
      break;
  }
  return true;
}