I am trying to switch between multiple SDL2 based apps. This is in framebuffer on Debian, rather than any desktop environment.
I am achieving this by pausing execution of apps using
kill -STOP, and selecting/resuming a focused active app using
After much work the only remaining issue I have relates to the joystick event queues. Even when the apps are halted it seems that some process is filling an events queue for each app, so when they are brought back into focus the backlog of events is there to be processed - with uninteded results!
I assume SDL2 is spawning some worker process that I cannot see using
ps and I have failed to halt. How is this implemented? Is there a way to stop the event queue being filled for specific apps or to flush their queues for them?
I assume this is queuing up in a kernel buffer to be emptied by the process when scheduled again, not in a separate process.
SIGSTOP can’t be caught by an app, so you probably can’t tell when to just dump the queue either, without some other way of alerting the app.
That’s an interesting thought. Another search term to investigate anyway, thank you.
If I were attempting to achieve it in app I’d try catching the substantial disparity in system time caused by the paused execution. However, seeing that several apps are affected I need to approach this centrally.
In another tack I’m wondering if I can manage something via udev to deny access to the input on the fly.
To handle this centrally I decided to patch SDL2 instead (it has to be compiled on my platform anyway).
I was looking into adding a timer thread to spot the discontinuity of a paused session.
But then I stumbled upon
You’re right that SIGSTOP can’t be caught, and that’s ok, because really we take action when it resumes execution upon SIGCONT. And that signal appears to be actionable. So I’ll try flushing the effects queue in response to that.
I’ll report back how it goes.
Yep, that worked a treat.