Added to-Key conversion functions

Two new functions have been introduced in namespace kaleidoscope.
One to conveniently add keyflags to an existing Key variable and
another one that can be overloaded to convert other types to type Key.

The keymap definition macros and the modifier function macro (LCTRL,
LALT, ...) are now using the to-Key conversion functions. This
allows users to use alternative ways to define keymaps by
defining types of their own that automatically convert to type Key.

Signed-off-by: Florian Fleissner <florian.fleissner@inpartik.de>
pull/916/head
Florian Fleissner 5 years ago committed by Jesse Vincent
parent 87373803ed
commit 040ce8d1bb
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -44,12 +44,41 @@ void setup();
#include "kaleidoscope/hid.h"
// Note: The CONVERT_TO_KEY macro can be redefined to use different
// host_keymap-keymaps on different layers (see key_defs.h for its
// default definition.
#define CONVERT_AND_CHECK_KEY(KEY) \
( \
( \
struct { \
static_assert(CONVERT_TO_KEY(KEY) != kaleidoscope::bad_keymap_key, \
"Bad key definition: \'" #KEY "\'"); \
} \
){}, \
CONVERT_TO_KEY(KEY) \
)
#ifdef PER_KEY_DATA_STACKED
#define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) }
#define KEYMAP_STACKED(...) \
{ \
MAP_LIST( \
CONVERT_AND_CHECK_KEY, \
PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) \
) \
}
#endif
#ifdef PER_KEY_DATA
#define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) }
#define KEYMAP(...) \
{ \
MAP_LIST( \
CONVERT_AND_CHECK_KEY, \
PER_KEY_DATA(XXX, __VA_ARGS__) \
) \
}
#endif
#include "kaleidoscope/KeyAddr.h"

@ -197,6 +197,13 @@ constexpr Key addFlags(Key k, uint8_t add_flags) {
} // namespace kaleidoscope
// Redefine this macro to enable using alternative char-string to Key
// conversions per layer. This is, howerver, only necessary in rare cases
// (e.g. to use individual host_keymap language maps on
// different layers, see kaleidoscope/host_keymap/host_keymap.h for an example).
//
#define CONVERT_TO_KEY(INPUT) kaleidoscope::convertToKey(INPUT)
// For compatibility reasons make the Key class also available
// in global namespace.
//
@ -213,11 +220,11 @@ typedef kaleidoscope::Key Key_;
#define SYNTHETIC B01000000
#define RESERVED B10000000
#define LCTRL(k) Key(k.getKeyCode(), k.getFlags() | CTRL_HELD)
#define LALT(k) Key(k.getKeyCode(), k.getFlags() | LALT_HELD)
#define RALT(k) Key(k.getKeyCode(), k.getFlags() | RALT_HELD)
#define LSHIFT(k) Key(k.getKeyCode(), k.getFlags() | SHIFT_HELD)
#define LGUI(k) Key(k.getKeyCode(), k.getFlags() | GUI_HELD)
#define LCTRL(k) kaleidoscope::addFlags(CONVERT_TO_KEY(k), CTRL_HELD)
#define LALT(k) kaleidoscope::addFlags(CONVERT_TO_KEY(k), LALT_HELD)
#define RALT(k) kaleidoscope::addFlags(CONVERT_TO_KEY(k), RALT_HELD)
#define LSHIFT(k) kaleidoscope::addFlags(CONVERT_TO_KEY(k), SHIFT_HELD)
#define LGUI(k) kaleidoscope::addFlags(CONVERT_TO_KEY(k), GUI_HELD)
// we assert that synthetic keys can never have keys held, so we reuse the _HELD bits
#define IS_SYSCTL B00000001

Loading…
Cancel
Save