Skip to content

Commit 6cd84d8

Browse files
LeaNumworksEmilieNumworks
authored andcommitted
[ion/keyboard] Fix python keyboard interruption on web
1 parent d0d9ad3 commit 6cd84d8

6 files changed

Lines changed: 16 additions & 7 deletions

File tree

ion/include/ion/keyboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class State {
5353
};
5454

5555
State scan();
56+
State scanForInterruptionAndPopState();
5657
State popState();
5758

5859
static_assert(sizeof(State)*8>NumberOfKeys, "Ion::Keyboard::State cannot hold a keyboard snapshot");

ion/src/device/shared/drivers/keyboard.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
4747
namespace Ion {
4848

4949
namespace Keyboard {
50-
void willPopState() {}
50+
51+
State scanForInterruptionAndPopState() {
52+
/* There is no need to manually scan to get the interruptions, as they are
53+
* done in hardware. We only need to do it on simulators. */
54+
return popState();
55+
}
56+
5157
}
5258

5359
namespace Device {

ion/src/shared/keyboard.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace Ion {
77
namespace Keyboard {
88

99
State popState() {
10-
willPopState();
1110
if (Queue::sharedQueue()->isEmpty()) {
1211
return State(-1);
1312
}

ion/src/shared/keyboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Ion {
77
namespace Keyboard {
88

9-
void willPopState(); // Callback only implemented on simulator, to refresh the window
109
void resetMemoizedState();
1110
void keyboardWasScanned(State state);
1211

ion/src/simulator/shared/keyboard.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ constexpr int sNumberOfKeyPairs = sizeof(sKeyPairs)/sizeof(KeySDLKeyPair);
4747
namespace Ion {
4848
namespace Keyboard {
4949

50-
void willPopState() {
51-
// Grab this opportunity to refresh the display if needed
52-
Simulator::Window::refresh();
50+
State scanForInterruptionAndPopState() {
51+
// We get eventual user interruptions via the simulator keyboard
52+
scan();
53+
return popState();
5354
}
5455

5556
State scan() {
@@ -65,6 +66,9 @@ State scan() {
6566
// Notify callbacks in case we need to do something
6667
Simulator::Keyboard::didScan();
6768

69+
// Grab this opportunity to refresh the display if needed
70+
Simulator::Window::refresh();
71+
6872
#if !EPSILON_SDL_SCREEN_ONLY
6973
// Register a key for the mouse, if any
7074
Key k = Simulator::Layout::getHighlightedKey();

python/port/helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool micropython_port_interrupt_if_needed() {
5757
bool interruption = false;
5858
while (state != Ion::Keyboard::State(-1)) {
5959
interruption = state.keyDown(interruptKey) ? true : interruption;
60-
state = Ion::Keyboard::popState();
60+
state = Ion::Keyboard::scanForInterruptionAndPopState();
6161
};
6262

6363
if (interruption) {

0 commit comments

Comments
 (0)