SDL
SDL copied to clipboard
wayland: Implement Non-Zenity MessageBox
With libdecor coming together it really seems like we're close to getting Wayland fully production ready... except oh crap I completely forgot there's no MessageBox implementation at all. This is pretty important to have if we want to preserve application error handling, the SDL_assert UI, and various other things like that.
Unlike lots of other parts of the video subsystem we can't really take notes from X11, since I don't think there's anything remotely close to what we do for that driver:
https://github.com/libsdl-org/SDL/blob/main/src/video/x11/SDL_x11messagebox.c
If we got desperate we could run a zenity subprocess, but that's if there's genuinely no way to do bare-bones popups through Wayland.
I think we're absolutely going to have to use zenity, as there's no barebones widgets and no built-in font rendering at all that we can build on top of, and we're not going to want to link against something like GTK or Cairo to get those things.
The best solution here is likely going to be adding a function to libdecoration.
But we could build out the world's simplest UI, using SDL's render API to draw rectangles for buttons, and pack an extremely small and low-ASCII-only bitmap font into static data. It's not out of the question, it just wouldn't look remotely good.
Considering what the X11 box looks like I guess appearance isn't everything... but the font is the scary part since we do in a lot of cases have to go way beyond ASCII support. Rendering stuff is easy, rendering text not so much.
But if zenity is on the table, I would just go straight for that. Not sure how hard it is to do a whole complete implementation but ShowSimpleMessageBox would be dead simple to scribble together!
Definitely start with zenity. We can rip it out or keep it as a fallback as better options arise in the future.
If zenity fails to launch, just return -1.
Wrote up the implementation... it was less work than I was expecting!
Going to leave this issue open for now, as a "this isn't meant to be the final result," but I'll absolutely accept it for the time being!
Thanks Ethan!
Opened up #4236 to fix something I didn't copy over in my test program... what I get for trying to work on this in an X environment!
Since there's a Zenity one, can we also support KDialog too?
It probably could, this is the only file you have to worry about:
https://github.com/libsdl-org/SDL/blob/main/src/video/wayland/SDL_waylandmessagebox.c
I've looked through the Kdialog options, and it doesn't support adding arbitrary buttons like Zenity does. It only supports some premade message box formats, like --yesno, --yesnocancel, --menu, etc. The only Kdialog option I think might be usable to implement SDL's MessageBox API is --radiolist, with a separate entry for each button the user provides. But that probably doesn't look like what the user is expecting to see:
kdialog --radiolist radiolist tag0 item0 off tag1 item1 off tag2 item2 off tag3 item3 off

With the above in mind, going to change this into a new issue: #6422
Aside from that, Wayland doesn't really have anything special about it... zenity is near-ubiquitous and we have an emergency fallback for the unsupported case; KDialog is the only alternative I'm aware of that doesn't involve GTK/Qt/handmade text rendering and it's too limited to support the API as-is.
With that in mind, closing as WONTFIX, any option that would fix this would fit into #6422.