13

For educational purposes, I'd like to write an application on a Linux environment that can process keyboard events and draw graphics without huge dependencies like X or SDL. I presume that this must be possible, because X and SDL are just programs themselves, so they must rely on other methods inherent to the environment. Is this understanding correct?

If so, where might I learn to write such a program? My limited experience tells me that it would involve making calls to the kernel, and/or writing to special files; however, I haven't been able to find any tutorials on the matter (I am not even sure what to Google).

Also, in case it is relevant, I am running Debian Squeeze on Virtualbox. I have used a netinst cd without networking, so there isn't much installed on it currently. I will install gcc, but I am hoping I can get by with nothing more.

math4tots
  • 437

3 Answers3

14

X (or the X Window System) is practically the most low-level graphics API a Linux application will likely use on a modern Linux Desktop. Most applications won't even bother going that deep and will instead use a GUI toolkit implementation like GTK or Qt.

Below that there's only the hardware drivers and probably some X-internal APIs for the drivers. But those are not meant or designed to be used by normal userspace applications.

You could use the kernel framebuffer device (fbdev), but I don't know how well that supports modern graphics API.

Edit: Wayland is an alternative to X that has only recently found some mainstream adoption. It is now possible to run a Linux-Desktop purely on Wayland with no X-Windows system running at all. Wayland itself depends on an EGL driver underneath (an API strongly related to OpenGL).

Joachim Sauer
  • 11,016
9

If you want to get input events without using X then you will have to read them out of device nodes. Linux has a generic input subsystem called evdev that most drivers take advantage of. So to read input events, you can read from any of the device nodes in /dev/input.

An easy trick to find the mouse device node is to run "cat" on the device nodes one at a time, moving the mouse during each "cat". If you see data coming out to the screen then that is your mouse device node. The relevant header file is linux/input.h. For an example of how to use it, look at the source for xevdev driver.

For low level graphics manipulation, if you are really feeling ambitious, you can generally memory map the framebuffer and do your own bit blts.

5

A good tutorial for low-level graphics on Linux is available here.

A good post on stack overflow for low-level input is available here.

Regardless, you probably want to use framebuffer or drm/kms (framebuffer being the simpler of the two) for graphics and evdev for direct input on Linux.

Vreality
  • 159