The primary reason for the move is to be able to disable mouse keys completely, and not even compile them in. For this to work, it needs to be in a separate library, otherwise it will always be included, even if not active. So, this patch turns mouse-keys into a simple plugin, included with the core firmware! This makes the default event handler a bit simpler, the code marginally smaller, and the feature completely optional. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>pull/50/head
parent
cedb0565e7
commit
28aa497452
@ -0,0 +1,9 @@
|
||||
name=Model01-MouseKeys
|
||||
version=0.0.1
|
||||
author=Jesse Vincent
|
||||
maintainer=Jesse Vincent <jesse@keyboard.io>
|
||||
sentence=Mouse keys for the Keyboardio Model 01.
|
||||
paragraph=...
|
||||
category=Communication
|
||||
url=https://github.com/keyboardio/KeyboardioFirmware
|
||||
architectures=avr
|
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "key_defs.h"
|
||||
|
||||
#define IS_MOUSE_KEY B00010000
|
||||
|
||||
// Synthetic, not internal
|
||||
#define KEY_MOUSE_BTN_L 0x01 // Synthetic key
|
||||
#define KEY_MOUSE_BTN_M 0x02 // Synthetic key
|
||||
#define KEY_MOUSE_BTN_R 0x04 // Synthetic key
|
||||
|
||||
|
||||
#define KEY_MOUSE_UP B0000001
|
||||
#define KEY_MOUSE_DOWN B0000010
|
||||
#define KEY_MOUSE_LEFT B0000100
|
||||
#define KEY_MOUSE_RIGHT B0001000
|
||||
#define KEY_MOUSE_CENTER B0010000
|
||||
#define KEY_MOUSE_WARP B0100000
|
||||
#define KEY_MOUSE_WARP_END B1000000
|
||||
|
||||
|
||||
#define Key_mouseWarpNW (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_WARP| KEY_MOUSE_UP | KEY_MOUSE_LEFT }
|
||||
#define Key_mouseWarpNE (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_WARP| KEY_MOUSE_UP | KEY_MOUSE_RIGHT }
|
||||
#define Key_mouseWarpSW (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_WARP| KEY_MOUSE_DOWN | KEY_MOUSE_LEFT }
|
||||
#define Key_mouseWarpSE (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_WARP| KEY_MOUSE_DOWN | KEY_MOUSE_RIGHT }
|
||||
#define Key_mouseWarpEnd (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_WARP| KEY_MOUSE_WARP_END}
|
||||
|
||||
|
||||
#define Key_mouseUpL (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_UP | KEY_MOUSE_LEFT }
|
||||
#define Key_mouseUp (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_UP }
|
||||
#define Key_mouseUpR (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_UP | KEY_MOUSE_RIGHT }
|
||||
#define Key_mouseL (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_LEFT }
|
||||
#define Key_mouseR (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_RIGHT }
|
||||
#define Key_mouseDnL (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_DOWN | KEY_MOUSE_LEFT }
|
||||
#define Key_mouseDn (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_DOWN }
|
||||
#define Key_mouseDnR (Key){ KEY_FLAGS|SYNTHETIC|IS_MOUSE_KEY, KEY_MOUSE_DOWN | KEY_MOUSE_RIGHT }
|
||||
#define Key_mouseScrollUp
|
||||
#define Key_mouseScrollDn
|
||||
#define Key_mouseScrollL
|
||||
#define Key_mouseScrollR
|
||||
#define Key_mouseBtnL (Key){ KEY_FLAGS | SYNTHETIC, KEY_MOUSE_BTN_L }
|
||||
#define Key_mouseBtnM (Key){ KEY_FLAGS | SYNTHETIC, KEY_MOUSE_BTN_M }
|
||||
#define Key_mouseBtnR (Key){ KEY_FLAGS | SYNTHETIC, KEY_MOUSE_BTN_R }
|
@ -0,0 +1,60 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "MouseKeys.h"
|
||||
#include "MouseWrapper.h"
|
||||
#include "KeyboardioFirmware.h"
|
||||
|
||||
static void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
|
||||
if (!key_is_pressed(currentState,previousState))
|
||||
return;
|
||||
|
||||
if (mappedKey.rawKey & KEY_MOUSE_UP) {
|
||||
MouseWrapper.move(0,-1);
|
||||
}
|
||||
if (mappedKey.rawKey & KEY_MOUSE_DOWN) {
|
||||
MouseWrapper.move(0,1);
|
||||
}
|
||||
if (mappedKey.rawKey & KEY_MOUSE_LEFT) {
|
||||
MouseWrapper.move(-1,0);
|
||||
}
|
||||
if (mappedKey.rawKey & KEY_MOUSE_RIGHT) {
|
||||
MouseWrapper.move(1,0);
|
||||
}
|
||||
}
|
||||
|
||||
static bool handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState) {
|
||||
if (! (mappedKey.flags & IS_INTERNAL)
|
||||
&& (mappedKey.rawKey == KEY_MOUSE_BTN_L
|
||||
|| mappedKey.rawKey == KEY_MOUSE_BTN_M
|
||||
|| mappedKey.rawKey == KEY_MOUSE_BTN_R)) {
|
||||
if (key_toggled_on(currentState, previousState)) {
|
||||
MouseWrapper.press_button(mappedKey.rawKey);
|
||||
} else if (key_toggled_off(currentState, previousState)) {
|
||||
MouseWrapper.release_button(mappedKey.rawKey);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(mappedKey.flags & IS_MOUSE_KEY))
|
||||
return false;
|
||||
|
||||
if (!(mappedKey.rawKey & KEY_MOUSE_WARP)) {
|
||||
handle_mouse_key_event(mappedKey, currentState, previousState);
|
||||
} else if (key_toggled_on(currentState,previousState)) {
|
||||
if (mappedKey.rawKey & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) {
|
||||
// we don't pass in the left and up values because those are the
|
||||
// default, "no-op" conditionals
|
||||
MouseWrapper.warp( ((mappedKey.rawKey & KEY_MOUSE_WARP_END) ? WARP_END : 0x00) |
|
||||
((mappedKey.rawKey & KEY_MOUSE_DOWN) ? WARP_DOWN : 0x00) |
|
||||
((mappedKey.rawKey & KEY_MOUSE_RIGHT) ? WARP_RIGHT : 0x00) );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MouseKeys_::MouseKeys_(void) {
|
||||
event_handler_hook_add (handleMouseKeys);
|
||||
}
|
||||
|
||||
MouseKeys_ MouseKeys;
|
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "MouseKeyDefs.h"
|
||||
|
||||
class MouseKeys_ {
|
||||
public:
|
||||
MouseKeys_ (void);
|
||||
};
|
||||
|
||||
extern MouseKeys_ MouseKeys;
|
Loading…
Reference in new issue