- Overview -
The main components of a windowing system seem to roughly be:
- hardware interfacing
- communicating with input (mouse, keyboard) and output (screen) devices
- state management
- tracking the state of a window. For example its position, size, parent, children, visibility
- determining the most efficient way to draw a window
- adding window decorations
- window server and client communication
- the server notifying clients of events (eg. mouse move, window exposed)
- clients sending requests to the server (eg. change window title, get contents of clipboard) and receiving responses from the server (eg. contents of clipboard)
- Tutorial -
I came across Joe Marlin’s awesome Windowing Systems By Example tutorial series (archived here). In it, we are shown how to create a simple stacking window manager. It uses clipping regions to draw/update only the visible parts of a window. The series covers the “state management” and “rendering” parts of a windowing system.
Below is a video of what I had by the end of the tutorial. It is not much visually, but the process helped cement a lot of concepts. (Source code can be found here.)
- Backend -
In the tutorial, all graphics are handled by the CPU. (This is great for my use case, as I do not intend to use a GPU in the homebrew computer). However, drawing individual pixels using the CPU is slow. I chose to use C for the emulation (instead of an interpreted language like Python), to help mitigate this.
It took me a while to figure out how to draw a pixel in C. I eventually came across the olcPixelGameEngine by Javidx9. It’s a small, single file library, that allows you to do exactly this. The library has a rich API, but I cut it down to only what is needed to draw a pixel (in Linux and Windows). The slimmed down version is useful not only for this project, but future ones I have in mind.
- Onwards -
The only component that remains a mystery is the “window server and client communication”. Once I figure this out, I will be in a pretty good position to write a simple windowing system.