summaryrefslogtreecommitdiff
path: root/users/noroadsleft/noroadsleft.c
blob: 82b0b0568f28fc0dae9bf7893896b82a99cf55b1 (plain)
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
/* Copyright 2020-2021 James Young (@noroadsleft)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "noroadsleft.h"
#include "version.h"

/*******************
** MODIFIER MASKS **
*******************/
bool macroMode = 0;

__attribute__((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; };

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    if (!process_record_keymap(keycode, record)) {
        return false;
    }
#if defined(ANSI_NUBS_ROW) && defined(ANSI_NUBS_COL)
    // if ANSI_NUBS_ROW and ANSI_NUBS_COL are both defined, and Right Alt mod is active
    if ( record->event.key.row == ANSI_NUBS_ROW && record->event.key.col == ANSI_NUBS_COL && get_mods() & MOD_MASK_RALT ) {
        if (record->event.pressed) {
            register_code(KC_NUBS);
        } else {
            unregister_code(KC_NUBS);
        }
        return false;
    }
#endif
    switch (keycode) {
        case VRSN:
            if (record->event.pressed) {
                SEND_STRING(QMK_KEYBOARD ":" QMK_KEYMAP " # @ " QMK_VERSION);
            }
            return false;
        case G_PUSH:
            if (record->event.pressed) {
                SEND_STRING("git push origin ");
            };
            return false;
        case G_FTCH:
            if (record->event.pressed) {
                if ( get_mods() & MOD_MASK_SHIFT ) {
                    clear_mods();
                    SEND_STRING("git pull upstream ");
                } else {
                    SEND_STRING("git fetch upstream ");
                }
            };
            return false;
        case G_BRCH:
            if (record->event.pressed) {
                if ( get_mods() & MOD_MASK_SHIFT ) {
                    clear_mods();
                    SEND_STRING("master");
                } else {
                    SEND_STRING("$(git branch-name)");
                }
            };
            return false;
        case M_SALL:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    SEND_STRING(SS_LGUI("a"));
                } else {
                    SEND_STRING(SS_LCTL("a"));
                }
            }
            return false;
        case M_UNDO:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    if ( get_mods() & MOD_MASK_SHIFT ) {
                        SEND_STRING(SS_LSFT(SS_LGUI("z")));
                    } else {
                        SEND_STRING(SS_LGUI("z"));
                    }
                } else {
                    SEND_STRING(SS_LCTL("z"));
                }
            }
            return false;
        case M_CUT:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    SEND_STRING(SS_LGUI("x"));
                } else {
                    SEND_STRING(SS_LCTL("x"));
                }
            }
            return false;
        case M_COPY:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    SEND_STRING(SS_LGUI("c"));
                } else {
                    SEND_STRING(SS_LCTL("c"));
                }
            }
            return false;
        case M_PASTE:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    if ( get_mods() & MOD_MASK_SHIFT ) {
                        SEND_STRING(SS_LSFT(SS_LALT(SS_LGUI("v"))));
                    } else {
                        SEND_STRING(SS_LGUI("v"));
                    }
                } else {
                    SEND_STRING(SS_LCTL("v"));
                }
            }
            return false;
        case M_MDSWP:
            if (record->event.pressed) {
                macroMode ^= 1;
            }
            return false;
        case KC_1 ... KC_0:
            if (record->event.pressed) {
                if (get_mods() & MOD_MASK_RALT) {
                    register_code(keycode + 0x3B);
                } else {
                    register_code(keycode);
                }
            } else {
                if (get_mods() & MOD_MASK_RALT) {
                    unregister_code(keycode + 0x3B);
                } else {
                    unregister_code(keycode);
                }
            }
            return false;
        case KC_F1 ... KC_F12:
            if (record->event.pressed) {
                if (get_mods() & MOD_MASK_RALT) {
                    register_code(keycode + 0x2E);
                } else {
                    register_code(keycode);
                }
            } else {
                if (get_mods() & MOD_MASK_RALT) {
                    unregister_code(keycode + 0x2E);
                } else {
                    unregister_code(keycode);
                }
            }
            return false;
        case KC_PSCR:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    tap_code16(G(S(KC_3)));
                } else {
                    tap_code(KC_PSCR);
                }
            }
            return false;
        case KC_HOME:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    tap_code16(G(KC_LEFT));
                } else {
                    tap_code(KC_HOME);
                }
            }
            return false;
        case KC_END:
            if (record->event.pressed) {
                if ( macroMode == 1 ) {
                    tap_code16(G(KC_RGHT));
                } else {
                    tap_code(KC_END);
                }
            }
            return false;
    }  // switch()
    return true;
};