Merge branch 'alfalfasprossen-ledcontrol/shift-invert-next-prev-led-key'

pull/848/head^2
Jesse Vincent 4 years ago
commit 1ae6b5b9ab
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -32,6 +32,7 @@ LEDMode *LEDControl::cur_led_mode_;
uint8_t LEDControl::syncDelay = 32; uint8_t LEDControl::syncDelay = 32;
uint16_t LEDControl::syncTimer = 0; uint16_t LEDControl::syncTimer = 0;
bool LEDControl::enabled_ = true; bool LEDControl::enabled_ = true;
Key LEDControl::pending_next_prev_key_ = Key_NoKey;
LEDControl::LEDControl(void) { LEDControl::LEDControl(void) {
} }
@ -155,10 +156,10 @@ kaleidoscope::EventHandlerResult LEDControl::onKeyswitchEvent(Key &mappedKey, Ke
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
if (keyToggledOn(keyState)) { if (keyToggledOn(keyState)) {
if (mappedKey == Key_LEDEffectNext) { if (mappedKey == Key_LEDEffectNext || mappedKey == Key_LEDEffectPrevious) {
next_mode(); // Handling of these keys is delayed into `beforeReportingState`
} else if (mappedKey == Key_LEDEffectPrevious) { // so that we can incorporate the shift modifier state.
prev_mode(); pending_next_prev_key_ = mappedKey;
} else if (mappedKey == Key_LEDToggle) { } else if (mappedKey == Key_LEDToggle) {
if (enabled_) if (enabled_)
disable(); disable();
@ -174,6 +175,20 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) {
if (!enabled_) if (!enabled_)
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
if (pending_next_prev_key_ != Key_NoKey) {
bool is_shifted =
kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_LeftShift) ||
kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_RightShift);
if ((pending_next_prev_key_ == Key_LEDEffectNext && !is_shifted) ||
(pending_next_prev_key_ == Key_LEDEffectPrevious && is_shifted)) {
next_mode();
} else {
prev_mode();
}
pending_next_prev_key_ = Key_NoKey;
}
if (Runtime.hasTimeExpired(syncTimer, syncDelay)) { if (Runtime.hasTimeExpired(syncTimer, syncDelay)) {
syncLeds(); syncLeds();
syncTimer += syncDelay; syncTimer += syncDelay;

@ -161,6 +161,7 @@ class LEDControl : public kaleidoscope::Plugin {
static uint8_t num_led_modes_; static uint8_t num_led_modes_;
static LEDMode *cur_led_mode_; static LEDMode *cur_led_mode_;
static bool enabled_; static bool enabled_;
static Key pending_next_prev_key_;
}; };
class FocusLEDCommand : public Plugin { class FocusLEDCommand : public Plugin {

Loading…
Cancel
Save