Chapter 20. Programming Virtual Consoles

   


The Linux virtual console programming interface is modeled on the one provided with some versions of UNIX. It is not a complete reimplementation (although it is complete enough for source code compatibility with almost all programs), and it provides several valuable extensions.

Linux can multiplex multiple terminal sessions over one screen and one keyboard. Special key sequences allow the user to control which terminal session is currently being displayed. Each of these login sessions has its own keyboard settings (such as whether the Caps Lock key is engaged), terminal settings (such as what the terminal size is, whether the screen is in graphics mode, and what the fonts are), and device entries (such as /dev/tty1, /dev/vcs1, and /dev/vcsa1).

The keyboard and terminal settings together make up virtual consoles (VCs), so called because of their similarity to virtual memory, in which the system uses disk space to provide more usable memory than is physically present in the machine.

Unless you wish to manage or manipulate VCs, you can skip this chapter. A few programming libraries manage VCs for you, but you may still need to know what they are doing behind your back, so that you work with them rather than against them.

For instance, svgalib, a library for using graphics on several types of graphics controllers, has functions that do most of the basic VC manipulation for you. It still requires that you avoid writing random bits to the graphics controller while it is in text mode; doing so would scramble the screen. The current lack of documentation for svgalib makes it even more important that you know what is going on underneath.[1]

[1] We do not recommend using svgalib to do graphics programming. Many books document programming for the X Window System, and X provides a far saner, safer, and portable method of graphics programming. On the other hand, if you actually want to program the X Window server, you may need to program VCs. You have then come full circle and still need to read this chapter.

VCs provide users with many options, but the majority of users ignore the options and simply use the X Window System. Those users who do use VCs can

  • Choose a separate font for each VC

  • Choose a separate terminal size for each VC

  • Choose key mappings (more on these later) for all VCs

  • Choose a different keystroke encoding for all VCs

  • Switch VCs on command with user-specifiable keystrokes

The Linux Documentation Project (LDP) has documents explaining how the user can use programs that already exist in order to take advantage of these capabilities. Your goal is different you wish to program VCs, not just use them. Although font setting and keyboard settings are well encapsulated in utilities[2] that you can simply call from within your programs, there are cases in which those external programs are insufficient.

[2] Read the man pages for the loadkeys, dumpkeys, keytables, setfont, and mapscrn utilities.


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net