aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-06-25 13:56:52 +0200
committerGuilhem Moulin <guilhem@fripost.org>2019-06-26 01:04:41 +0200
commit461109e695f163303549648d93dc7d9253e88b81 (patch)
treed749711146f8ffd98838f8ada19e342eff0aba5e /src
parent67cc18c9ed357d4ba290d62e2f2836601a19ca2b (diff)
For the top row, return the num key when a 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).
Diffstat (limited to 'src')
-rw-r--r--src/Macros.cpp52
-rw-r--r--src/Macros.h37
-rw-r--r--src/keymap.h31
-rw-r--r--src/model01.ino2
4 files changed, 102 insertions, 20 deletions
diff --git a/src/Macros.cpp b/src/Macros.cpp
new file mode 100644
index 0000000..2fd4229
--- /dev/null
+++ b/src/Macros.cpp
@@ -0,0 +1,52 @@
+/***********************************************************************
+ * 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).
+ */
+#define TopRow(k1, k2) \
+ if (kaleidoscope::hid::isModifierKeyActive(Key_LeftControl) || \
+ ::OneShot.isModifierActive(Key_LeftControl) || \
+ kaleidoscope::hid::isModifierKeyActive(Key_RightAlt) || \
+ ::OneShot.isModifierActive(Key_RightAlt)) \
+ return MACRODOWN(Tr(k2)); \
+ else \
+ return MACRODOWN(Tr(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;
+ }
+}
diff --git a/src/Macros.h b/src/Macros.h
new file mode 100644
index 0000000..829308c
--- /dev/null
+++ b/src/Macros.h
@@ -0,0 +1,37 @@
+/***********************************************************************
+ * 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/>.
+ **********************************************************************/
+
+#pragma once
+
+#include <Kaleidoscope-Macros.h>
+
+enum {
+ LEFT_BRACKET
+ , AT
+ , STAR
+ , DOLLAR
+ , CARET
+
+ , PERCENT
+ , BANG
+ , HASH
+ , AMPERSAND
+ , RIGHT_BRACKET
+};
+
+extern const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
diff --git a/src/keymap.h b/src/keymap.h
index 2f4d5bd..35826f3 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -19,6 +19,8 @@
#pragma once
+#include "Macros.h"
+
/* Layers */
enum {
DVORAK
@@ -28,36 +30,25 @@ enum {
, LAYER_MAX = NUM
};
-#define Key_AT LSHIFT(Key_2)
-#define Key_STAR LSHIFT(Key_8)
-#define Key_DOLLR LSHIFT(Key_4)
-#define Key_CARET LSHIFT(Key_6)
-#define Key_PRCNT LSHIFT(Key_5)
-#define Key_EXCLM LSHIFT(Key_1)
-#define Key_HASH LSHIFT(Key_3)
-#define Key_AND LSHIFT(Key_7)
-#define Key_LCB LSHIFT(Key_LeftBracket)
-#define Key_RCB LSHIFT(Key_RightBracket)
-#define Key_Plus LSHIFT(Key_Equals)
-
#define Key_PlayPause Consumer_PlaySlashPause
+#define Key_Plus LSHIFT(Key_Equals)
#define Key_Underscore LSHIFT(Key_Minus)
/* Keymaps */
KEYMAPS(
[DVORAK] = KEYMAP_STACKED(
- ___, Key_LCB, Key_AT, Key_STAR, Key_DOLLR, Key_CARET, ___
- , Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, TD(LPB)
- , Key_Tab, Key_A, Key_O, Key_E, Key_U, Key_I
- , Key_Menu, Key_Slash, Key_Q, Key_J, Key_K, Key_X, TD(COLON)
+ ___, M(LEFT_BRACKET), M(AT), M(STAR), M(DOLLAR), M(CARET), ___
+ , Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, TD(LPB)
+ , Key_Tab, Key_A, Key_O, Key_E, Key_U, Key_I
+ , Key_Menu, Key_Slash, Key_Q, Key_J, Key_K, Key_X, TD(COLON)
, OSM(LeftControl), Key_Backspace, OSM(LeftShift), Key_Escape
, OSL(NAV)
- , ___, Key_PRCNT, Key_EXCLM, Key_HASH, Key_AND, Key_RCB, ___
- , TD(RPB), Key_F, Key_G, Key_C, Key_R, Key_L, Key_Backslash
- , Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus
- , Key_Equals, Key_B, Key_M, Key_W, Key_V, Key_Z, ___
+ , ___, M(PERCENT), M(BANG), M(HASH), M(AMPERSAND), M(RIGHT_BRACKET), ___
+ , TD(RPB), Key_F, Key_G, Key_C, Key_R, Key_L, Key_Backslash
+ , Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus
+ , Key_Equals, Key_B, Key_M, Key_W, Key_V, Key_Z, ___
, ___, Key_Enter, Key_Spacebar, OSM(RightAlt)
, OSL(NUM)
diff --git a/src/model01.ino b/src/model01.ino
index 3a714d7..03ad6c2 100644
--- a/src/model01.ino
+++ b/src/model01.ino
@@ -28,6 +28,7 @@
#include <Kaleidoscope-MouseKeys.h>
#include <Kaleidoscope-Unicode.h>
+#include "Macros.h"
#include "TapDance.h"
#include "keymap.h"
@@ -43,6 +44,7 @@ KALEIDOSCOPE_INIT_PLUGINS(
, OneShot
, EscapeOneShot
, ActiveModColorEffect
+ , Macros
);
void setup() {