From 62f423083131586749b3246ac81f2b511db87bf5 Mon Sep 17 00:00:00 2001
From: Guilhem Moulin <guilhem@fripost.org>
Date: Thu, 8 Aug 2019 10:21:52 +0200
Subject: Refactor TopRow() macro.

---
 src/Macros.cpp | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/Macros.cpp b/src/Macros.cpp
index 2fd4229..c8013cc 100644
--- a/src/Macros.cpp
+++ b/src/Macros.cpp
@@ -24,15 +24,20 @@
  * 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 (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)); \
+    if (keyToggledOn(keyState)) { \
+        if (kaleidoscope::hid::isModifierKeyActive(Key_LeftControl) || \
+                ::OneShot.isModifierActive(Key_LeftControl) || \
+                kaleidoscope::hid::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) {
-- 
cgit v1.2.3