#How it works
##Overview It looks something like this (not draws to scale)
┌───────────────────────────────────────────────┐ │ User │ │ ┌─────────────────────────────────────────┤ │ │ Application │ │ │ ┌──────────┬─────┬─────┬─────┤ │ │ │ ... │ SDL │ GTK │ SDL │ │ │ ├──────────┴─────┴─────┴─────┤ │ │ │ xLib │ │ │ ├────────────────────────────┤ ├─────┴───┬────────┴──┐ X11 │ │ Gnu │ Libraries │ │ │ Tools │ │ │ ├─────────┘ │ │ ├─────────────────────┤ │ │ Linux / kernel │ │ ├─────────────────────┴─────────────────────────┤ │ Hardware │ └───────────────────────────────────────────────┘ We see from the diagram that X11 talks mostly with the hardware. However it needs to talk via the kernel, to initially get access to this hardware.
I am a bit hazy on the detail (and I think it changed since I last looked into it). There is a device /dev/mem that gives access to the whole of memory (I think physical memory), as most of the graphics hardware is memory mapped, this file (see everything is a file) can be used to access it. X11 would open the file (kernel uses file permissions to see if it can do this), then X11 uses mmap to map the file into virtual memory (make it look like memory), now the memory looks like memory. After mmap, the kernel is not involved.
X11 needs to know about the various graphics hardware, as it accesses it directly, via memory.
(this may have changes, specifically the security model, may no longer give access to ALL of the memory.)
##Linux At the bottom is the Linux kernel: a small part of the system. It provides access to hardware, and implements security.
#Gnu Then Gnu (Libraries; bash; tools:ls, etc; C compiler, etc). Most of the operating system.
##X11 Then X11 (Or Wayland, or ...), the base GUI subsystem. This runs in user-land (outside of the kernel): it is just another process, with some privileges. The kernel does not get involved, except to give access to the hardware. And providing inter-process communication, so that other processes can talk with the X11 server.
##X11 library A simple abstraction to allow you to write code for X11.
##GUI libraries Libraries such as qt, gtk, sdl, are next - they make it easier to use X11, and work on other systems such as wayland, Microsoft's Windows, or MacOS.
##Applications Applications sit on top of the libraries.
#Some low-level entry points, for programming
##xlib Using xlib, is a good way to learn about X11. However do some reading about X11 first.
##SDL SDL will give you low level access, direct to bit-planes for you to directly draw to.
#Going lower If you want to go lower, then I am not sure what good current options are, but here are some ideas.
- Get an old Amiga, or simulator. And some good documentation. e.g. https://archive.org/details/Amiga_System_Programmers_Guide_1988_Abacus/mode/2up (I had 2 books, this one and similar).
- Look at what can be done on a raspberry pi. I have not looked into this.
#Links
##X11 https://en.wikipedia.org/wiki/X_Window_System
##Modern ways Writing this got my interest, so I had a look at what the modern fast way to do it is. Here are some links:
https://blogs.igalia.com/itoral/2014/07/29/a-brief-introduction-to-the-linux-graphics-stack/