mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion/sdl] Do not process more than one buffered event
Scenario: Make an infinite loop script (while 1 : 1+1) and run it. Input 1234567 then press Back to interrupt the infinite loop -> the script execution stops, then 1234567 is input in the input line, which is quite weird. It is even weirder when the key pressed during the [script execution / a long computation] result in navigation inside the calculator apps.
This commit is contained in:
committed by
RubenNumworks
parent
9ab3558cfe
commit
90f2e5beed
@@ -171,6 +171,7 @@ Event getPlatformEvent() {
|
||||
}
|
||||
#endif
|
||||
SDL_Event event;
|
||||
Event result = None;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// The while is important: it'll do a fast-pass over all useless SDL events
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
@@ -179,19 +180,35 @@ Event getPlatformEvent() {
|
||||
}
|
||||
}
|
||||
if (event.type == SDL_QUIT) {
|
||||
return Termination;
|
||||
result = Termination;
|
||||
break;
|
||||
}
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
if (IonSimulatorSDLKeyDetectedByScan(event.key.keysym.scancode)) {
|
||||
continue;
|
||||
}
|
||||
return eventFromSDLKeyboardEvent(event.key);
|
||||
result = eventFromSDLKeyboardEvent(event.key);
|
||||
break;
|
||||
}
|
||||
if (event.type == SDL_TEXTINPUT) {
|
||||
return eventFromSDLTextInputEvent(event.text);
|
||||
result = eventFromSDLTextInputEvent(event.text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return None;
|
||||
if (result != None) {
|
||||
/* When events are not being processed - for instance when a Python script
|
||||
* is being executed - SDL puts all ingoing events in a queue.
|
||||
* When events processing goes back to normal, all the queued events are
|
||||
* processed, which can result in weird behaviours (for instance, really
|
||||
* fast navigation in the calculator, "instantanate" text input, ...).
|
||||
* These behaviours are even more visible if the script contains an infinite
|
||||
* loop.
|
||||
* To prevent that, we flush all queued events after encountering a non-null
|
||||
* event -> the first event from the queue will still be processed, but not
|
||||
* the subsequent ones. */
|
||||
SDL_FlushEvents(0, UINT32_MAX);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user