Rearranged and commented Layer.on() and Layer.off()

The boolean wasOn was unnecessary, and there was no need to call
bitSet() (or bitClear(), in the case of Layer.off()) if the test
passed. Mostly, I just added a few explanatory comments.

(Aslo reversed the sense of the on/off test in Layer.on() and .off())

@algernon likes it better this way, and I agree.
pull/258/head
Michael Richters 7 years ago committed by Jesse Vincent
parent 0870a2d560
commit c060c5ef7e

@ -136,29 +136,39 @@ void Layer_::on(uint8_t layer) {
if (layer_count != 0 && layer >= layer_count) if (layer_count != 0 && layer >= layer_count)
return; return;
bool wasOn = isOn(layer); // If the target layer was already on, return
if (isOn(layer))
return;
// Otherwise, turn on its bit in LayerState
bitSet(LayerState, layer); bitSet(LayerState, layer);
// If the target layer is above the previous highest active layer,
// update highestLayer
if (layer > highestLayer) if (layer > highestLayer)
updateHighestLayer(); updateHighestLayer();
/* If the layer did turn on, update the keymap cache. See layers.h for an // Update the keymap cache (but not liveCompositeKeymap; that gets
* explanation about the caches we have. */ // updated separately, when keys toggle on or off. See layers.h)
if (!wasOn)
updateActiveLayers(); updateActiveLayers();
} }
// Deactivate a given layer // Deactivate a given layer
void Layer_::off(uint8_t layer) { void Layer_::off(uint8_t layer) {
bool wasOn = isOn(layer); // If the target layer was already off, return
if (!bitRead(LayerState, layer))
return;
// Turn off its bit in LayerState
bitClear(LayerState, layer); bitClear(LayerState, layer);
// If the target layer was the previous highest active layer,
// update highestLayer
if (layer == highestLayer) if (layer == highestLayer)
updateHighestLayer(); updateHighestLayer();
/* If the layer did turn off, update the keymap cache. See layers.h for an // Update the keymap cache (but not liveCompositeKeymap; that gets
* explanation about the caches we have. */ // updated separately, when keys toggle on or off. See layers.h)
if (wasOn)
updateActiveLayers(); updateActiveLayers();
} }

Loading…
Cancel
Save