[ion] Add an event journal

It's pretty much just two callbacks that one can hook into to get some
events in or out of Ion.

It adds a couple useless checks and pointers to any build and could be
hidden behind a feature flag, but the extra weight is minimal.
This commit is contained in:
Romain Goyet
2020-09-03 23:00:20 -04:00
committed by Léa Saviot
parent 62aafa7597
commit cbc3951ab1
2 changed files with 36 additions and 1 deletions

View File

@@ -53,6 +53,15 @@ enum class ShiftAlphaStatus {
// Timeout is decremented
Event getEvent(int * timeout);
class Journal {
public:
virtual void pushEvent(Event e) = 0;
virtual Event popEvent() = 0;
};
void replayFrom(Journal * l);
void logTo(Journal * l);
ShiftAlphaStatus shiftAlphaStatus();
void setShiftAlphaStatus(ShiftAlphaStatus s);
void removeShift();

View File

@@ -50,7 +50,11 @@ void resetLongRepetition() {
ComputeAndSetRepetionFactor(sEventRepetitionCount);
}
Event getEvent(int * timeout) {
static Keyboard::Key keyFromState(Keyboard::State state) {
return static_cast<Keyboard::Key>(63 - __builtin_clzll(state));
}
static inline Event innerGetEvent(int * timeout) {
assert(*timeout > delayBeforeRepeat);
assert(*timeout > delayBetweenRepeat);
int time = 0;
@@ -114,5 +118,27 @@ Event getEvent(int * timeout) {
}
}
static Journal * sSourceJournal = nullptr;
static Journal * sDestinationJournal = nullptr;
void replayFrom(Journal * l) { sSourceJournal = l; }
void logTo(Journal * l) { sDestinationJournal = l; }
Event getEvent(int * timeout) {
if (sSourceJournal != nullptr) {
Event e = sSourceJournal->popEvent();
if (e == None) {
sSourceJournal = nullptr;
} else {
return e;
}
}
Event e = innerGetEvent(timeout);
if (sDestinationJournal != nullptr && e != None) {
sDestinationJournal->pushEvent(e);
}
return e;
}
}
}