aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiyang HU <github.com@liyang.hu>2021-02-20 19:53:53 +0000
committerGitHub <noreply@github.com>2021-02-20 14:53:53 -0500
commitc4bd6af837ada55cd3cbc21f0e50d6a2d620bcf8 (patch)
treeb4510734d4d0a90ae95ade91e8230221cf0f79f6
parent2e4f0876151d7016172fa51d1588def1c96102fc (diff)
downloadqmk_firmware-c4bd6af837ada55cd3cbc21f0e50d6a2d620bcf8.tar.gz
qmk_firmware-c4bd6af837ada55cd3cbc21f0e50d6a2d620bcf8.zip
tmk_core/common/action.c: refactor for code size; merge multiple `case`s into one (#11943)
* tmk_core/common/report.h: define `enum mouse_buttons` in terms of `#define MOUSE_BTN_MASK()` * 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.
-rw-r--r--tmk_core/common/action.c76
-rw-r--r--tmk_core/common/report.h17
2 files changed, 21 insertions, 72 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 66411b4fd..f53e3c708 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) {
410 case ACT_MOUSEKEY: 410 case ACT_MOUSEKEY:
411 if (event.pressed) { 411 if (event.pressed) {
412 mousekey_on(action.key.code); 412 mousekey_on(action.key.code);
413 switch (action.key.code) {
414# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
415 case KC_MS_BTN1:
416 register_button(true, MOUSE_BTN1);
417 break;
418 case KC_MS_BTN2:
419 register_button(true, MOUSE_BTN2);
420 break;
421 case KC_MS_BTN3:
422 register_button(true, MOUSE_BTN3);
423 break;
424# endif
425# ifdef POINTING_DEVICE_ENABLE
426 case KC_MS_BTN4:
427 register_button(true, MOUSE_BTN4);
428 break;
429 case KC_MS_BTN5:
430 register_button(true, MOUSE_BTN5);
431 break;
432 case KC_MS_BTN6:
433 register_button(true, MOUSE_BTN6);
434 break;
435 case KC_MS_BTN7:
436 register_button(true, MOUSE_BTN7);
437 break;
438 case KC_MS_BTN8:
439 register_button(true, MOUSE_BTN8);
440 break;
441# endif
442 default:
443 mousekey_send();
444 break;
445 }
446 } else { 413 } else {
447 mousekey_off(action.key.code); 414 mousekey_off(action.key.code);
448 switch (action.key.code) { 415 }
416 switch (action.key.code) {
449# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) 417# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
450 case KC_MS_BTN1: 418# ifdef POINTING_DEVICE_ENABLE
451 register_button(false, MOUSE_BTN1); 419 case KC_MS_BTN1 ... KC_MS_BTN8:
452 break; 420# else
453 case KC_MS_BTN2: 421 case KC_MS_BTN1 ... KC_MS_BTN3:
454 register_button(false, MOUSE_BTN2); 422# endif
455 break; 423 register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1));
456 case KC_MS_BTN3: 424 break;
457 register_button(false, MOUSE_BTN3);
458 break;
459# endif
460# ifdef POINTING_DEVICE_ENABLE
461 case KC_MS_BTN4:
462 register_button(false, MOUSE_BTN4);
463 break;
464 case KC_MS_BTN5:
465 register_button(false, MOUSE_BTN5);
466 break;
467 case KC_MS_BTN6:
468 register_button(false, MOUSE_BTN6);
469 break;
470 case KC_MS_BTN7:
471 register_button(false, MOUSE_BTN7);
472 break;
473 case KC_MS_BTN8:
474 register_button(false, MOUSE_BTN8);
475 break;
476# endif 425# endif
477 default: 426 default:
478 mousekey_send(); 427 mousekey_send();
479 break; 428 break;
480 }
481 } 429 }
482 break; 430 break;
483#endif 431#endif
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index bcf5cab38..606a25964 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -34,15 +34,16 @@ enum hid_report_ids {
34}; 34};
35 35
36/* Mouse buttons */ 36/* Mouse buttons */
37#define MOUSE_BTN_MASK(n) (1 << (n))
37enum mouse_buttons { 38enum mouse_buttons {
38 MOUSE_BTN1 = (1 << 0), 39 MOUSE_BTN1 = MOUSE_BTN_MASK(0),
39 MOUSE_BTN2 = (1 << 1), 40 MOUSE_BTN2 = MOUSE_BTN_MASK(1),
40 MOUSE_BTN3 = (1 << 2), 41 MOUSE_BTN3 = MOUSE_BTN_MASK(2),
41 MOUSE_BTN4 = (1 << 3), 42 MOUSE_BTN4 = MOUSE_BTN_MASK(3),
42 MOUSE_BTN5 = (1 << 4), 43 MOUSE_BTN5 = MOUSE_BTN_MASK(4),
43 MOUSE_BTN6 = (1 << 5), 44 MOUSE_BTN6 = MOUSE_BTN_MASK(5),
44 MOUSE_BTN7 = (1 << 6), 45 MOUSE_BTN7 = MOUSE_BTN_MASK(6),
45 MOUSE_BTN8 = (1 << 7) 46 MOUSE_BTN8 = MOUSE_BTN_MASK(7)
46}; 47};
47 48
48/* Consumer Page (0x0C) 49/* Consumer Page (0x0C)