summaryrefslogtreecommitdiff
path: root/layer.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2012-05-27 14:19:16 +0900
committertmk <nobody@nowhere>2012-05-27 14:19:16 +0900
commit225de7a847a511d004bf909b1334e19497cf2f9d (patch)
treece7c4786038cd3a3bd6086db25a5061e6f51dc73 /layer.c
parent7be605cce75ea572cd2eb62dca03e14d161ef467 (diff)
parent11f087002052be0aab285a77362085008e853be6 (diff)
Merge branch 'fix_layer_delay'
Diffstat (limited to 'layer.c')
-rw-r--r--[-rwxr-xr-x]layer.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/layer.c b/layer.c
index 40b4d7b34a..0854eede0d 100755..100644
--- a/layer.c
+++ b/layer.c
@@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* Parameters:
- * ENTER_DELAY |=======|
+ * SWITCH_DELAY |=======|
* SEND_FN_TERM |================|
*
* Fn key processing cases:
@@ -49,7 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* other key press _____________|~~|__________
* other key send _____________|~~|__________
*
- * 4. press other key during ENTER_DELAY.
+ * 4. press other key during SWITCH_DELAY.
* Layer sw ___________________________
* Fn key press ___|~~~~~~~~~|_____________
* Fn key send ______|~~~~~~|_____________
@@ -69,11 +69,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* Fn key send _____|~|__|~~~~~~~~~~~~~~~~
*/
-// LAYER_ENTER_DELAY: prevent from moving new layer
-#define LAYER_ENTER_DELAY 150
+// LAYER_SWITCH_DELAY: prevent from moving to new layer
+#ifndef LAYER_SWITCH_DELAY
+# define LAYER_SWITCH_DELAY 150
+#endif
// LAYER_SEND_FN_TERM: send keycode if release key in this term
-#define LAYER_SEND_FN_TERM 500
+#ifndef LAYER_SEND_FN_TERM
+# define LAYER_SEND_FN_TERM 500
+#endif
uint8_t default_layer = 0;
@@ -107,10 +111,11 @@ void layer_switching(uint8_t fn_bits)
if (fn_bits == 0) {
// do nothing
} else {
- if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) {
+ if (!keymap_fn_keycode(BIT_SUBST(fn_bits, sent_fn)) ||
+ timer_elapsed(last_timer) > LAYER_SWITCH_DELAY) {
uint8_t _layer_to_switch = new_layer(BIT_SUBST(fn_bits, sent_fn));
if (current_layer != _layer_to_switch) { // not switch layer yet
- debug("Fn case: 1,2,3(LAYER_ENTER_DELAY passed)\n");
+ debug("Fn case: 1,2,3(LAYER_SWITCH_DELAY passed)\n");
debug("Switch Layer: "); debug_hex(current_layer);
current_layer = _layer_to_switch;
layer_used = false;
@@ -120,14 +125,14 @@ void layer_switching(uint8_t fn_bits)
if (host_has_anykey()) { // other keys is pressed
uint8_t _fn_to_send = BIT_SUBST(fn_bits, sent_fn);
if (_fn_to_send) {
- debug("Fn case: 4(send Fn before other key pressed)\n");
+ debug("Fn case: 4(press other key during SWITCH_DELAY.)\n");
// send only Fn key first
- host_swap_keyboard_report();
- host_clear_keyboard_report();
+ uint8_t tmp_mods = keyboard_report->mods;
+ host_add_code(keymap_fn_keycode(_fn_to_send));
host_set_mods(last_mods);
- host_add_code(keymap_fn_keycode(_fn_to_send)); // TODO: do all Fn keys
host_send_keyboard_report();
- host_swap_keyboard_report();
+ host_set_mods(tmp_mods);
+ host_del_code(keymap_fn_keycode(_fn_to_send));
sent_fn |= _fn_to_send;
}
}
@@ -143,15 +148,16 @@ void layer_switching(uint8_t fn_bits)
debug("last_fn: "); debug_bin(last_fn); debug("\n");
debug("last_mods: "); debug_hex(last_mods); debug("\n");
debug("last_timer: "); debug_hex16(last_timer); debug("\n");
+ debug("timer_count: "); debug_hex16(timer_count); debug("\n");
// pressed Fn
if ((fn_changed = BIT_SUBST(fn_bits, last_fn))) {
- debug("fn_changed: "); debug_bin(fn_changed); debug("\n");
+ debug("fn_changed: "); debug_bin(fn_changed); debug("\n");
if (host_has_anykey()) {
debug("Fn case: 5(pressed Fn with other key)\n");
sent_fn |= fn_changed;
} else if (fn_changed & sent_fn) { // pressed same Fn in a row
- if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) {
+ if (timer_elapsed(last_timer) > LAYER_SEND_FN_TERM) {
debug("Fn case: 6(not repeat)\n");
// time passed: not repeate
sent_fn &= ~fn_changed;
@@ -162,17 +168,17 @@ void layer_switching(uint8_t fn_bits)
}
// released Fn
if ((fn_changed = BIT_SUBST(last_fn, fn_bits))) {
- debug("fn_changed: "); debug_bin(fn_changed); debug("\n");
+ debug("fn_changed: "); debug_bin(fn_changed); debug("\n");
if (timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) {
if (!layer_used && BIT_SUBST(fn_changed, sent_fn)) {
debug("Fn case: 2(send Fn one shot: released Fn during LAYER_SEND_FN_TERM)\n");
// send only Fn key first
- host_swap_keyboard_report();
- host_clear_keyboard_report();
+ uint8_t tmp_mods = keyboard_report->mods;
+ host_add_code(keymap_fn_keycode(fn_changed));
host_set_mods(last_mods);
- host_add_code(keymap_fn_keycode(fn_changed)); // TODO: do all Fn keys
host_send_keyboard_report();
- host_swap_keyboard_report();
+ host_set_mods(tmp_mods);
+ host_del_code(keymap_fn_keycode(fn_changed));
sent_fn |= fn_changed;
}
}