]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - common/action.c
Fix debug code of serial_soft.c
[max/tmk_keyboard.git] / common / action.c
index 6d5336752ed29acd2b7cc8c8b7e8a30b105bec9b..6528cd46c8113f9bf8aa91792e7c707d06d42c75 100644 (file)
@@ -26,6 +26,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "action.h"
 
 
+/* default layer indicates base layer */
+uint8_t default_layer = 0;
+/* current layer indicates active layer at this time */
+uint8_t current_layer = 0;
+
+
 static void process_action(keyrecord_t *record);
 static bool process_tapping(keyrecord_t *record);
 static void waiting_buffer_scan_tap(void);
@@ -201,6 +207,19 @@ void action_exec(keyevent_t event)
     }
 }
 
+static action_t get_action(key_t key)
+{
+    action_t action = action_for_key(current_layer, key);
+
+    /* Transparently use default layer */
+    if (action.code == ACTION_TRANSPARENT) {
+        // TODO: layer stacking
+        action = action_for_key(default_layer, key);
+        debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n");
+    }
+    return action;
+}
+
 static void process_action(keyrecord_t *record)
 {
     keyevent_t event = record->event;
@@ -208,8 +227,7 @@ static void process_action(keyrecord_t *record)
 
     if (IS_NOEVENT(event)) { return; }
 
-    action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col);
-    //debug("action: "); debug_hex16(action.code); if (event.pressed) debug("d\n"); else debug("u\n");
+    action_t action = get_action(event.key);
     debug("ACTION: "); debug_action(action); debug("\n");
 
     switch (action.kind.id) {
@@ -358,6 +376,7 @@ static void process_action(keyrecord_t *record)
                         layer_switch(action.layer.val);
                     }
                     else {
+                        // NOTE: This is needed by legacy keymap support
                         layer_switch(default_layer);
                     }
                     break;
@@ -421,7 +440,7 @@ static void process_action(keyrecord_t *record)
                             unregister_code(action.layer.code);
                         } else {
                             //debug("LAYER_PRESSED: No tap: NO ACTION\n");
-//TODO: this is ok?
+                            // NOTE: This is needed by legacy keymap support
                             debug("LAYER_PRESSED: No tap: return to default layer\n");
                             layer_switch(default_layer);
                         }
@@ -496,12 +515,12 @@ static void process_action(keyrecord_t *record)
 
         /* Extentions */
         case ACT_MACRO:
+            // TODO
             break;
         case ACT_COMMAND:
             break;
         case ACT_FUNCTION:
-            // TODO
-            keymap_call_function(record, action.func.id, action.func.opt);
+            action_function(record, action.func.id, action.func.opt);
             break;
         default:
             break;
@@ -808,7 +827,8 @@ void layer_switch(uint8_t new_layer)
 
 bool is_tap_key(key_t key)
 {
-    action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col);
+    action_t action = get_action(key);
+
     switch (action.kind.id) {
         case ACT_LMODS_TAP:
         case ACT_RMODS_TAP:
@@ -839,7 +859,7 @@ bool is_tap_key(key_t key)
  */
 static void debug_event(keyevent_t event)
 {
-    debug_hex16(event.key.raw);
+    debug_hex16((event.key.row<<8) | event.key.col);
     if (event.pressed) debug("d("); else debug("u(");
     debug_dec(event.time); debug(")");
 }