💾 Archived View for yujiri.xyz › software › guide › gui.gmi captured on 2024-06-16 at 12:38:20. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-12-28)
-=-=-=-=-=-=-
Learn programming for good instead of profit
The reason I put this off for so long is because the story is really complex. Writing any GUI (Graphical User Interface) or windowed program will almost certainly involve several libraries, which is why I don't recommend it to a beginner.
On Linux, windows are provided by a program called a window manager or compositor (because it composits many windowed programs onto one screen). Programs that run in windows start by connecting to your window manager over a Unix socket and asking it to create a window for them. The window manager also establishes a block of shared memory that represents the contents of the window. After that, the program can draw to the window by writing to this region of memory.
What's a Unix socket? How does shared memory work?
The protocol that programs use to communicate with the window manager is called Wayland.
Wayland's predecessor, which is still used in some Linux environments, is called X11, or just X. X works a little differently: in X, the role of a Wayland compositor is split into two different programs: the X server, which controls the graphics hardware, and the window manager, which controls how windows are arranged. Both the window manager and windowed programs communicate directly with the X server.
It doesn't end there. Wayland and X are both very low-level things, and the stuff most windowed prorgams do - like rendering text, buttons, and other user interface elements - is actually incredibly complicated, much more so than you would think*. As an app developer, you'd be crazy to try to implement those things on your own. You would want to use a library that handles the hard stuff, so you can think about questions like "where should this button be?" instead of "what arrangement of shaded pixels do I need to draw to make this square look like a button, or to make it look pressed in when the user clicks on it?" and "how to line-break text?" and "how to support screenreaders?".
There are two main libraries for this: GTK and Qt (pronounced 'cute'). Almost every GUI app on Linux uses one of the two.
Widget, by the way, is short for window gadget, and refers to the elements of a GUI like buttons and text input boxes.