summaryrefslogtreecommitdiff
path: root/users/pdl/pdl.c
blob: 5b90a0b3102d6f7c16984379b50dd7c151e247bb (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
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
/*
Copyright 2018-2021 Daniel Perrett

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 "pdl.h"

// unshifted
//
// regardless of current mods, send this character in an unshifted state

__attribute__ ((weak))
bool unshifted (uint16_t keycode, keyrecord_t *record) {
    uint8_t mods;

    if (record->event.pressed) {
        mods = keyboard_report->mods & EITHER_SHIFT;

        if (mods) {
            unregister_mods(mods);
            register_code(keycode);
            register_mods(mods);
        } else {
            register_code(keycode);
        }

        return false;
    } else {
        return true;
    }
}

/*
 * update_punctn_coding_layer_state
 *
 * Check NAVIGN and NUMBRS layers. If one is activated, also activate PUNCTN. If both are activated, also activate CODING.
 */

__attribute__ ((weak))
uint32_t update_punctn_coding_layer_state(uint32_t state) {
    uint32_t maskEither = (1UL << _NAVIGN) | (1UL << _NUMBRS);
    uint32_t maskPunctn = 1UL << _PUNCTN;
    uint32_t maskCoding = 1UL << _CODING;

#ifdef COMBO_PDL
    return (
        (state & maskEither)
        ? (state | maskPunctn) & ~maskCoding  // either  => punctn
        : (state & ~maskCoding) & ~maskPunctn // neither => neither
    );
#endif

    return (
        (state & maskEither)
        ? (state & maskEither) == maskEither
            ? (state & ~maskPunctn) | maskCoding // both    => coding
            : (state | maskPunctn) & ~maskCoding // either  => punctn
        : (state & ~maskCoding) & ~maskPunctn    // neither => neither
    );
}

__attribute__ ((weak))
uint32_t layer_state_set_user(uint32_t state) {
    return update_punctn_coding_layer_state(state);
}

__attribute__ ((weak))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
            if (record->event.pressed) {
                // ensure that the toggled layer is switched off by a single tap
                layer_off(keycode & 0xFF);
            }
            break;
        case QWERTY:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_QWERTY);
            }
            return false;
            break;
        case PROXIM:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_PROXIM);
            }
            return false;
            break;
        // KC_LBRC, KC_NUHS, KC_GRV, KC_RBRC [#`]
        // These four keys are unshifted in the UK layout and should be sent as such.
        case KU_LBRC:
            return unshifted(KC_LBRC, record);
        case KU_NUHS:
            return unshifted(KC_NUHS, record);
        case KU_GRV:
            return unshifted(KC_GRV, record);
        case KU_RBRC:
            return unshifted(KC_RBRC, record);
        case KC_ESC:
            if (!record->event.pressed) {
                layer_off(_NUMBRS);
                layer_off(_NAVIGN);
                layer_off(_PUNCTN);
                layer_off(_CODING);
            }
            return true;
    }
    return true;
}

#ifdef COMBO_PDL
enum combos {
    VCOMBO_PU,
    VCOMBO_NU,
    VCOMBO_EU,
    VCOMBO_IU,
    VCOMBO_LU,
    VCOMBO_PD,
    VCOMBO_ND,
    VCOMBO_ED,
    VCOMBO_ID,
    VCOMBO_LD,
    HCOMBO_JR,
    HCOMBO_UR,
    HCOMBO_PR,
    HCOMBO_MR,
    HCOMBO_HR,
    XCOMBO_LEFT,
    XCOMBO_RIGHT,
    XCOMBO_UP,
    XCOMBO_DOWN,
    XCOMBO_ENTER,
    XCOMBO_DEL,
    XCOMBO_BKSP,
    XCOMBO_MINS,
    XCOMBO_TAB,
    XCOMBO_UNDO,
    XCOMBO_REDO,
    XCOMBO_PGUP,
    XCOMBO_PGDN
};

const uint16_t PROGMEM vcombo_pu[] = {KC_J,    KC_P, COMBO_END};
const uint16_t PROGMEM vcombo_nu[] = {KC_Y,    KC_N, COMBO_END};
const uint16_t PROGMEM vcombo_eu[] = {KC_O,    KC_E, COMBO_END};
const uint16_t PROGMEM vcombo_iu[] = {KC_U,    KC_I, COMBO_END};
const uint16_t PROGMEM vcombo_lu[] = {KC_QUOT, KC_L, COMBO_END};
const uint16_t PROGMEM vcombo_pd[] = {KC_M,    KC_P, COMBO_END};
const uint16_t PROGMEM vcombo_nd[] = {KC_H,    KC_N, COMBO_END};
const uint16_t PROGMEM vcombo_ed[] = {KC_COMM, KC_E, COMBO_END};
const uint16_t PROGMEM vcombo_id[] = {KC_DOT,  KC_I, COMBO_END};
const uint16_t PROGMEM vcombo_ld[] = {KC_SLSH, KC_L, COMBO_END};
const uint16_t PROGMEM hcombo_jr[] = {KC_J,    KC_Y, COMBO_END};
const uint16_t PROGMEM hcombo_ur[] = {KC_QUOT, KC_U, COMBO_END};
const uint16_t PROGMEM hcombo_pr[] = {KC_P,    KC_N, COMBO_END};
const uint16_t PROGMEM hcombo_mr[] = {KC_M,    KC_H, COMBO_END};
const uint16_t PROGMEM hcombo_hr[] = {KC_COMM, KC_H, COMBO_END};

const uint16_t PROGMEM xcombo_left[]   = {KC_K, KC_P, COMBO_END};
const uint16_t PROGMEM xcombo_right[]  = {KC_M, KC_G, COMBO_END};
const uint16_t PROGMEM xcombo_up[]     = {KC_B, KC_J, COMBO_END};
const uint16_t PROGMEM xcombo_down[]   = {KC_K, KC_M, COMBO_END};
const uint16_t PROGMEM xcombo_enter[]  = {KC_G, KC_P, COMBO_END};
const uint16_t PROGMEM xcombo_del[]    = {KC_M, KC_B, COMBO_END};
const uint16_t PROGMEM xcombo_bksp[]   = {KC_K, KC_J, COMBO_END};
const uint16_t PROGMEM xcombo_mins[]   = {KC_V, KC_H, COMBO_END};
const uint16_t PROGMEM xcombo_tab[]    = {KC_V, KC_K, COMBO_END};
const uint16_t PROGMEM xcombo_undo[]   = {KC_V, KC_J, COMBO_END};
const uint16_t PROGMEM xcombo_redo[]   = {KC_B, KC_H, COMBO_END};
const uint16_t PROGMEM xcombo_pgup[]   = {KC_G, KC_B, COMBO_END};
const uint16_t PROGMEM xcombo_pgdn[]   = {KC_G, KC_K, COMBO_END};

combo_t key_combos[COMBO_COUNT] = {
    [VCOMBO_PU] = COMBO(vcombo_pu, KC_CIRC),
    [VCOMBO_NU] = COMBO(vcombo_nu, KC_LBRC),
    [VCOMBO_EU] = COMBO(vcombo_eu, LSFT(KC_9)),
    [VCOMBO_IU] = COMBO(vcombo_iu, LSFT(KC_0)),
    [VCOMBO_LU] = COMBO(vcombo_lu, KC_RBRC),
    [VCOMBO_PD] = COMBO(vcombo_pd, LSFT(KC_7)),
    [VCOMBO_ND] = COMBO(vcombo_nd, KC_EQL),
    [VCOMBO_ED] = COMBO(vcombo_ed, KC_MINS),
    [VCOMBO_ID] = COMBO(vcombo_id, LSFT(KC_1)),
    [VCOMBO_LD] = COMBO(vcombo_ld, LSFT(KC_5)),
    [HCOMBO_JR] = COMBO(hcombo_jr, KC_GRV),
    [HCOMBO_UR] = COMBO(hcombo_ur, LSFT(KC_2)),
    [HCOMBO_PR] = COMBO(hcombo_pr, LSFT(KC_8)),
    [HCOMBO_MR] = COMBO(hcombo_mr, KC_NUHS),
    [HCOMBO_HR] = COMBO(hcombo_hr, KC_NUBS),

    [XCOMBO_LEFT]   = COMBO(xcombo_left,  KC_LEFT),
    [XCOMBO_RIGHT]  = COMBO(xcombo_right, KC_RGHT),
    [XCOMBO_UP]     = COMBO(xcombo_up,    KC_UP),
    [XCOMBO_DOWN]   = COMBO(xcombo_down,  KC_DOWN),
    [XCOMBO_ENTER]  = COMBO(xcombo_enter, KC_ENT),
    [XCOMBO_DEL]    = COMBO(xcombo_del,   KC_DEL),
    [XCOMBO_BKSP]   = COMBO(xcombo_bksp,  KC_BSPC),
    [XCOMBO_MINS]   = COMBO(xcombo_mins,  KC_MINS),
    [XCOMBO_TAB]    = COMBO(xcombo_tab,   KC_TAB),
    [XCOMBO_UNDO]   = COMBO(xcombo_undo,  LCTL(KC_Y)),
    [XCOMBO_REDO]   = COMBO(xcombo_redo,  LCTL(KC_Z)),
    [XCOMBO_PGUP]   = COMBO(xcombo_pgup,  KC_PGUP),
    [XCOMBO_PGDN]   = COMBO(xcombo_pgdn,  KC_PGDN)
};

#endif