Skip to content

Commit

Permalink
port the rest of the 'onNameQuery' implementations over to the mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Mar 7, 2024
1 parent 4624f3c commit 640ef19
Show file tree
Hide file tree
Showing 28 changed files with 102 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ namespace plugin {
// =============================================================================
// Event handlers

// -----------------------------------------------------------------------------
EventHandlerResult CharShift::onNameQuery() {
return ::Focus.sendName(F("CharShift"));
}

// -----------------------------------------------------------------------------
EventHandlerResult CharShift::onKeyEvent(KeyEvent &event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

namespace kaleidoscope {
namespace plugin {
Expand All @@ -38,10 +39,9 @@ namespace plugin {
/// normally produced with the `shift` modifier. Crucially, when `shift` is
/// held, and the `Key` to be output does not have the `shift` modifier flag
/// applied to it, the held `shift` modifier will be suppressed.
class CharShift : public Plugin {
class CharShift : public Plugin, public FocusPlugin {

public:
EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult beforeReportingState(const KeyEvent &event);

Expand Down Expand Up @@ -82,6 +82,11 @@ class CharShift : public Plugin {
num_keypairs_ = _num_keypairs;
}

protected:
const __FlashStringHelper *getPluginName() const override {
return F("CharShift");
}

private:
// A pointer to an array of `KeyPair` objects in PROGMEM
KeyPair const *progmem_keypairs_ = nullptr;
Expand Down
3 changes: 0 additions & 3 deletions plugins/Kaleidoscope-Cycle/src/kaleidoscope/plugin/Cycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) {

// --- hooks ---

EventHandlerResult Cycle::onNameQuery() {
return ::Focus.sendName(F("Cycle"));
}

EventHandlerResult Cycle::onKeyEvent(KeyEvent &event) {
if (keyIsInjected(event.state))
Expand Down
9 changes: 7 additions & 2 deletions plugins/Kaleidoscope-Cycle/src/kaleidoscope/plugin/Cycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

constexpr Key Key_Cycle = Key(kaleidoscope::ranges::CYCLE);

Expand All @@ -36,14 +37,18 @@ constexpr Key Key_Cycle = Key(kaleidoscope::ranges::CYCLE);

namespace kaleidoscope {
namespace plugin {
class Cycle : public kaleidoscope::Plugin {
class Cycle : public kaleidoscope::Plugin, public FocusPlugin {
public:
void replace(Key key);
void replace(uint8_t cycle_size, const Key cycle_steps[]);

EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event);

protected:
const __FlashStringHelper *getPluginName() const override {
return F("Cycle");
}

private:
uint8_t toModFlag(uint8_t keyCode);
Key last_non_cycle_key_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ bool DynamicTapDance::dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t t
return true;
}

EventHandlerResult DynamicTapDance::onNameQuery() {
return ::Focus.sendName(F("DynamicTapDance"));
}

EventHandlerResult DynamicTapDance::onFocusEvent(const char *input) {
const char *cmd_map = PSTR("tapdance.map");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@
#include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

namespace kaleidoscope {
namespace plugin {

class DynamicTapDance : public kaleidoscope::Plugin {
class DynamicTapDance : public kaleidoscope::Plugin, public FocusPlugin {
public:
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *input);

void setup(uint8_t dynamic_offset, uint16_t size);

bool dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t tap_count, TapDance::ActionType tap_dance_action);

protected:
const __FlashStringHelper *getPluginName() const override {
return F("DynamicTapDance");
}

private:
uint16_t storage_base_;
uint16_t storage_size_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
namespace kaleidoscope {
namespace plugin {

EventHandlerResult FingerPainter::onNameQuery() {
return ::Focus.sendName(F("FingerPainter"));
}

EventHandlerResult FingerPainter::onSetup() {
color_base_ = ::LEDPaletteTheme.reserveThemes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin/LEDMode.h" // for LEDMode
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

namespace kaleidoscope {
namespace plugin {
Expand All @@ -31,19 +32,22 @@ namespace plugin {
// as there is no benefit of transforming it into a dynamic
// LED mode in terms of PROGMEM or RAM.
//
class FingerPainter : public LEDMode {
class FingerPainter : public LEDMode, public FocusPlugin {
public:
void toggle();

EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();

protected:
void update() final;
void refreshAt(KeyAddr key_addr) final;

const __FlashStringHelper *getPluginName() const override {
return F("FingerPainter");
}

private:
uint16_t color_base_;
bool edit_mode_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ EventHandlerResult IdleLEDs::onKeyEvent(KeyEvent &event) {

uint16_t PersistentIdleLEDs::settings_base_;

EventHandlerResult PersistentIdleLEDs::onNameQuery() {
return ::Focus.sendName(F("PersistentIdleLEDs"));
}

EventHandlerResult PersistentIdleLEDs::onSetup() {
uint16_t idle_time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

namespace kaleidoscope {
namespace plugin {
Expand All @@ -42,14 +43,18 @@ class IdleLEDs : public kaleidoscope::Plugin {
static uint32_t start_time_;
};

class PersistentIdleLEDs : public IdleLEDs {
class PersistentIdleLEDs : public IdleLEDs, public FocusPlugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *input);

static void setIdleTimeoutSeconds(uint32_t new_limit);

protected:
const __FlashStringHelper *getPluginName() const override {
return F("PersistentIdleLEDs");
}

private:
static uint16_t settings_base_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ EventHandlerResult LEDBrightnessConfig::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED;
}

EventHandlerResult LEDBrightnessConfig::onNameQuery() {
return ::Focus.sendName(F("LEDBrightnessConfig"));
}

} // namespace plugin
} // namespace kaleidoscope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@

#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

namespace kaleidoscope {
namespace plugin {

class LEDBrightnessConfig : public kaleidoscope::Plugin {
class LEDBrightnessConfig : public kaleidoscope::Plugin, public FocusPlugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command);


protected:
const __FlashStringHelper *getPluginName() const override {
return F("LEDBrightnessConfig");
}

private:
static uint16_t settings_base_;
static struct settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ namespace plugin {

// =============================================================================

EventHandlerResult LayerNames::onNameQuery() {
return ::Focus.sendName(F("LayerNames"));
}

EventHandlerResult LayerNames::onFocusEvent(const char *input) {
const char *cmd_layerNames = PSTR("keymap.layerNames");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@

#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

namespace kaleidoscope {
namespace plugin {

class LayerNames : public kaleidoscope::Plugin {
class LayerNames : public kaleidoscope::Plugin, public FocusPlugin {
public:
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *input);

void reserve_storage(uint16_t size);

protected:
const __FlashStringHelper *getPluginName() const override {
return F("LayerNames");
}

private:
uint16_t storage_base_;
uint16_t storage_size_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ void Leader::inject(Key key, uint8_t key_state) {
#endif

// --- hooks ---
EventHandlerResult Leader::onNameQuery() {
return ::Focus.sendName(F("Leader"));
}


EventHandlerResult Leader::onKeyswitchEvent(KeyEvent &event) {
// If the plugin has already processed and released this event, ignore it.
Expand Down
10 changes: 8 additions & 2 deletions plugins/Kaleidoscope-Leader/src/kaleidoscope/plugin/Leader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key, Key_NoKey
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

// -----------------------------------------------------------------------------
// Deprecation warning messages
#include "kaleidoscope_internal/deprecations.h" // for DEPRECATED
Expand Down Expand Up @@ -61,7 +63,7 @@ constexpr Key LeaderKey(uint8_t n) {
return Key(kaleidoscope::ranges::LEAD_FIRST + n);
}

class Leader : public kaleidoscope::Plugin {
class Leader : public kaleidoscope::Plugin, public FocusPlugin {
public:
typedef void (*action_t)(uint8_t seq_index);
struct dictionary_t {
Expand Down Expand Up @@ -91,10 +93,14 @@ class Leader : public kaleidoscope::Plugin {
timeout_ = timeout;
}

EventHandlerResult onNameQuery();
EventHandlerResult onKeyswitchEvent(KeyEvent &event);
EventHandlerResult afterEachCycle();

protected:
const __FlashStringHelper *getPluginName() const override {
return F("Leader");
}

private:
Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1];
KeyEventTracker event_tracker_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ EventHandlerResult MacroSupport::beforeReportingState(const KeyEvent &event) {
return EventHandlerResult::OK;
}

EventHandlerResult MacroSupport::onNameQuery() {
return ::Focus.sendName(F("MacroSupport"));
}

} // namespace plugin
} // namespace kaleidoscope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key
#include "kaleidoscope/plugin.h" // for Plugin
#include "kaleidoscope/plugin/FocusPlugin.h" // for FocusPlugin

// =============================================================================
// The number of simultaneously-active `Key` values that a macro can have
Expand All @@ -33,7 +34,7 @@
namespace kaleidoscope {
namespace plugin {

class MacroSupport : public Plugin {
class MacroSupport : public Plugin, public FocusPlugin {
public:
/// Send a key press event from a Macro
///
Expand Down Expand Up @@ -64,9 +65,14 @@ class MacroSupport : public Plugin {

// ---------------------------------------------------------------------------
// Event handlers
EventHandlerResult onNameQuery();
EventHandlerResult beforeReportingState(const KeyEvent &event);


protected:
const __FlashStringHelper *getPluginName() const override {
return F("MacroSupport");
}

private:
// An array of key values that are active while a macro sequence is playing
Key active_macro_keys_[MAX_CONCURRENT_MACRO_KEYS];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ namespace plugin {
uint16_t MagicCombo::min_interval = 500;
#endif

EventHandlerResult MagicCombo::onNameQuery() {
return ::Focus.sendName(F("MagicCombo"));
}

EventHandlerResult MagicCombo::afterEachCycle() {
for (uint8_t i = 0; i < magiccombo::combos_length; i++) {
Expand Down
Loading

0 comments on commit 640ef19

Please sign in to comment.