]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - common/action.c
Add NO_PRINT and NO_DEBUG config options.
[max/tmk_keyboard.git] / common / action.c
index 7f3e236f0413e3267931be2b9c7ed63b203c5b4c..4fafbfa79f58f86a0c1cf1638f859efa2fc3b1f2 100644 (file)
@@ -23,6 +23,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "command.h"
 #include "util.h"
 #include "debug.h"
+#include "led.h"
 #include "layer_switch.h"
 #include "action_macro.h"
 #include "action.h"
@@ -360,6 +361,7 @@ static void process_action(keyrecord_t *record)
                 case OP_RESET:
                     switch (action.layer.val & 0x03) {
                         case 0:
+                            // NOTE: reserved
                             overlay_clear();
                             keymap_clear();
                             break;
@@ -379,26 +381,21 @@ static void process_action(keyrecord_t *record)
                             overlay_clear();
                             keymap_clear();
                             break;
+                        /* NOTE: 4-7 rserved */
                     }
                     break;
                 /* Keymap Reset default layer */
                 case (OP_RESET | ON_PRESS):
                     if (event.pressed) {
-                        overlay_clear();
-                        keymap_clear();
                         default_layer_set(action.layer.val);
                     }
                     break;
                 case (OP_RESET | ON_RELEASE):
                     if (!event.pressed) {
-                        overlay_clear();
-                        keymap_clear();
                         default_layer_set(action.layer.val);
                     }
                     break;
                 case (OP_RESET | ON_BOTH):
-                    overlay_clear();
-                    keymap_clear();
                     default_layer_set(action.layer.val);
                     break;
 
@@ -525,6 +522,7 @@ static void process_action(keyrecord_t *record)
                 // Overlay Invert bit4
                 case OP_INV4 | 0:
                     if (action.layer.val == 0) {
+                        // NOTE: reserved for future use
                         overlay_clear();
                     } else {
                         overlay_set(overlay_stat ^ action.layer.val);
@@ -532,6 +530,7 @@ static void process_action(keyrecord_t *record)
                     break;
                 case OP_INV4 | 1:
                     if (action.layer.val == 0) {
+                        // on pressed
                         if (event.pressed) overlay_clear();
                     } else {
                         overlay_set(overlay_stat ^ action.layer.val<<4);
@@ -539,6 +538,7 @@ static void process_action(keyrecord_t *record)
                     break;
                 case OP_INV4 | 2:
                     if (action.layer.val == 0) {
+                        // on released
                         if (!event.pressed) overlay_clear();
                     } else {
                         overlay_set(overlay_stat ^ action.layer.val<<8);
@@ -546,6 +546,7 @@ static void process_action(keyrecord_t *record)
                     break;
                 case OP_INV4 | 3:
                     if (action.layer.val == 0) {
+                        // on both
                         overlay_clear();
                     } else {
                         overlay_set(overlay_stat ^ action.layer.val<<12);
@@ -889,6 +890,18 @@ void register_code(uint8_t code)
     if (code == KC_NO) {
         return;
     }
+#ifdef CAPSLOCK_LOCKING_ENABLE
+    else if (KC_LOCKING_CAPS == code) {
+#ifdef CAPSLOCK_LOCKING_RESYNC_ENABLE
+        // Resync: ignore if caps lock already is on
+        if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return;
+#endif
+        host_add_key(KC_CAPSLOCK);
+        host_send_keyboard_report();
+        host_del_key(KC_CAPSLOCK);
+        host_send_keyboard_report();
+    }
+#endif
     else if IS_KEY(code) {
         // TODO: should push command_proc out of this block?
         if (command_proc(code)) return;
@@ -914,7 +927,22 @@ void register_code(uint8_t code)
 
 void unregister_code(uint8_t code)
 {
-    if IS_KEY(code) {
+    if (code == KC_NO) {
+        return;
+    }
+#ifdef CAPSLOCK_LOCKING_ENABLE
+    else if (KC_LOCKING_CAPS == code) {
+#ifdef CAPSLOCK_LOCKING_RESYNC_ENABLE
+        // Resync: ignore if caps lock already is off
+        if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return;
+#endif
+        host_add_key(KC_CAPSLOCK);
+        host_send_keyboard_report();
+        host_del_key(KC_CAPSLOCK);
+        host_send_keyboard_report();
+    }
+#endif
+    else if IS_KEY(code) {
         host_del_key(code);
         host_send_keyboard_report();
     }