Skip to content

Commit

Permalink
Add movement hook to ps2_mouse (qmk#8805)
Browse files Browse the repository at this point in the history
Process mouse movement in the keymap before it is sent to the host. Example uses
include filtering noise, adding acceleration, and automatically activating a
layer. To use, define the following function in your keymap:

void ps2_mouse_moved_user(report_mouse_t *mouse_report);
  • Loading branch information
manna-harbour authored Jul 2, 2020
1 parent e941527 commit 94c308f
Show file tree
Hide file tree
Showing 3 changed files with 18 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 @@ -294,3 +294,13 @@ To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
#define PS2_MOUSE_DEBUG_HID
#define PS2_MOUSE_DEBUG_RAW
```
### Movement Hook :id=movement-hook
Process mouse movement in the keymap before it is sent to the host. Example
uses include filtering noise, adding acceleration, and automatically activating
a layer. To use, define the following function in your keymap:
```c
void ps2_mouse_moved_user(report_mouse_t *mouse_report);
```
5 changes: 5 additions & 0 deletions tmk_core/protocol/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void ps2_mouse_init(void) {

__attribute__((weak)) void ps2_mouse_init_user(void) {}

__attribute__((weak)) void ps2_mouse_moved_user(report_mouse_t *mouse_report) {}

void ps2_mouse_task(void) {
static uint8_t buttons_prev = 0;
extern int tp_buttons;
Expand Down Expand Up @@ -98,6 +100,9 @@ void ps2_mouse_task(void) {
#if PS2_MOUSE_SCROLL_BTN_MASK
ps2_mouse_scroll_button_task(&mouse_report);
#endif
if (mouse_report.x || mouse_report.y || mouse_report.v) {
ps2_mouse_moved_user(&mouse_report);
}
#ifdef PS2_MOUSE_DEBUG_HID
// Used to debug the bytes sent to the host
ps2_mouse_print_report(&mouse_report);
Expand Down
3 changes: 3 additions & 0 deletions tmk_core/protocol/ps2_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <stdbool.h>
#include "debug.h"
#include "report.h"

#define PS2_MOUSE_SEND(command, message) \
do { \
Expand Down Expand Up @@ -174,4 +175,6 @@ void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);

void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);

void ps2_mouse_moved_user(report_mouse_t *mouse_report);

#endif

0 comments on commit 94c308f

Please sign in to comment.