From 4a9bfca1f6a02edfcea5fb5068891f48bfe309e7 Mon Sep 17 00:00:00 2001 From: Joachim Le Fournis <43498612+RedGl0w@users.noreply.github.com> Date: Thu, 9 Apr 2020 18:09:03 +0200 Subject: [PATCH] [ion] Alpha-locked percent becomes backspace --- ion/include/ion/events.h | 3 ++- ion/src/shared/events.cpp | 6 +++++- ion/src/shared/events_keyboard.cpp | 3 ++- ion/src/shared/events_modifier.cpp | 4 ++++ ion/test/events.cpp | 20 ++++++++++++-------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index 2b09c0795..a20873e44 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -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); diff --git a/ion/src/shared/events.cpp b/ion/src/shared/events.cpp index 6a62db538..519c4acd3 100644 --- a/ion/src/shared/events.cpp +++ b/ion/src/shared/events.cpp @@ -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(Ion::Events::Percent) && lock){ + m_id = static_cast(Ion::Events::Backspace); + } assert(m_id != Events::None.m_id); } diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index 6edfadea9..f9535dae3 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -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); diff --git a/ion/src/shared/events_modifier.cpp b/ion/src/shared/events_modifier.cpp index f2bc8b61f..db7e24d43 100644 --- a/ion/src/shared/events_modifier.cpp +++ b/ion/src/shared/events_modifier.cpp @@ -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; } diff --git a/ion/test/events.cpp b/ion/test/events.cpp index d7082936c..0c3fd3298 100644 --- a/ion/test/events.cpp +++ b/ion/test/events.cpp @@ -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); }