PrefixLayer: prefer getter/setter methods

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

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

@ -31,11 +31,6 @@
namespace kaleidoscope {
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) {
if (event.state & INJECTED)
return EventHandlerResult::OK;
@ -48,11 +43,11 @@ EventHandlerResult PrefixLayer::onKeyEvent(KeyEvent &event) {
if (event.key.isKeyboardModifier())
return EventHandlerResult::OK;
for (uint8_t i = 0; i < prefix_layers_length; i++) {
if (Layer.isActive(prefix_layers[i].layer)) {
for (uint8_t i = 0; i < prefix_layers_length_; i++) {
if (Layer.isActive(prefix_layers_[i].layer)) {
clear_modifiers_ = true;
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(), IS_PRESSED | INJECTED, prefix_layers_[i].prefix});
Runtime.handleKeyEvent(KeyEvent{KeyAddr::none(), WAS_PRESSED | INJECTED, prefix_layers_[i].prefix});
clear_modifiers_ = false;
}
}
@ -71,6 +66,19 @@ EventHandlerResult PrefixLayer::beforeReportingState(const KeyEvent &event) {
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 kaleidoscope

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

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

Loading…
Cancel
Save