Skip to content

Commit

Permalink
[Feature] Swap buttons on PS2 Mouse/Trackball (#9205)
Browse files Browse the repository at this point in the history
* [Feature Request] Swap buttons on PS2 Mouse/Trackball

* [Feature Request] Swap buttons on PS2 Mouse/Trackball

* Added id: to the doc

* Missing space

* Solve comment
#9205 (comment)

* Solve comments #9205 (comment) & #9205 (comment)

* Format code more according to https://docs.qmk.fm/#/coding_conventions_c

* change logic to LUT

* WIP: Clean up

* WIP: Solution with xor operators to mask the change

* delete #endif & added the missed xor operator (ahhh)

* Variable (mouse_report->buttons): avoid setting twice #9205 (comment)

* Update tmk_core/protocol/ps2_mouse.c

Co-authored-by: Nick Brassel <nick@tzarc.org>

Co-authored-by: juank <juank@fktech.net>
Co-authored-by: Nick Brassel <nick@tzarc.org>
  • Loading branch information
3 people authored Aug 5, 2021
1 parent 3396756 commit 07553b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/feature_ps2_mouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ Fine control over the scrolling is supported with the following defines:
#define PS2_MOUSE_SCROLL_DIVISOR_V 2
```
### Invert Mouse buttons :id=invert-buttons
To invert the left & right buttons you can put:
```c
#define PS2_MOUSE_INVERT_BUTTONS
```
into config.h.
### Invert Mouse and Scroll Axes :id=invert-mouse-and-scroll-axes
To invert the X and Y axes you can put:
Expand Down
7 changes: 7 additions & 0 deletions tmk_core/protocol/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,15 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report)
mouse_report->x = X_IS_NEG ? ((!X_IS_OVF && -127 <= mouse_report->x && mouse_report->x <= -1) ? mouse_report->x : -127) : ((!X_IS_OVF && 0 <= mouse_report->x && mouse_report->x <= 127) ? mouse_report->x : 127);
mouse_report->y = Y_IS_NEG ? ((!Y_IS_OVF && -127 <= mouse_report->y && mouse_report->y <= -1) ? mouse_report->y : -127) : ((!Y_IS_OVF && 0 <= mouse_report->y && mouse_report->y <= 127) ? mouse_report->y : 127);

#ifdef PS2_MOUSE_INVERT_BUTTONS
// swap left & right buttons
uint8_t needs_left = mouse_report->buttons & PS2_MOUSE_BTN_RIGHT;
uint8_t needs_right = mouse_report->buttons & PS2_MOUSE_BTN_LEFT;
mouse_report->buttons = (mouse_report->buttons & ~(PS2_MOUSE_BTN_MASK)) | (needs_left ? PS2_MOUSE_BTN_LEFT : 0) | (needs_right ? PS2_MOUSE_BTN_RIGHT : 0);
#else
// remove sign and overflow flags
mouse_report->buttons &= PS2_MOUSE_BTN_MASK;
#endif

#ifdef PS2_MOUSE_INVERT_X
mouse_report->x = -mouse_report->x;
Expand Down

0 comments on commit 07553b4

Please sign in to comment.