Merge pull request #71 from algernon/f/hook-rework-part-2

Hook rework part #2
pull/73/head
Jesse Vincent 8 years ago committed by GitHub
commit 231af4d229

@ -44,17 +44,17 @@ void Macros_::play(const macro_t *macro_p) {
}
}
static bool handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MACRO))
return false;
return mappedKey;
if (!key_toggled_on(keyState))
return true;
return Key_NoKey;
const macro_t *m = macroAction(mappedKey.rawKey, keyState);
Macros.play(m);
return true;
return Key_NoKey;
}
Macros_::Macros_ (void) {

@ -22,9 +22,9 @@ static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) {
}
}
static bool handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState) {
static Key handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return false;
return mappedKey;
if (mappedKey.rawKey & KEY_MOUSE_BUTTON) {
uint8_t button = mappedKey.rawKey & ~KEY_MOUSE_BUTTON;
@ -46,7 +46,7 @@ static bool handleMouseKeys(Key mappedKey, byte row, byte col, uint8_t keyState)
}
}
return true;
return Key_NoKey;
}
MouseKeys_::MouseKeys_(void) {

@ -24,12 +24,18 @@ void
Keyboardio_::loop(void) {
KeyboardHardware.scan_matrix();
LEDControl.update();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
custom_loop_t hook = loopHooks[i];
(*hook)(false);
}
Keyboard.sendReport();
Keyboard.releaseAll();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
custom_loop_t hook = loopHooks[i];
(*hook)();
(*hook)(true);
}
}

@ -40,7 +40,10 @@ LEDNumlock::update (void) {
}
void
LEDNumlock::loopHook (void) {
LEDNumlock::loopHook (bool postClear) {
if (!postClear)
return;
if (Layer.isOn (numpadIndex)) {
if (storedLEDMode != us) {
storedLEDMode = LEDControl.get_mode ();

@ -13,7 +13,7 @@ class LEDNumlock : LEDMode {
virtual void setup (void) final;
private:
static void loopHook (void);
static void loopHook (bool postClear);
BreathState breathState;
};

@ -109,9 +109,9 @@ void TestMode_::loop() {
TestMatrix();
}
bool handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t keyState) {
Key handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t keyState) {
Serial.write(row);
return false;
return mappedKey;
}
TestMode_ TestMode;

@ -16,4 +16,4 @@ class TestMode_ {
extern TestMode_ TestMode;
bool handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t keyState);
Key handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t keyState);

@ -5,13 +5,13 @@
#define HOOK_MAX 64
typedef bool (*custom_handler_t)(Key mappedKey, byte row, byte col, uint8_t keyState);
typedef Key (*custom_handler_t)(Key mappedKey, byte row, byte col, uint8_t keyState);
extern custom_handler_t eventHandlers[HOOK_MAX];
void event_handler_hook_add (custom_handler_t hook);
void event_handler_hook_replace (custom_handler_t oldHook, custom_handler_t newHook);
typedef void (*custom_loop_t)(void);
typedef void (*custom_loop_t)(bool postClear);
extern custom_loop_t loopHooks[HOOK_MAX];
void loop_hook_add (custom_loop_t hook);

@ -89,7 +89,8 @@ void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState) {
}
for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
custom_handler_t handler = eventHandlers[i];
if ((*handler)(mappedKey, row, col, keyState))
mappedKey = (*handler)(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
}
handle_key_event_default(mappedKey, row, col, keyState);

@ -33,13 +33,13 @@ static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
}
}
static bool
static Key
layerEventHandler(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | SWITCH_TO_KEYMAP))
return false;
return mappedKey;
handle_keymap_key_event(mappedKey, keyState);
return true;
return Key_NoKey;
}
Layer_::Layer_ (void) {

Loading…
Cancel
Save