Single Instance & IPC Event (SDL3)

Short question is, is there a way I can get an SDL3 event when data is written into a pipe? or some other inter process signal? I have a solution using SIGUSR1 on linux but I’m looking for something better.

Long version: I wrote a program that does a fuzzy search on my music collection, and lets me play the song or album (external program, either mpd or vlc). When the window loses focus (or when I choose something) the window is hidden (SDL_HideWindow). I use SDL_WaitEvent so I don’t spin. How do I show the window once it’s hidden? My current solution is having a global hotkey run a script that either launches the process or sends user1 signal, my previous solution (diff app) did a file lock on a named pipe and wrote data when it wanted the app to show again.

For the signal, I use SDL_PushEvent in the signal handler, for the pipe solution I used SDL_WaitEventTimeout with 100ms, and would check the pipe every time. Is there a better solution? I ran my program with strace and it looks like there’s a poll on two unix sockets, but I’m not sure if I can do something with that to create an event? Even a no op would be helpful

I handle this sort of thing by starting up a separate thread using SDL_CreateThread(), whose sole purpose is to read from the pipe and forward the data via SDL_PushEvent().

3 Likes

That sounds like a great solution. I’ll implement this when I port to windows

Side Note:
I don’t have any experience with pipes, but I see that SDL3 supports them in what I assume to be a cross-platform manner using SDL_IOStream and SDL_Process.
SDL_CreateProcess
SDL_GetProcessInput
SDL_GetProcessOutput
SDL_FlushIO

CategoryProcess
CategoryIOStream

1 Like