[ion] Alpha-locked percent becomes backspace

This commit is contained in:
Joachim Le Fournis
2020-04-09 18:09:03 +02:00
committed by GitHub
parent 8dbe719a68
commit 4a9bfca1f6
5 changed files with 25 additions and 11 deletions

View File

@@ -21,7 +21,7 @@ public:
#if DEBUG
const char * name() const;
#endif
Event(Keyboard::Key key, bool shift, bool alpha);
Event(Keyboard::Key key, bool shift, bool alpha, bool lock);
bool operator==(const Event & other) const {
return (m_id == other.m_id);
@@ -56,6 +56,7 @@ void setShiftAlphaStatus(ShiftAlphaStatus s);
void removeShift();
bool isShiftActive();
bool isAlphaActive();
bool isLockActive();
void setLongRepetition(bool longRepetition);
bool isLongRepetition();
void updateModifiersFromEvent(Event e);

View File

@@ -15,7 +15,7 @@ const char * EventData::text() const {
return m_data;
}
Event::Event(Keyboard::Key key, bool shift, bool alpha) {
Event::Event(Keyboard::Key key, bool shift, bool alpha, bool lock) {
// We're mapping a key, shift and alpha to an event
// This can be a bit more complicated than it seems since we want to fall back:
// for example, alpha-up is just plain up.
@@ -41,6 +41,10 @@ Event::Event(Keyboard::Key key, bool shift, bool alpha) {
m_id = offset + (int)key;
} while (offset > 0 && !s_dataForEvent[m_id].isDefined() && m_id < 4*PageSize);
//If we press percent in alphalock, change to backspace
if (m_id == static_cast<uint8_t>(Ion::Events::Percent) && lock){
m_id = static_cast<uint8_t>(Ion::Events::Backspace);
}
assert(m_id != Events::None.m_id);
}

View File

@@ -73,7 +73,8 @@ Event getEvent(int * timeout) {
Keyboard::Key key = (Keyboard::Key)(63-__builtin_clzll(keysSeenTransitionningFromUpToDown));
bool shift = isShiftActive() || state.keyDown(Keyboard::Key::Shift);
bool alpha = isAlphaActive() || state.keyDown(Keyboard::Key::Alpha);
Event event(key, shift, alpha);
bool lock = isLockActive();
Event event(key, shift, alpha, lock);
sLastEventShift = shift;
sLastEventAlpha = alpha;
updateModifiersFromEvent(event);

View File

@@ -29,6 +29,10 @@ bool isAlphaActive() {
return sShiftAlphaStatus == ShiftAlphaStatus::Alpha || sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlpha || sShiftAlphaStatus == ShiftAlphaStatus::AlphaLock || sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlphaLock;
}
bool isLockActive() {
return sShiftAlphaStatus == ShiftAlphaStatus::AlphaLock || sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlphaLock;
}
void setLongRepetition(bool longRepetition) {
sLongRepetition = longRepetition;
}

View File

@@ -8,15 +8,19 @@ using namespace Ion::Events;
QUIZ_CASE(ion_events_from_keyboard) {
/* Ensure all events generated from the keyboard are properly defined */
for (Key k : ValidKeys) {
quiz_assert(Event(k, false, false).isDefined());
quiz_assert(Event(k, true, false).isDefined());
quiz_assert(Event(k, false, true).isDefined());
quiz_assert(Event(k, true, true).isDefined());
quiz_assert(Event(k, false, false, false).isDefined());
quiz_assert(Event(k, true, false, false).isDefined());
quiz_assert(Event(k, false, true, false).isDefined());
quiz_assert(Event(k, true, true, false).isDefined());
quiz_assert(Event(k, false, true, true).isDefined());
quiz_assert(Event(k, true, true, true).isDefined());
}
// Test some fallbacks
quiz_assert(Event(Key::EXE, false, false) == EXE);
quiz_assert(Event(Key::EXE, true, false) == EXE);
quiz_assert(Event(Key::EXE, false, true) == EXE);
quiz_assert(Event(Key::EXE, true, true) == EXE);
quiz_assert(Event(Key::EXE, false, false, false) == EXE);
quiz_assert(Event(Key::EXE, true, false, false) == EXE);
quiz_assert(Event(Key::EXE, false, true, false) == EXE);
quiz_assert(Event(Key::EXE, true, true, false) == EXE);
quiz_assert(Event(Key::EXE, false, true, true) == EXE);
quiz_assert(Event(Key::EXE, true, true, true) == EXE);
}