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.

  • I don't know if this is what your looking for but it gives color. ncurses
    – Joe
    Mar 28 '12 at 6:41
  • You may want to take a look to the Linux Framebuffer.
    – mouviciel
    Mar 28 '12 at 7:22
  • In addition to X and fbdev, there's also SVGALib, which hasn't been updated since 2001.
    – user16764
    Jun 21 '12 at 16:59
  • If you really want to do bare-metal programming (e.g. calling an interrupt to set the video mode), may I suggest DOS?
    – user16764
    Jun 21 '12 at 17:23
  • This looks helpful: tldp.org/HOWTO/Framebuffer-HOWTO
    – Chinasaur
    Sep 10 '12 at 18:44

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).

  • 2
    X is able to use the framebuffer. GTK and Qt, while usually targeting X, are also able to target the framebuffer. Mar 28 '12 at 6:55
  • @AProgrammer: that's true, but it doesn't really change my answer. Most GTK/Qt applications run on X as at the underlying framework (at least for now) and almost no applications use the raw X API directly. Mar 28 '12 at 6:57
  • The framebuffer should, at the very least, support running the graphics card in the standard VESA modes. It might not be perfect (the number of different resolutions is limited, for example, and I don't think any widescreen modes are supported), but it will give you graphics on a Linux system with a minimum number of dependencies.
    – user
    Mar 28 '12 at 9:55

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.


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.

  • Why the downvote?
    – Vreality
    Apr 2 '16 at 12:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.