commit c70a527d0418b4f32437873f682680f451fa4fb8
parent 2c1db6b9b0ee16f7da7ef18164ce96fda7b4a572
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 9 Jan 2023 13:39:17 +0100
Fix macro_send for multiple held keys
Diffstat:
3 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/src/hid.c b/src/hid.c
@@ -19,6 +19,9 @@
#include <stdbool.h>
#include <string.h>
+#define MACRO_X 0
+#define MACRO_Y 7
+
struct layerkey {
uint layer;
uint key;
@@ -172,7 +175,7 @@ void
macro_held_push(uint32_t keysym)
{
if (macro_held_cnt == MACRO_HOLD_MAX) {
- WARN("Macro help keys overflow");
+ WARN("Macro held keys overflow");
return;
}
@@ -269,7 +272,7 @@ process_keypress(uint32_t keysym, uint x, uint y)
active_layers_reset();
active_layers[0].layer = TO_LAYER(keysym);
} else if (IS_USER(keysym)) {
- process_user_keypress(TO_SYM(keysym), x, y);
+ process_user_keypress(TO_USER(keysym), x, y);
} else if (IS_KC(keysym) && IS_KEY_KC(TO_KC(keysym))) {
/* FIXME: two keys pressed at the exact same time with
* different weak modifiers will not be reported correctly */
@@ -282,8 +285,10 @@ process_keypress(uint32_t keysym, uint x, uint y)
void
process_keydown(uint32_t keysym, uint x, uint y)
{
- if (seen_mat[y][x]) return;
- seen_mat[y][x] = true;
+ if (x != MACRO_X || y != MACRO_Y) {
+ if (seen_mat[y][x]) return;
+ seen_mat[y][x] = true;
+ }
if (IS_KC(keysym) && IS_KEY_KC(TO_KC(keysym))) {
add_keycode(TO_KC(keysym));
@@ -300,7 +305,7 @@ process_keyrelease(uint32_t keysym, uint x, uint y)
uint i;
if (IS_USER(keysym))
- process_user_keyrelease(TO_SYM(keysym), x, y);
+ process_user_keyrelease(TO_USER(keysym), x, y);
for (i = 1; i <= active_layers_top; i++) {
if (active_layers[i].key == y * KEY_COLS + x) {
@@ -549,8 +554,7 @@ hid_switch_layer_with_key(uint8_t layer, uint x, uint y)
void
hid_send_macro(const uint32_t *keysyms, uint cnt)
{
- /* TODO: replace macro x y with less hacky alternative */
- static const uint mx = 0, my = 7;
+ static const uint mx = MACRO_X, my = MACRO_Y;
struct hid_keyboard_report tmp;
uint32_t start_ms;
uint i, k;
@@ -580,29 +584,25 @@ hid_send_macro(const uint32_t *keysyms, uint cnt)
memset(&keyboard_report, 0, sizeof(keyboard_report));
if (IS_MACRO_RELEASE(keysyms[i]))
- macro_held_pop(keysyms[i]);
+ macro_held_pop(TO_SYM(keysyms[i]));
for (k = 0; k < i; k++) {
- if (macro_held_find(keysyms[k])) {
- seen_mat[my][mx] = false;
- process_keydown(keysyms[k], mx, my);
- }
+ if (!IS_MACRO_HOLD(keysyms[k]))
+ continue;
+ if (macro_held_find(TO_SYM(keysyms[k])))
+ process_keydown(TO_SYM(keysyms[k]), mx, my);
}
- if (IS_MACRO_HOLD(keysyms[i]))
- macro_held_push(keysyms[i]);
-
if (IS_MACRO_PRESS(keysyms[i])) {
keyboard_report.mods = active_weak_mods | active_mods;
memcpy(&tmp, &keyboard_report, sizeof(keyboard_report));
- }
-
- if (IS_MACRO_RELEASE(keysyms[i])) {
- process_keyrelease(keysyms[i], mx, my);
- process_keyup(keysyms[i], mx, my);
- } else {
- process_keypress(keysyms[i], mx, my);
- process_keydown(keysyms[i], mx, my);
+ process_keypress(TO_SYM(keysyms[i]), mx, my);
+ process_keydown(TO_SYM(keysyms[i]), mx, my);
+ } else if (IS_MACRO_HOLD(keysyms[i])) {
+ macro_held_push(TO_SYM(keysyms[i]));
+ } else if (IS_MACRO_RELEASE(keysyms[i])) {
+ process_keyrelease(TO_SYM(keysyms[i]), mx, my);
+ process_keyup(TO_SYM(keysyms[i]), mx, my);
}
send_keyboard_report();
diff --git a/src/keymap.c b/src/keymap.c
@@ -49,7 +49,7 @@
\
DE_J , DE_L , DE_U , DE_Y , DE_HASH , DE_SS , \
DE_M , DE_N , DE_E , DE_I , DE_O , SW(SPEC), \
- DE_K , DE_H , DE_COMM , DE_DOT , DE_MINS , XXXXXXX , \
+ DE_K , DE_H , DE_COMM , DE_DOT , DE_MINS , SW(MISC), \
SW(NUMS), KC_SPC , KC_LCTL \
)
@@ -125,6 +125,18 @@
_______ , _______ , _______ \
)
+#define LAYER_MISC_DE KEYMAP( \
+ XXXXXXX , SX(TTY1), SX(TTY2), SX(TTY3), SX(TTY4), SX(TTY5), \
+ XXXXXXX , SX(TTY6), SX(TTY7), SX(TTY8), SX(TTY9),SX(TTY10), \
+ XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , \
+ XXXXXXX , XXXXXXX , XXXXXXX , \
+ \
+ XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , \
+ XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , \
+ XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , \
+ XXXXXXX , XXXXXXX , XXXXXXX \
+)
+
#define LAYER_GAME_DE KEYMAP( \
KC_ESC , DE_Q , DE_W , DE_E , DE_R , DE_T , \
SW(GNUM), DE_A , DE_S , DE_D , DE_F , DE_G , \
@@ -158,6 +170,7 @@ enum {
NUMS, /* numbers */
SPEC, /* specials */
META, /* functions */
+ MISC,
GAME, /* gaming base */
GNUM, /* gaming nums */
};
@@ -166,6 +179,16 @@ enum {
KVM1,
KVM2,
QUSW,
+ TTY1,
+ TTY2,
+ TTY3,
+ TTY4,
+ TTY5,
+ TTY6,
+ TTY7,
+ TTY8,
+ TTY9,
+ TTY10,
};
const uint32_t keymap_layers_de[][KEY_ROWS][KEY_COLS] = {
@@ -176,6 +199,7 @@ const uint32_t keymap_layers_de[][KEY_ROWS][KEY_COLS] = {
[NUMS] = LAYER_NUMS_DE,
[SPEC] = LAYER_SPEC_DE,
[META] = LAYER_META_DE,
+ [MISC] = LAYER_MISC_DE,
[GAME] = LAYER_GAME_DE,
[GNUM] = LAYER_GNUM_DE
@@ -185,14 +209,22 @@ const uint32_t keymap_layers_de_count = ARRLEN(keymap_layers_de);
const uint32_t (*keymap_layers)[KEY_ROWS][KEY_COLS] = keymap_layers_de;
uint32_t keymap_layers_count = keymap_layers_de_count;
-const uint32_t macro_kvm1[] = {
+static const uint32_t macro_kvm1[] = {
KC_LEFT_CTRL, KC_LEFT_CTRL, KC_1
};
-const uint32_t macro_kvm2[] = {
+static const uint32_t macro_kvm2[] = {
KC_LEFT_CTRL, KC_LEFT_CTRL, KC_2
};
+static const uint32_t ttysw_lut[] = {
+ KC_F1, KC_F2, KC_F3, KC_F4, KC_F5,
+ KC_F6, KC_F7, KC_F8, KC_F9, KC_F10
+};
+static uint32_t macro_ttysw[] = {
+ HOLD(KC_LEFT_CTRL), HOLD(KC_LEFT_ALT), KC_F1,
+};
+
void
process_user_keypress(uint8_t sym, uint x, uint y)
{
@@ -211,6 +243,10 @@ process_user_keypress(uint8_t sym, uint x, uint y)
hid_switch_layer_with_key(QUIK, x, y);
}
break;
+ case TTY1...TTY10:
+ macro_ttysw[2] = ttysw_lut[sym - TTY1];
+ hid_send_macro(macro_ttysw, ARRLEN(macro_ttysw));
+ break;
}
}
diff --git a/src/keysym.h b/src/keysym.h
@@ -23,8 +23,9 @@
#define IS_MACRO_HOLD(x) ((x) & (1U << B_MACRO_HOLD))
#define IS_MACRO_RELEASE(x) ((x) & (1U << B_MACRO_RELEASE))
-#define IS_MACRO_PRESS(x) (!IS_MACRO_HOLD(x) && !IS_MACRO_RELEASE(x))
#define IS_MACRO_DELAY(x) ((x) & (1U << B_MACRO_DELAY))
+#define IS_MACRO_PRESS(x) (!IS_MACRO_HOLD(x) && !IS_MACRO_RELEASE(x) \
+ && !IS_MACRO_DELAY(x))
#define IS_LEFT_CTRL(x) (IS_CTRL(x) && !IS_RIGHT(x))
#define IS_RIGHT_CTRL(x) (IS_CTRL(x) && IS_RIGHT(x))
@@ -38,9 +39,10 @@
#define IS_MOD(x) ((x) & MASK(B_TOGGLE, B_CTRL))
#define TO_SPECIAL(x) (((x) >> B_SPECIAL_SEL) & 0b11)
-#define TO_KC(x) ((x) & 0xFF)
-#define TO_SYM(x) ((x) & 0xFF)
+#define TO_KC(x) ((x) & 0xFF)
+#define TO_USER(x) ((x) & 0xFF)
#define TO_LAYER(x) ((x) & 0xFF)
+#define TO_SYM(x) ((x) & 0xFFFF)
#define TO_DELAY(x) ((x) & 0xFFFF)
#define SPECIAL(x, g) ((x) | (1U << B_SPECIAL) | ((g) << B_SPECIAL_SEL))