Make diagonal mouse movement considerably smoother

Instead of acting on mouse movement keys immediately in the event handler hook,
just store them, and act on them during a loop hook. This has the effect of
collecting all movement intents noticed in a full scan, and acting on them in
one go, rather than acting individually.

This makes diagonal movement (up & right keys pressed at the same time) a lot
smoother, at the cost of a few ms of delay. The delay is not noticeable, and the
smoothing would be a good trade anyway. No more jerky diagonal movements!

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago committed by Gergely Nagy
parent dcd8d8405e
commit c782eb7275

@ -4,6 +4,25 @@
#include "MouseWrapper.h" #include "MouseWrapper.h"
#include "KeyboardioFirmware.h" #include "KeyboardioFirmware.h"
static uint8_t mouseMoveIntent;
static void loopHook(bool postClear) {
if (postClear) {
mouseMoveIntent = 0;
return;
}
if (mouseMoveIntent & KEY_MOUSE_UP)
MouseWrapper.move(0, -1);
else if (mouseMoveIntent & KEY_MOUSE_DOWN)
MouseWrapper.move(0, 1);
if (mouseMoveIntent & KEY_MOUSE_LEFT)
MouseWrapper.move(-1, 0);
else if (mouseMoveIntent & KEY_MOUSE_RIGHT)
MouseWrapper.move(1, 0);
}
static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) { static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) {
if (key_toggled_off(keyState)) { if (key_toggled_off(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_UP || mappedKey.keyCode & KEY_MOUSE_DOWN) { if (mappedKey.keyCode & KEY_MOUSE_UP || mappedKey.keyCode & KEY_MOUSE_DOWN) {
@ -17,17 +36,7 @@ static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) {
if (!key_is_pressed(keyState)) if (!key_is_pressed(keyState))
return; return;
if (mappedKey.keyCode & KEY_MOUSE_UP) { mouseMoveIntent |= mappedKey.keyCode;
MouseWrapper.move(0,-1);
} else if (mappedKey.keyCode & KEY_MOUSE_DOWN) {
MouseWrapper.move(0,1);
}
if (mappedKey.keyCode & KEY_MOUSE_LEFT) {
MouseWrapper.move(-1,0);
} else if (mappedKey.keyCode & KEY_MOUSE_RIGHT) {
MouseWrapper.move(1,0);
}
} }
static Key handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState) { static Key handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState) {
@ -63,6 +72,7 @@ MouseKeys_::MouseKeys_(void) {
void void
MouseKeys_::begin (void) { MouseKeys_::begin (void) {
event_handler_hook_use (handleMouseKeys); event_handler_hook_use (handleMouseKeys);
loop_hook_use (loopHook);
} }
MouseKeys_ MouseKeys; MouseKeys_ MouseKeys;

Loading…
Cancel
Save