diff options
author | Didier Loiseau <didierloiseau+git@gmail.com> | 2016-03-08 23:14:15 +0100 |
---|---|---|
committer | Didier Loiseau <didierloiseau+git@gmail.com> | 2016-03-08 23:14:15 +0100 |
commit | b7a81f041906c3c978a314987e486536be0a58cd (patch) | |
tree | 81865fdb062f2716cb1581a856f3728fb4b09209 | |
parent | 7d3ebd7b40b96f576fe4608b33f47329c334925b (diff) | |
download | qmk_firmware-b7a81f041906c3c978a314987e486536be0a58cd.tar.gz qmk_firmware-b7a81f041906c3c978a314987e486536be0a58cd.zip |
Fix #156: clear weak mods on every key press
- new macro_mods bit field for mods applied by macros
- weak_mods now only used for ACT_{L,R}MODS (i.e. LSFT, RSFT, LCTL etc.)
- clear the _weak_ mods on every key *pressed* such that LSFT etc.
can no more interfere with the next key
-rw-r--r-- | tmk_core/common/action.c | 5 | ||||
-rw-r--r-- | tmk_core/common/action_macro.c | 4 | ||||
-rw-r--r-- | tmk_core/common/action_util.c | 9 | ||||
-rw-r--r-- | tmk_core/common/action_util.h | 7 |
4 files changed, 23 insertions, 2 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index 77ea39e94..4197c53ed 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c | |||
@@ -70,6 +70,10 @@ void process_action(keyrecord_t *record) | |||
70 | #endif | 70 | #endif |
71 | dprintln(); | 71 | dprintln(); |
72 | 72 | ||
73 | if (event.pressed) { | ||
74 | // clear the potential weak mods left by previously pressed keys | ||
75 | clear_weak_mods(); | ||
76 | } | ||
73 | switch (action.kind.id) { | 77 | switch (action.kind.id) { |
74 | /* Key and Mods */ | 78 | /* Key and Mods */ |
75 | case ACT_LMODS: | 79 | case ACT_LMODS: |
@@ -500,6 +504,7 @@ void clear_keyboard(void) | |||
500 | void clear_keyboard_but_mods(void) | 504 | void clear_keyboard_but_mods(void) |
501 | { | 505 | { |
502 | clear_weak_mods(); | 506 | clear_weak_mods(); |
507 | clear_macro_mods(); | ||
503 | clear_keys(); | 508 | clear_keys(); |
504 | send_keyboard_report(); | 509 | send_keyboard_report(); |
505 | #ifdef MOUSEKEY_ENABLE | 510 | #ifdef MOUSEKEY_ENABLE |
diff --git a/tmk_core/common/action_macro.c b/tmk_core/common/action_macro.c index ffaf125c0..7726b1190 100644 --- a/tmk_core/common/action_macro.c +++ b/tmk_core/common/action_macro.c | |||
@@ -41,7 +41,7 @@ void action_macro_play(const macro_t *macro_p) | |||
41 | MACRO_READ(); | 41 | MACRO_READ(); |
42 | dprintf("KEY_DOWN(%02X)\n", macro); | 42 | dprintf("KEY_DOWN(%02X)\n", macro); |
43 | if (IS_MOD(macro)) { | 43 | if (IS_MOD(macro)) { |
44 | add_weak_mods(MOD_BIT(macro)); | 44 | add_macro_mods(MOD_BIT(macro)); |
45 | send_keyboard_report(); | 45 | send_keyboard_report(); |
46 | } else { | 46 | } else { |
47 | register_code(macro); | 47 | register_code(macro); |
@@ -51,7 +51,7 @@ void action_macro_play(const macro_t *macro_p) | |||
51 | MACRO_READ(); | 51 | MACRO_READ(); |
52 | dprintf("KEY_UP(%02X)\n", macro); | 52 | dprintf("KEY_UP(%02X)\n", macro); |
53 | if (IS_MOD(macro)) { | 53 | if (IS_MOD(macro)) { |
54 | del_weak_mods(MOD_BIT(macro)); | 54 | del_macro_mods(MOD_BIT(macro)); |
55 | send_keyboard_report(); | 55 | send_keyboard_report(); |
56 | } else { | 56 | } else { |
57 | unregister_code(macro); | 57 | unregister_code(macro); |
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index f81877dd9..a2d6577b2 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c | |||
@@ -29,6 +29,7 @@ static inline void del_key_bit(uint8_t code); | |||
29 | 29 | ||
30 | static uint8_t real_mods = 0; | 30 | static uint8_t real_mods = 0; |
31 | static uint8_t weak_mods = 0; | 31 | static uint8_t weak_mods = 0; |
32 | static uint8_t macro_mods = 0; | ||
32 | 33 | ||
33 | #ifdef USB_6KRO_ENABLE | 34 | #ifdef USB_6KRO_ENABLE |
34 | #define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) | 35 | #define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) |
@@ -55,6 +56,7 @@ static int16_t oneshot_time = 0; | |||
55 | void send_keyboard_report(void) { | 56 | void send_keyboard_report(void) { |
56 | keyboard_report->mods = real_mods; | 57 | keyboard_report->mods = real_mods; |
57 | keyboard_report->mods |= weak_mods; | 58 | keyboard_report->mods |= weak_mods; |
59 | keyboard_report->mods |= macro_mods; | ||
58 | #ifndef NO_ACTION_ONESHOT | 60 | #ifndef NO_ACTION_ONESHOT |
59 | if (oneshot_mods) { | 61 | if (oneshot_mods) { |
60 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 62 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
@@ -118,6 +120,13 @@ void del_weak_mods(uint8_t mods) { weak_mods &= ~mods; } | |||
118 | void set_weak_mods(uint8_t mods) { weak_mods = mods; } | 120 | void set_weak_mods(uint8_t mods) { weak_mods = mods; } |
119 | void clear_weak_mods(void) { weak_mods = 0; } | 121 | void clear_weak_mods(void) { weak_mods = 0; } |
120 | 122 | ||
123 | /* macro modifier */ | ||
124 | uint8_t get_macro_mods(void) { return macro_mods; } | ||
125 | void add_macro_mods(uint8_t mods) { macro_mods |= mods; } | ||
126 | void del_macro_mods(uint8_t mods) { macro_mods &= ~mods; } | ||
127 | void set_macro_mods(uint8_t mods) { macro_mods = mods; } | ||
128 | void clear_macro_mods(void) { macro_mods = 0; } | ||
129 | |||
121 | /* Oneshot modifier */ | 130 | /* Oneshot modifier */ |
122 | #ifndef NO_ACTION_ONESHOT | 131 | #ifndef NO_ACTION_ONESHOT |
123 | void set_oneshot_mods(uint8_t mods) | 132 | void set_oneshot_mods(uint8_t mods) |
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index a955638b4..1a95cec10 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h | |||
@@ -47,6 +47,13 @@ void del_weak_mods(uint8_t mods); | |||
47 | void set_weak_mods(uint8_t mods); | 47 | void set_weak_mods(uint8_t mods); |
48 | void clear_weak_mods(void); | 48 | void clear_weak_mods(void); |
49 | 49 | ||
50 | /* macro modifier */ | ||
51 | uint8_t get_macro_mods(void); | ||
52 | void add_macro_mods(uint8_t mods); | ||
53 | void del_macro_mods(uint8_t mods); | ||
54 | void set_macro_mods(uint8_t mods); | ||
55 | void clear_macro_mods(void); | ||
56 | |||
50 | /* oneshot modifier */ | 57 | /* oneshot modifier */ |
51 | void set_oneshot_mods(uint8_t mods); | 58 | void set_oneshot_mods(uint8_t mods); |
52 | void clear_oneshot_mods(void); | 59 | void clear_oneshot_mods(void); |