💾 Archived View for yujiri.xyz › software › guide › gui.gmi captured on 2023-06-14 at 14:53:35. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-03-20)
-=-=-=-=-=-=-
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 graphical 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 prograns onto one screen). Programs that run in windows start by connecting to your window manager over a Unix socket, and by communicating with the window manager, they negotiate the creation of a window which they can control, along with a block of memory that represents the contents of the window. After that, the program can draw to the window by writing to this region of memory.
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 differentlly: 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 "what should happen when the user clicks this button?" 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. Almost every GUI (graphical user interface) 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.