Rearrange the SYNTHETIC bits, and their handling

Introduces the RESERVED bit, a bit reserved for plugins. If it is set, the core
handlers will not handle the event.

Also rearranges the SYNTHETIC bits, to make slightly more sense. In practice,
this means that LED_TOGGLE was promoted to a flag bit, under IS_INTERNAL.

The handler that deals with synthetic events was updated to look at the flag
bits in an order that does not cause confusion, and preparations were also made
to turn it into an independent handler on its own (but that step has not been
taken yet).

This is just groundwork to clean things up, and make the event flow easier to
follow.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/68/head
Gergely Nagy 8 years ago
parent 2eb61391ee
commit 1acc23063e

@ -1,6 +1,6 @@
#pragma once
#define IS_MACRO B00000001
#define IS_MACRO B00000100
#define M(n) (Key){ KEY_FLAGS|SYNTHETIC|IS_MACRO, n}
#define Key_macroKey1 M(1)

@ -1,6 +1,6 @@
#pragma once
#define IS_MOUSE_KEY B00010000
#define IS_MOUSE_KEY B00000010
// Synthetic, not internal
#define KEY_MOUSE_BTN_L 0x01 // Synthetic key

@ -19,7 +19,8 @@ typedef union {
#define RALT_HELD B00000100
#define SHIFT_HELD B00001000
#define GUI_HELD B00010000
#define SYNTHETIC B10000000
#define SYNTHETIC B01000000
#define RESERVED B10000000
#define LCTRL(k) ((Key) { k.flags | CTRL_HELD, k.rawKey })
#define LALT(k) ((Key) { k.flags | LALT_HELD, k.rawKey })
@ -28,16 +29,15 @@ typedef union {
#define LGUI(k) ((Key) { k.flags | GUI_HELD, k.rawKey })
// we assert that synthetic keys can never have keys held, so we reuse the _HELD bits
#define IS_SYSCTL B00000010
#define IS_CONSUMER B00000100
#define IS_INTERNAL B00001000
#define SWITCH_TO_KEYMAP B00100000
#define SWITCH_TO_KEYMAP_MOMENTARY B01000000
#define IS_SYSCTL B00000001
#define IS_CONSUMER B00000010
#define SWITCH_TO_KEYMAP B00000100
#define SWITCH_TO_KEYMAP_MOMENTARY B00001000
#define IS_INTERNAL B00010000
// IS_INTERNAL key table:
#define LED_TOGGLE 0x01 // Synthetic, internal
#define LED_TOGGLE B00000001 // Synthetic, internal
#define KEYMAP_0 0
@ -253,4 +253,4 @@ typedef union {
#define Key_LEDEffectNext (Key) { KEY_FLAGS | SYNTHETIC | IS_INTERNAL, LED_TOGGLE }
#define Key_LEDEffectNext (Key) { KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE, 0 }

@ -1,18 +1,53 @@
#include "key_events.h"
void handle_synthetic_key_event(Key mappedKey, uint8_t keyState) {
static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.flags & SWITCH_TO_KEYMAP_MOMENTARY ) {
if (key_toggled_on(keyState)) {
if ( keymapEntry.rawKey == KEYMAP_NEXT) {
temporary_keymap++;
} else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) {
temporary_keymap--;
} else {
temporary_keymap = keymapEntry.rawKey;
}
}
if (key_toggled_off(keyState)) {
temporary_keymap = primary_keymap;
}
// switch keymap and stay there
} else if (key_toggled_on(keyState)) {
temporary_keymap = primary_keymap = keymapEntry.rawKey;
Storage.save_primary_keymap(primary_keymap);
}
}
static bool handle_synthetic_key_event(Key mappedKey, uint8_t keyState) {
if (mappedKey.flags & RESERVED)
return false;
if (!(mappedKey.flags & SYNTHETIC))
return false;
if (!key_toggled_on(keyState))
return;
return true;
if (mappedKey.flags & IS_CONSUMER) {
ConsumerControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_INTERNAL) {
if (mappedKey.rawKey == LED_TOGGLE) {
if (mappedKey.flags & IS_INTERNAL) {
if (mappedKey.flags & LED_TOGGLE) {
LEDControl.next_mode();
} else {
return false;
}
} else if (mappedKey.flags & IS_CONSUMER) {
ConsumerControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & IS_SYSCTL) {
SystemControl.press(mappedKey.rawKey);
} else if (mappedKey.flags & SWITCH_TO_KEYMAP ||
mappedKey.flags & SWITCH_TO_KEYMAP_MOMENTARY) {
// Should not happen, handled elsewhere.
}
return true;
}
custom_handler_t eventHandlers[HOOK_MAX];
@ -96,26 +131,3 @@ void release_key(Key mappedKey) {
}
Keyboard.release(mappedKey.rawKey);
}
void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.flags & SWITCH_TO_KEYMAP_MOMENTARY ) {
if (key_toggled_on(keyState)) {
if ( keymapEntry.rawKey == KEYMAP_NEXT) {
temporary_keymap++;
} else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) {
temporary_keymap--;
} else {
temporary_keymap = keymapEntry.rawKey;
}
}
if (key_toggled_off(keyState)) {
temporary_keymap = primary_keymap;
}
// switch keymap and stay there
} else if (key_toggled_on(keyState)) {
temporary_keymap = primary_keymap = keymapEntry.rawKey;
Storage.save_primary_keymap(primary_keymap);
}
}

@ -46,10 +46,8 @@ extern const Key keymaps[][ROWS][COLS];
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t keyState);
// Internal use
void handle_synthetic_key_event( Key mappedKey, uint8_t keyState);
void press_key(Key mappedKey);
void release_key(Key mappedKey);
void handle_keymap_key_event(Key keymapEntry, uint8_t keyState);
bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t keyState);
Key lookup_key(byte keymap, byte row, byte col);

Loading…
Cancel
Save