Some small code cleanups

Move the hooks inside the `MouseKeys_` object, and drop the
`handle_mouse_key_event` function, by inlining it into the event handler hook.

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

@ -4,9 +4,9 @@
#include "MouseWrapper.h"
#include "KeyboardioFirmware.h"
static uint8_t mouseMoveIntent;
uint8_t MouseKeys_::mouseMoveIntent;
static void loopHook(bool postClear) {
void MouseKeys_::loopHook(bool postClear) {
if (postClear) {
mouseMoveIntent = 0;
return;
@ -31,14 +31,7 @@ static void loopHook(bool postClear) {
MouseWrapper.move(1, 0);
}
static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) {
if (!key_is_pressed(keyState))
return;
mouseMoveIntent |= mappedKey.keyCode;
}
static Key handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState) {
Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return mappedKey;
@ -51,7 +44,8 @@ static Key handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState)
MouseWrapper.release_button(button);
}
} else if (!(mappedKey.keyCode & KEY_MOUSE_WARP)) {
handle_mouse_key_event(mappedKey, keyState);
if (key_is_pressed(keyState))
mouseMoveIntent |= mappedKey.keyCode;
} else if (key_toggled_on(keyState)) {
if (mappedKey.keyCode & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) {
// we don't pass in the left and up values because those are the
@ -70,8 +64,8 @@ MouseKeys_::MouseKeys_(void) {
void
MouseKeys_::begin (void) {
event_handler_hook_use (handleMouseKeys);
loop_hook_use (loopHook);
event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook);
}
MouseKeys_ MouseKeys;

@ -8,6 +8,12 @@ class MouseKeys_ : public KeyboardioPlugin {
MouseKeys_ (void);
virtual void begin(void) final;
private:
static uint8_t mouseMoveIntent;
static void loopHook(bool postClear);
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
};
extern MouseKeys_ MouseKeys;

Loading…
Cancel
Save