Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmk_core/common/action.c: refactor for code size; merge multiple cases into one #11943

Merged
merged 2 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 12 additions & 64 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions tmk_core/common/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down