]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
Add NO_ACTION_ONESHOT config option
authortmk <nobody@nowhere>
Thu, 21 Mar 2013 05:42:40 +0000 (14:42 +0900)
committertmk <nobody@nowhere>
Thu, 21 Mar 2013 05:42:40 +0000 (14:42 +0900)
common.mk
common/action.c
common/action_oneshot.c [new file with mode: 0644]
common/action_oneshot.h [new file with mode: 0644]

index e4c9fb26954cf6bb30cb9d342923b5ea2a93b575..de1c6c36055a60debdba303fc96372465c5aab98 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -2,6 +2,7 @@ COMMON_DIR = common
 SRC += $(COMMON_DIR)/host.c \
        $(COMMON_DIR)/keyboard.c \
        $(COMMON_DIR)/action.c \
+       $(COMMON_DIR)/action_oneshot.c \
        $(COMMON_DIR)/action_macro.c \
        $(COMMON_DIR)/layer_switch.c \
        $(COMMON_DIR)/keymap.c \
index 3d81318a9c6f7fcd5ee43cf910b083b89cec22e7..49bfc54e7ea61b018c4483442c53bd9ae3419fe4 100644 (file)
@@ -25,6 +25,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "debug.h"
 #include "led.h"
 #include "layer_switch.h"
+#include "action_oneshot.h"
 #include "action_macro.h"
 #include "action.h"
 
@@ -125,44 +126,6 @@ bool waiting_buffer_has_anykey_pressed(void)
     }
     return false;
 }
-
-
-/* Oneshot modifier
- *
- * Problem: Want to capitalize like 'The' but the result tends to be 'THe'.
- * Solution: Oneshot modifier have its effect on only one key coming next.
- *           Tap Shift, then type 't', 'h' and 'e'. Not need to hold Shift key.
- *
- *  Hold:       works as normal modifier.
- *  Tap:        one shot modifier.
- *  2 Tap:      cancel one shot modifier.
- *  5-Tap:      toggles enable/disable oneshot feature.
- */
-static struct {
-    uint8_t mods;
-    uint8_t time;
-    bool    ready;
-    bool    disabled;
-}   oneshot_state;
-
-static void oneshot_start(uint8_t mods, uint16_t time)
-{
-    oneshot_state.mods = mods;
-    oneshot_state.time = time;
-    oneshot_state.ready = true;
-}
-
-static void oneshot_cancel(void)
-{
-    oneshot_state.mods = 0;
-    oneshot_state.time = 0;
-    oneshot_state.ready = false;
-}
-
-static void oneshot_toggle(void)
-{
-    oneshot_state.disabled = !oneshot_state.disabled;
-}
 #endif
 
 
@@ -263,6 +226,7 @@ static void process_action(keyrecord_t *record)
                 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ?  action.key.mods :
                                                                     action.key.mods<<4;
                 switch (action.layer.code) {
+    #ifndef NO_ACTION_ONESHOT
                     case 0x00:
                         // Oneshot modifier
                         if (event.pressed) {
@@ -272,7 +236,7 @@ static void process_action(keyrecord_t *record)
                             }
                             else if (tap_count == 1) {
                                 debug("MODS_TAP: Oneshot: start\n");
-                                oneshot_start(mods, event.time);
+                                oneshot_start(mods);
                             }
                             else if (tap_count == TAPPING_TOGGLE) {
                                 debug("MODS_TAP: Oneshot: toggle\n");
@@ -303,6 +267,7 @@ static void process_action(keyrecord_t *record)
                             }
                         }
                         break;
+    #endif
                     default:
                         if (event.pressed) {
                             if (tap_count > 0) {
@@ -930,15 +895,16 @@ void register_code(uint8_t code)
         // TODO: should push command_proc out of this block?
         if (command_proc(code)) return;
 
-#ifndef NO_ACTION_TAPPING
-        if (oneshot_state.mods && oneshot_state.ready && !oneshot_state.disabled) {
+#ifndef NO_ACTION_ONESHOT
+        if (oneshot_state.mods && !oneshot_state.disabled) {
             uint8_t tmp_mods = host_get_mods();
             host_add_mods(oneshot_state.mods);
+
             host_add_key(code);
             host_send_keyboard_report();
 
             host_set_mods(tmp_mods);
-            oneshot_state.ready = false;
+            oneshot_cancel();
         } else 
 #endif
         {
diff --git a/common/action_oneshot.c b/common/action_oneshot.c
new file mode 100644 (file)
index 0000000..d34f44b
--- /dev/null
@@ -0,0 +1,21 @@
+#include "action_oneshot.h"
+
+
+#ifndef NO_ACTION_ONESHOT
+oneshot_state_t oneshot_state;
+
+void oneshot_start(uint8_t mods)
+{
+    oneshot_state.mods = mods;
+}
+
+void oneshot_cancel(void)
+{
+    oneshot_state.mods = 0;
+}
+
+void oneshot_toggle(void)
+{
+    oneshot_state.disabled = !oneshot_state.disabled;
+}
+#endif
diff --git a/common/action_oneshot.h b/common/action_oneshot.h
new file mode 100644 (file)
index 0000000..36ef9e9
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+Copyright 2013 Jun Wako <wakojun@gmail.com>
+
+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 2 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/>.
+*/
+#ifndef ACTION_ONESHOT_H
+#define ACTION_ONESHOT_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef NO_ACTION_TAPPING
+    #define NO_ACTION_ONESHOT
+#endif
+
+#ifndef NO_ACTION_ONESHOT
+/* Oneshot modifier
+ *
+ * Problem: Want to capitalize like 'The' but the result tends to be 'THe'.
+ * Solution: Oneshot modifier have its effect on only one key coming next.
+ *           Tap Shift, then type 't', 'h' and 'e'. Not need to hold Shift key.
+ *
+ *  Hold:       works as normal modifier.
+ *  Tap:        one shot modifier.
+ *  2 Tap:      cancel one shot modifier.
+ *  5-Tap:      toggles enable/disable oneshot feature.
+ */
+typedef struct {
+    uint8_t mods;
+    bool    disabled;
+}   oneshot_state_t;
+
+
+oneshot_state_t oneshot_state;
+
+void oneshot_start(uint8_t mods);
+void oneshot_cancel(void);
+void oneshot_toggle(void);
+#endif
+
+#endif