Deprecate old Leader code properly

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1115/head
Michael Richters 3 years ago
parent 2c40e908d5
commit ce31989a9c
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -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.

@ -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;
}

@ -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);
};

Loading…
Cancel
Save