aboutsummaryrefslogtreecommitdiffstats
path: root/src/Macros.cpp
blob: 27b6b210c43b12edc2aa9659e1c09d4380cdd2f9 (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
/***********************************************************************
 * A firmware Sketch for the Keyboardio Model 01
 * Copyright © 2019 Guilhem Moulin <guilhem@fripost.org>
 *
 * 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 3 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 <Kaleidoscope-OneShot.h>
#include "Macros.h"

/* For the top row, return the num key (not the symbol) when the Control
 * and/or Alt modifier is active.  This is useful with a window manager
 * like i3: without this macro it doesn't see the difference between
 * $mod+R0C2 (switch to workspace #2) and $mod+shift+R0C2 (move focused
 * container to workspace #2), as R0C2 triggers LSHIFT(Key_2).
 *
 * XXX doesn't work with repeats...
 * https://github.com/keyboardio/Kaleidoscope/issues/647
 */
#define TopRow(k1, k2) \
    if (keyToggledOn(keyState)) { \
        if (kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_LeftControl) || \
                ::OneShot.isModifierActive(Key_LeftControl) || \
                kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_RightAlt) || \
                ::OneShot.isModifierActive(Key_RightAlt)) \
            return MACRO(Dr(k2)); \
        else \
            return MACRO(Dr(k1)); \
    };

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
    switch (macroIndex) {
        case AT:        TopRow(LSHIFT(Key_2), Key_2);
        case STAR:      TopRow(LSHIFT(Key_8), Key_3);
        case DOLLAR:    TopRow(LSHIFT(Key_4), Key_4);
        case CARET:     TopRow(LSHIFT(Key_6), Key_5);
        case PERCENT:   TopRow(LSHIFT(Key_5), Key_6);
        case BANG:      TopRow(LSHIFT(Key_1), Key_7);
        case HASH:      TopRow(LSHIFT(Key_3), Key_8);
        case AMPERSAND: TopRow(LSHIFT(Key_7), Key_9);
        case LEFT_BRACKET:  TopRow(LSHIFT(Key_LeftBracket),  Key_1);
        case RIGHT_BRACKET: TopRow(LSHIFT(Key_RightBracket), Key_0);
        default:
            return MACRO_NONE;
    }
}