I’m looking for the simplest, lowest-cost program to display a window in Win32 and X11 without requiring any dependencies. I got a basic Win32 window working, executable size is 6KB, but it is far from perfect and probably inefficient. I can’t get an equivalent X11 established.
The window will need to be able to redraw text, be resized. Mostly though the problem is the OS doesn’t recognize that a window is opened, or the program crashes immediately.
A basic window with graphics context or a cross-platform GUI application framework? I assume the latter based on the your mention of rendering text, though there are some lightweight immediate-mode APIs that work with the former.
If you are asking for an application framework, does it need to be native?
The most basic window. I finally put together something that works in X11, compiles to only 4.5KB of program size and allows me to print unicode characters to the screen which is most of what I need. The handlers are easy enough with knowledge of the X Protocol. I have an equivalent version in Win32 that already works without dependencies. I wouldn’t use it for a “real” program or call it a windowing system but for putting a window on the screen it is sufficient. I want to clean up the program before sharing it.
Wayland is quite a bit more complicated to do from scratch than the others, there isn’t really a robust way to just link to a system library and call the functions to create a window like there is with Win32 and X11.
You will need to know which Wayland protocols you are using, then generate/implement some bindings for those interfaces and their protocol version. If this is beyond the scope of what you were looking to get into, you could just let it fallback to XWayland on Wayland hosts.
Thanks. Since what I need is very simple, single-window programs and dialog boxes, I don’t think I need to worry too much about moving up to Wayland. I will need to be able to read from the clipboard for copy and pasting.
Wayland is quite a bit more complicated to do from scratch than the others
The wayland wire protocol is fairly trivial to implement; the hardest part is creating a code generator but that too is doable. I have recently created a pure-zig Wayland library (which I still need to update to zig 0.17) and the only annoying thing was zigs stdlib not supporting sending/receiving filedescriptors over unix domain sockets yet so I had to hand-roll that.
Once you have a wayland implementation it is also trivial to open a simple window with an shm backed buffer.
The bigger issue with wayland is that since all rendering is client side, you’ll likely want to use an external font drawing library. Hardware-accelerated rendering you can only do with mesa, which requires linking libwayland.
Keyboard handling is also annoying, you’ll need to either link xkbcommon or create a client implementation of it yourself. I’ve done that, it’s not fun but possible.
Yes, of course, there are no shortage of projects that do this, as well as generators, though they explicitly stated they did not want to include any dependencies. All of this and the steps required to do this are much more complicated than just linking to a system library and calling CreateWindowEx or XCreateSimpleWindow.
When coming from the base of “how do I create a window”, calling something that requires learning and implementing how the protocol works, figuring out which interfaces/versions are needed, implementing the generator (must also implemt XML parsing to do this), and writing extensive boilerplate as “trivial” seems like an understatement. My impression was that OP was looking for something like a WaylandCreateWindow and WaylandDrawString, and were not aware Wayland had no such APIs.
Additionally both Win32 and X11 have built-in ways to render text to the window, which is going to be its own sidequest to do the same with Wayland. This would be its own external dependency unless they want to also implement parsing and rendering fonts, so the level of complexity is growing rapidly.