Define constexpr constructors for plugin-specific Key objects

In some cases, we still need preprocessor macros to preserve the same keymap
markup as before, because they convert `X` to `Key_X` (for example).

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1139/head
Michael Richters 3 years ago committed by Jesse Vincent
parent 54ca31f959
commit ec834f2fe5
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -20,7 +20,7 @@
#include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h>
#define Key_Cycle Key(kaleidoscope::ranges::CYCLE)
constexpr Key Key_Cycle = Key(kaleidoscope::ranges::CYCLE);
#define cycleThrough(...) ({ \
static const Key __k[] PROGMEM = { __VA_ARGS__ }; \

@ -22,13 +22,17 @@
#include "kaleidoscope/plugin/Macros/MacroSteps.h"
#define DM(n) Key(kaleidoscope::ranges::DYNAMIC_MACRO_FIRST + n)
#define DM(n) ::kaleidoscope::plugin::DynamicMacrosKey(n)
#define MAX_CONCURRENT_DYNAMIC_MACRO_KEYS 8
namespace kaleidoscope {
namespace plugin {
constexpr Key DynamicMacrosKey(uint8_t n) {
return Key(kaleidoscope::ranges::DYNAMIC_MACRO_FIRST + n);
}
class DynamicMacros : public kaleidoscope::Plugin {
public:
EventHandlerResult onNameQuery();

@ -36,7 +36,7 @@
#define LEADER_MAX_SEQUENCE_LENGTH 4
#define LEAD(n) Key(kaleidoscope::ranges::LEAD_FIRST + n)
#define LEAD(n) kaleidoscope::plugin::LeaderKey(n)
#define LEADER_SEQ(...) { __VA_ARGS__, Key_NoKey }
#define LEADER_DICT(...) { __VA_ARGS__, {{Key_NoKey}, NULL} }
@ -44,6 +44,10 @@
namespace kaleidoscope {
namespace plugin {
constexpr Key LeaderKey(uint8_t n) {
return Key(kaleidoscope::ranges::LEAD_FIRST + n);
}
class Leader : public kaleidoscope::Plugin {
public:
typedef void (*action_t)(uint8_t seq_index);

@ -24,12 +24,21 @@
// ----------------------------------------------------------------------------
// Keymap macros
#define OSM(kc) Key(kaleidoscope::ranges::OSM_FIRST + (Key_ ## kc).getKeyCode() - Key_LeftControl.getKeyCode())
#define OSL(n) Key(kaleidoscope::ranges::OSL_FIRST + n)
#define OSM(k) ::kaleidoscope::plugin::OneShotModifierKey(Key_ ## k)
#define OSL(n) ::kaleidoscope::plugin::OneShotLayerKey(n)
namespace kaleidoscope {
namespace plugin {
constexpr Key OneShotModifierKey(Key mod_key) {
return Key(kaleidoscope::ranges::OSM_FIRST +
mod_key.getKeyCode() - HID_KEYBOARD_FIRST_MODIFIER);
}
constexpr Key OneShotLayerKey(uint8_t layer) {
return Key(kaleidoscope::ranges::OSL_FIRST + layer);
}
class OneShot : public kaleidoscope::Plugin {
public:
// Constructor

@ -24,21 +24,29 @@
#include "kaleidoscope/KeyEventTracker.h"
// DualUse Key definitions for Qukeys in the keymap
#define MT(mod, key) Key( \
kaleidoscope::ranges::DUM_FIRST + \
(((Key_ ## mod).getKeyCode() - Key_LeftControl.getKeyCode()) << 8) + \
(Key_ ## key).getKeyCode() \
)
#define MT(mod, key) kaleidoscope::plugin::ModTapKey(Key_ ## mod, Key_ ## key)
#define SFT_T(key) MT(LeftShift, key)
#define CTL_T(key) MT(LeftControl, key)
#define ALT_T(key) MT(LeftAlt, key)
#define GUI_T(key) MT(LeftGui, key)
#define LT(layer, key) Key(kaleidoscope::ranges::DUL_FIRST + (layer << 8) + (Key_ ## key).getKeyCode())
#define LT(layer, key) kaleidoscope::plugin::LayerTapKey(layer, Key_ ## key)
namespace kaleidoscope {
namespace plugin {
constexpr Key ModTapKey(Key mod_key, Key tap_key) {
uint8_t mod = mod_key.getKeyCode() - HID_KEYBOARD_FIRST_MODIFIER;
return Key(kaleidoscope::ranges::DUM_FIRST +
(mod << 8) + tap_key.getKeyCode());
}
constexpr Key LayerTapKey(uint8_t layer, Key tap_key) {
return Key(kaleidoscope::ranges::DUL_FIRST +
(layer << 8) + tap_key.getKeyCode());
}
// Data structure for an individual qukey
struct Qukey {
// The layer this qukey is mapped on.

@ -20,7 +20,7 @@
#include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h>
#define Key_Redial Key(kaleidoscope::ranges::REDIAL)
constexpr Key Key_Redial = Key(kaleidoscope::ranges::REDIAL);
namespace kaleidoscope {
namespace plugin {

@ -27,8 +27,8 @@
#define SPACECADET_MAP_END (kaleidoscope::plugin::SpaceCadet::KeyBinding) { Key_NoKey, Key_NoKey, 0 }
#endif
#define Key_SpaceCadetEnable Key(kaleidoscope::ranges::SC_FIRST)
#define Key_SpaceCadetDisable Key(kaleidoscope::ranges::SC_LAST)
constexpr Key Key_SpaceCadetEnable = Key(kaleidoscope::ranges::SC_FIRST);
constexpr Key Key_SpaceCadetDisable = Key(kaleidoscope::ranges::SC_LAST);
namespace kaleidoscope {
namespace plugin {

@ -22,7 +22,8 @@
#define SYSTER_MAX_SYMBOL_LENGTH 32
#define SYSTER Key(kaleidoscope::ranges::SYSTER)
constexpr Key Key_Syster = Key(kaleidoscope::ranges::SYSTER);
constexpr Key SYSTER = Key_Syster;
namespace kaleidoscope {
namespace plugin {

@ -24,7 +24,7 @@
#include "kaleidoscope/KeyAddrEventQueue.h"
#include "kaleidoscope/KeyEventTracker.h"
#define TD(n) Key(kaleidoscope::ranges::TD_FIRST + n)
#define TD(n) kaleidoscope::plugin::TapDanceKey(n)
#define tapDanceActionKeys(tap_count, tap_dance_action, ...) ({ \
static const Key __k[] PROGMEM = { __VA_ARGS__ }; \
@ -34,6 +34,11 @@
namespace kaleidoscope {
namespace plugin {
constexpr Key TapDanceKey(uint8_t n) {
return Key(kaleidoscope::ranges::TD_FIRST + n);
}
class TapDance : public kaleidoscope::Plugin {
public:
enum ActionType {

@ -20,11 +20,15 @@
#include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h>
#define TOPSY(k) Key(kaleidoscope::ranges::TT_FIRST + (Key_ ## k).getKeyCode())
#define TOPSY(k) ::kaleidoscope::plugin::TopsyTurvyKey(Key_ ## k)
namespace kaleidoscope {
namespace plugin {
constexpr Key TopsyTurvyKey(Key key) {
return Key(kaleidoscope::ranges::TT_FIRST + key.getKeyCode());
}
class TopsyTurvy: public kaleidoscope::Plugin {
public:
TopsyTurvy(void) {}

@ -21,7 +21,7 @@
#pragma once
#define Key_Turbo Key{kaleidoscope::ranges::TURBO}
constexpr Key Key_Turbo = Key(kaleidoscope::ranges::TURBO);
namespace kaleidoscope {
namespace plugin {

Loading…
Cancel
Save