Skip to content

Commit

Permalink
Fix mod stuck of MODS_KEY when leaving layer #62
Browse files Browse the repository at this point in the history
- Add action_util.c and remove action_oneshot.c
- Add oneshot_mods for MODS_ONESHOT
- Add weak_mods for MODS_KEY and MACRO
- weak_mods is cleared when layer switching
  • Loading branch information
yashikno committed Oct 4, 2013
1 parent cb434cf commit d52d554
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 323 deletions.
2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/keyboard.c \
$(COMMON_DIR)/action.c \
$(COMMON_DIR)/action_tapping.c \
$(COMMON_DIR)/action_oneshot.c \
$(COMMON_DIR)/action_macro.c \
$(COMMON_DIR)/action_layer.c \
$(COMMON_DIR)/action_util.c \
$(COMMON_DIR)/keymap.c \
$(COMMON_DIR)/timer.c \
$(COMMON_DIR)/print.c \
Expand Down
138 changes: 67 additions & 71 deletions common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "backlight.h"
#include "action_layer.h"
#include "action_tapping.h"
#include "action_oneshot.h"
#include "action_macro.h"
#include "action_util.h"
#include "action.h"

#ifdef DEBUG_ACTION
Expand Down Expand Up @@ -79,15 +79,15 @@ void process_action(keyrecord_t *record)
action.key.mods<<4;
if (event.pressed) {
if (mods) {
host_add_mods(mods);
host_send_keyboard_report();
add_weak_mods(mods);
send_keyboard_report();
}
register_code(action.key.code);
} else {
unregister_code(action.key.code);
if (mods) {
host_del_mods(mods);
host_send_keyboard_report();
del_weak_mods(mods);
send_keyboard_report();
}
}
}
Expand All @@ -105,11 +105,11 @@ void process_action(keyrecord_t *record)
if (event.pressed) {
if (tap_count == 0) {
dprint("MODS_TAP: Oneshot: add_mods\n");
add_mods(mods);
register_mods(mods);
}
else if (tap_count == 1) {
dprint("MODS_TAP: Oneshot: start\n");
oneshot_start(mods);
set_oneshot_mods(mods);
}
else if (tap_count == TAPPING_TOGGLE) {
dprint("MODS_TAP: Oneshot: toggle\n");
Expand All @@ -118,25 +118,23 @@ void process_action(keyrecord_t *record)
else {
dprint("MODS_TAP: Oneshot: cancel&add_mods\n");
// double tap cancels oneshot and works as normal modifier.
oneshot_cancel();
add_mods(mods);
clear_oneshot_mods();
register_mods(mods);
}
} else {
if (tap_count == 0) {
dprint("MODS_TAP: Oneshot: cancel/del_mods\n");
// cancel oneshot on hold
oneshot_cancel();
del_mods(mods);
clear_oneshot_mods();
unregister_mods(mods);
}
else if (tap_count == 1) {
dprint("MODS_TAP: Oneshot: del_mods\n");
// retain Oneshot
del_mods(mods);
// Oneshot
}
else {
dprint("MODS_TAP: Oneshot: del_mods\n");
// cancel Mods
del_mods(mods);
unregister_mods(mods);
}
}
break;
Expand All @@ -148,22 +146,22 @@ void process_action(keyrecord_t *record)
dprint("MODS_TAP: Tap: Cancel: add_mods\n");
// ad hoc: set 0 to cancel tap
record->tap.count = 0;
add_mods(mods);
register_mods(mods);
} else {
dprint("MODS_TAP: Tap: register_code\n");
register_code(action.key.code);
}
} else {
dprint("MODS_TAP: No tap: add_mods\n");
add_mods(mods);
register_mods(mods);
}
} else {
if (tap_count > 0) {
dprint("MODS_TAP: Tap: unregister_code\n");
unregister_code(action.key.code);
} else {
dprint("MODS_TAP: No tap: add_mods\n");
del_mods(mods);
unregister_mods(mods);
}
}
break;
Expand Down Expand Up @@ -343,30 +341,30 @@ void register_code(uint8_t code)
// 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();
add_key(KC_CAPSLOCK);
send_keyboard_report();
del_key(KC_CAPSLOCK);
send_keyboard_report();
}

else if (KC_LOCKING_NUM == code) {
#ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return;
#endif
host_add_key(KC_NUMLOCK);
host_send_keyboard_report();
host_del_key(KC_NUMLOCK);
host_send_keyboard_report();
add_key(KC_NUMLOCK);
send_keyboard_report();
del_key(KC_NUMLOCK);
send_keyboard_report();
}

else if (KC_LOCKING_SCROLL == code) {
#ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return;
#endif
host_add_key(KC_SCROLLLOCK);
host_send_keyboard_report();
host_del_key(KC_SCROLLLOCK);
host_send_keyboard_report();
add_key(KC_SCROLLLOCK);
send_keyboard_report();
del_key(KC_SCROLLLOCK);
send_keyboard_report();
}
#endif

Expand All @@ -375,25 +373,28 @@ void register_code(uint8_t code)
if (command_proc(code)) return;

#ifndef NO_ACTION_ONESHOT
/* TODO: remove
if (oneshot_state.mods && !oneshot_state.disabled) {
uint8_t tmp_mods = host_get_mods();
host_add_mods(oneshot_state.mods);
uint8_t tmp_mods = get_mods();
add_mods(oneshot_state.mods);
host_add_key(code);
host_send_keyboard_report();
add_key(code);
send_keyboard_report();
host_set_mods(tmp_mods);
set_mods(tmp_mods);
send_keyboard_report();
oneshot_cancel();
} else
*/
#endif
{
host_add_key(code);
host_send_keyboard_report();
add_key(code);
send_keyboard_report();
}
}
else if IS_MOD(code) {
host_add_mods(MOD_BIT(code));
host_send_keyboard_report();
add_mods(MOD_BIT(code));
send_keyboard_report();
}
else if IS_SYSTEM(code) {
host_system_send(KEYCODE2SYSTEM(code));
Expand All @@ -415,40 +416,40 @@ void unregister_code(uint8_t code)
// 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();
add_key(KC_CAPSLOCK);
send_keyboard_report();
del_key(KC_CAPSLOCK);
send_keyboard_report();
}

else if (KC_LOCKING_NUM == code) {
#ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return;
#endif
host_add_key(KC_NUMLOCK);
host_send_keyboard_report();
host_del_key(KC_NUMLOCK);
host_send_keyboard_report();
add_key(KC_NUMLOCK);
send_keyboard_report();
del_key(KC_NUMLOCK);
send_keyboard_report();
}

else if (KC_LOCKING_SCROLL == code) {
#ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return;
#endif
host_add_key(KC_SCROLLLOCK);
host_send_keyboard_report();
host_del_key(KC_SCROLLLOCK);
host_send_keyboard_report();
add_key(KC_SCROLLLOCK);
send_keyboard_report();
del_key(KC_SCROLLLOCK);
send_keyboard_report();
}
#endif

else if IS_KEY(code) {
host_del_key(code);
host_send_keyboard_report();
del_key(code);
send_keyboard_report();
}
else if IS_MOD(code) {
host_del_mods(MOD_BIT(code));
host_send_keyboard_report();
del_mods(MOD_BIT(code));
send_keyboard_report();
}
else if IS_SYSTEM(code) {
host_system_send(0);
Expand All @@ -458,38 +459,33 @@ void unregister_code(uint8_t code)
}
}

void add_mods(uint8_t mods)
void register_mods(uint8_t mods)
{
if (mods) {
host_add_mods(mods);
host_send_keyboard_report();
add_mods(mods);
send_keyboard_report();
}
}

void del_mods(uint8_t mods)
void unregister_mods(uint8_t mods)
{
if (mods) {
host_del_mods(mods);
host_send_keyboard_report();
del_mods(mods);
send_keyboard_report();
}
}

void set_mods(uint8_t mods)
{
host_set_mods(mods);
host_send_keyboard_report();
}

void clear_keyboard(void)
{
host_clear_mods();
clear_mods();
clear_keyboard_but_mods();
}

void clear_keyboard_but_mods(void)
{
host_clear_keys();
host_send_keyboard_report();
clear_weak_mods();
clear_keys();
send_keyboard_report();
#ifdef MOUSEKEY_ENABLE
mousekey_clear();
mousekey_send();
Expand All @@ -502,7 +498,7 @@ void clear_keyboard_but_mods(void)

bool sending_anykey(void)
{
return (host_has_anykey() || host_mouse_in_use() ||
return (has_anykey() || host_mouse_in_use() ||
host_last_sysytem_report() || host_last_consumer_report());
}

Expand Down
6 changes: 3 additions & 3 deletions common/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
void process_action(keyrecord_t *record);
void register_code(uint8_t code);
void unregister_code(uint8_t code);
void add_mods(uint8_t mods);
void del_mods(uint8_t mods);
void set_mods(uint8_t mods);
void register_mods(uint8_t mods);
void unregister_mods(uint8_t mods);
//void set_mods(uint8_t mods);
void clear_keyboard(void);
void clear_keyboard_but_mods(void);
bool sending_anykey(void);
Expand Down
6 changes: 3 additions & 3 deletions common/action_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 000r|0000|0000 0001 Transparent code
* 000r|0000| keycode Key
* 000r|mods|0000 0000 Modifiers
* 000r|mods| keycode Key and Modifiers
* 000r|mods| keycode Modifiers+Key(Modified key)
* r: Left/Right flag(Left:0, Right:1)
*
* ACT_MODS_TAP(001r):
* 001r|mods|0000 0000 Modifiers with OneShot
* 001r|mods|0000 00xx (reserved)
* 001r|mods| keycode Modifiers with Tap Key
* 001r|mods| keycode Modifiers with Tap Key(Dual role)
*
*
* Other Keys(01xx)
Expand Down Expand Up @@ -69,7 +69,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 1001|oopp|BBBB BBBB 8-bit Bitwise Operation???
*
* ACT_LAYER_TAP(101x):
* 101E|LLLL| keycode Invert with tap key
* 101E|LLLL| keycode On/Off with tap key
* 101E|LLLL|1110 xxxx Reserved(0xE0-EF)
* 101E|LLLL|1111 0000 Invert with tap toggle(0xF0)
* 101E|LLLL|1111 0001 On/Off
Expand Down
21 changes: 0 additions & 21 deletions common/action_oneshot.c

This file was deleted.

Loading

0 comments on commit d52d554

Please sign in to comment.