From 1be62c75368575e09c8aa29a4252d02945167f83 Mon Sep 17 00:00:00 2001 From: Liyang HU Date: Tue, 16 Feb 2021 14:06:30 +0000 Subject: [PATCH 1/2] tmk_core/common/report.h: define `enum mouse_buttons` in terms of `#define MOUSE_BTN_MASK()` --- tmk_core/common/report.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index bcf5cab388de..606a25964363 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -34,15 +34,16 @@ enum hid_report_ids { }; /* Mouse buttons */ +#define MOUSE_BTN_MASK(n) (1 << (n)) enum mouse_buttons { - MOUSE_BTN1 = (1 << 0), - MOUSE_BTN2 = (1 << 1), - MOUSE_BTN3 = (1 << 2), - MOUSE_BTN4 = (1 << 3), - MOUSE_BTN5 = (1 << 4), - MOUSE_BTN6 = (1 << 5), - MOUSE_BTN7 = (1 << 6), - MOUSE_BTN8 = (1 << 7) + MOUSE_BTN1 = MOUSE_BTN_MASK(0), + MOUSE_BTN2 = MOUSE_BTN_MASK(1), + MOUSE_BTN3 = MOUSE_BTN_MASK(2), + MOUSE_BTN4 = MOUSE_BTN_MASK(3), + MOUSE_BTN5 = MOUSE_BTN_MASK(4), + MOUSE_BTN6 = MOUSE_BTN_MASK(5), + MOUSE_BTN7 = MOUSE_BTN_MASK(6), + MOUSE_BTN8 = MOUSE_BTN_MASK(7) }; /* Consumer Page (0x0C) From 03ddd855d28dca2804e6b3e2a078b484e8fb1daa Mon Sep 17 00:00:00 2001 From: Liyang HU Date: Tue, 16 Feb 2021 14:38:16 +0000 Subject: [PATCH 2/2] tmk_core/common/action.c: collapse multiple `case KC_MS_BTN[1-8]:` into single `MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1)` We all love tapping on our keyboards but this is taking the piss. This saves ~134 bytes on my ATmega32. --- tmk_core/common/action.c | 76 +++++++--------------------------------- 1 file changed, 12 insertions(+), 64 deletions(-) diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index 66411b4fd3c0..f53e3c70844b 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -410,74 +410,22 @@ void process_action(keyrecord_t *record, action_t action) { case ACT_MOUSEKEY: if (event.pressed) { mousekey_on(action.key.code); - switch (action.key.code) { -# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) - case KC_MS_BTN1: - register_button(true, MOUSE_BTN1); - break; - case KC_MS_BTN2: - register_button(true, MOUSE_BTN2); - break; - case KC_MS_BTN3: - register_button(true, MOUSE_BTN3); - break; -# endif -# ifdef POINTING_DEVICE_ENABLE - case KC_MS_BTN4: - register_button(true, MOUSE_BTN4); - break; - case KC_MS_BTN5: - register_button(true, MOUSE_BTN5); - break; - case KC_MS_BTN6: - register_button(true, MOUSE_BTN6); - break; - case KC_MS_BTN7: - register_button(true, MOUSE_BTN7); - break; - case KC_MS_BTN8: - register_button(true, MOUSE_BTN8); - break; -# endif - default: - mousekey_send(); - break; - } } else { mousekey_off(action.key.code); - switch (action.key.code) { + } + switch (action.key.code) { # if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) - case KC_MS_BTN1: - register_button(false, MOUSE_BTN1); - break; - case KC_MS_BTN2: - register_button(false, MOUSE_BTN2); - break; - case KC_MS_BTN3: - register_button(false, MOUSE_BTN3); - break; -# endif -# ifdef POINTING_DEVICE_ENABLE - case KC_MS_BTN4: - register_button(false, MOUSE_BTN4); - break; - case KC_MS_BTN5: - register_button(false, MOUSE_BTN5); - break; - case KC_MS_BTN6: - register_button(false, MOUSE_BTN6); - break; - case KC_MS_BTN7: - register_button(false, MOUSE_BTN7); - break; - case KC_MS_BTN8: - register_button(false, MOUSE_BTN8); - break; +# ifdef POINTING_DEVICE_ENABLE + case KC_MS_BTN1 ... KC_MS_BTN8: +# else + case KC_MS_BTN1 ... KC_MS_BTN3: +# endif + register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1)); + break; # endif - default: - mousekey_send(); - break; - } + default: + mousekey_send(); + break; } break; #endif