diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index c047ae5a..01baae1f 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -1029,6 +1029,12 @@ The masking API has been removed on **2021-01-01** ## Deprecated APIs and their replacements +### Leader plugin + +The `Leader.inject()` function is deprecated. Please call `Runtime.handleKeyEvent()` directly instead. + +Direct access to the `Leader.time_out` configuration variable is deprecated. Please use the `Leader.setTimeout(ms)` function instead. + ### Source code and namespace rearrangement With the move towards a monorepo-based source, some headers have moved to a new location, and plenty of plugins moved to a new namespace (`kaleidoscope::plugin`). This means that the old headers, and some old names are deprecated. The old names no longer work. diff --git a/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.cpp b/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.cpp index 3e7c833c..ea737802 100644 --- a/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.cpp +++ b/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.cpp @@ -29,7 +29,10 @@ Key Leader::sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1]; KeyEventTracker Leader::event_tracker_; uint8_t Leader::sequence_pos_; uint16_t Leader::start_time_ = 0; +#ifndef NDEPRECATED uint16_t Leader::time_out = 1000; +#endif +uint16_t Leader::timeout_ = 1000; const Leader::dictionary_t *Leader::dictionary; // --- helpers --- @@ -82,10 +85,11 @@ void Leader::reset(void) { sequence_[0] = Key_NoKey; } -// DEPRECATED +#ifndef NDEPRECATED void Leader::inject(Key key, uint8_t key_state) { Runtime.handleKeyEvent(KeyEvent(KeyAddr::none(), key_state | INJECTED, key)); } +#endif // --- hooks --- EventHandlerResult Leader::onNameQuery() { @@ -141,8 +145,16 @@ EventHandlerResult Leader::afterEachCycle() { if (!isActive()) return EventHandlerResult::OK; +#ifndef NDEPRECATED +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" if (Runtime.hasTimeExpired(start_time_, time_out)) reset(); +#pragma GCC diagnostic pop +#else + if (Runtime.hasTimeExpired(start_time_, timeout_)) + reset(); +#endif return EventHandlerResult::OK; } diff --git a/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.h b/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.h index f84b4752..0b730cbf 100644 --- a/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.h +++ b/plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.h @@ -21,6 +21,19 @@ #include "kaleidoscope/KeyEventTracker.h" #include "kaleidoscope/plugin.h" +// ----------------------------------------------------------------------------- +// Deprecation warning messages +#define _DEPRECATED_MESSAGE_LEADER_INJECT \ + "The `Leader.inject()` function is deprecated. Please call\n" \ + "`kaleidoscope::Runtime.handleKeyEvent()` directly instead.\n" \ + "This function will be removed after 2022-09-01." + +#define _DEPRECATED_MESSAGE_LEADER_TIME_OUT \ + "The `Leader.time_out` variable is deprecated. Please use the\n" \ + "`Leader.setTimeout()` function instead.\n" \ + "This variable will be removed after 2022-09-01." +// ----------------------------------------------------------------------------- + #define LEADER_MAX_SEQUENCE_LENGTH 4 #define LEAD(n) Key(kaleidoscope::ranges::LEAD_FIRST + n) @@ -43,9 +56,24 @@ class Leader : public kaleidoscope::Plugin { static const dictionary_t *dictionary; static void reset(void); + +#ifndef NDEPRECATED + DEPRECATED(LEADER_TIME_OUT) static uint16_t time_out; + DEPRECATED(LEADER_INJECT) void inject(Key key, uint8_t key_state); +#endif + + static void setTimeout(uint16_t timeout) { +#ifndef NDEPRECATED +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + time_out = timeout; +#pragma GCC diagnostic pop +#endif + timeout_ = timeout; + } EventHandlerResult onNameQuery(); EventHandlerResult onKeyswitchEvent(KeyEvent &event); @@ -56,6 +84,7 @@ class Leader : public kaleidoscope::Plugin { static KeyEventTracker event_tracker_; static uint8_t sequence_pos_; static uint16_t start_time_; + static uint16_t timeout_; static int8_t lookup(void); };