PrefixLayer: prefer getter/setter methods

Signed-off-by: iliana etaoin <iliana@buttslol.net>
pull/1187/head
iliana etaoin 2 years ago
parent 0810321272
commit a960f5a0cb

@ -61,8 +61,7 @@ KALEIDOSCOPE_INIT_PLUGINS(PrefixLayer);
void setup() { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
/* Configure the previously-defined prefix layers. */ /* Configure the previously-defined prefix layers. */
PrefixLayer.prefix_layers = prefix_layers; PrefixLayer.setPrefixLayers(prefix_layers);
PrefixLayer.prefix_layers_length = 1;
} }
void loop() { void loop() {

@ -31,11 +31,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
static const PrefixLayer::Entry prefix_layers_default_[] PROGMEM = {};
const PrefixLayer::Entry *PrefixLayer::prefix_layers = prefix_layers_default_;
uint8_t PrefixLayer::prefix_layers_length = 0;
bool PrefixLayer::clear_modifiers_ = false;
EventHandlerResult PrefixLayer::onKeyEvent(KeyEvent &event) { EventHandlerResult PrefixLayer::onKeyEvent(KeyEvent &event) {
if (event.state & INJECTED) if (event.state & INJECTED)
return EventHandlerResult::OK; return EventHandlerResult::OK;
@ -48,11 +43,11 @@ EventHandlerResult PrefixLayer::onKeyEvent(KeyEvent &event) {
if (event.key.isKeyboardModifier()) if (event.key.isKeyboardModifier())
return EventHandlerResult::OK; return EventHandlerResult::OK;
for (uint8_t i = 0; i < prefix_layers_length; i++) { for (uint8_t i = 0; i < prefix_layers_length_; i++) {
if (Layer.isActive(prefix_layers[i].layer)) { if (Layer.isActive(prefix_layers_[i].layer)) {
clear_modifiers_ = true; clear_modifiers_ = true;
Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), IS_PRESSED | INJECTED, prefix_layers[i].prefix}); Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), IS_PRESSED | INJECTED, prefix_layers_[i].prefix});
Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, prefix_layers[i].prefix}); Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, prefix_layers_[i].prefix});
clear_modifiers_ = false; clear_modifiers_ = false;
} }
} }
@ -71,6 +66,19 @@ EventHandlerResult PrefixLayer::beforeReportingState(const KeyEvent &event) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void PrefixLayer::setPrefixLayers(const PrefixLayer::Entry *prefix_layers) {
prefix_layers_ = prefix_layers;
prefix_layers_length_ = sizeof(prefix_layers) / sizeof(PrefixLayer::Entry);
}
const PrefixLayer::Entry *PrefixLayer::getPrefixLayers() {
return prefix_layers_;
}
uint8_t PrefixLayer::getPrefixLayersLength() {
return prefix_layers_length_;
}
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope

@ -41,11 +41,14 @@ class PrefixLayer : public Plugin {
: layer(layer), prefix(prefix) {} : layer(layer), prefix(prefix) {}
}; };
static const Entry *prefix_layers; void setPrefixLayers(const Entry *prefix_layers);
static uint8_t prefix_layers_length; const Entry *getPrefixLayers();
uint8_t getPrefixLayersLength();
private: private:
static bool clear_modifiers_; const Entry *prefix_layers_ PROGMEM = {};
uint8_t prefix_layers_length_ = 0;
bool clear_modifiers_ = false;
}; };
} // namespace plugin } // namespace plugin

@ -59,8 +59,7 @@ KALEIDOSCOPE_INIT_PLUGINS(PrefixLayer);
void setup() { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
PrefixLayer.prefix_layers = prefix_layers; PrefixLayer.setPrefixLayers(prefix_layers);
PrefixLayer.prefix_layers_length = 1;
} }
void loop() { void loop() {

Loading…
Cancel
Save