Mac OS X Unleashed

Mac OS X Unleashed

By John Ray and William C. Ray

Configuring the X Window System

Most configuration of the X Window System is handled by a server resource database. When a client makes a request of the server, the server checks the server resource database to determine user preferences for that client. The server resource database is loaded on a per-user basis via the command xrdb, which needs to be executed automatically after starting X11. xrdb loads configuration information from a dotfile, usually named .X11defaults. .X11defaults usually contains lines similar to the following:

1    xbiff*onceOnly:                on
2    xbiff*wm_option.autoRaise:     off
3    xbiff*mailBox                  /usr/spool/mail/mymail

If you were to include these lines in your .X11defaults file, you would be telling your X server that if xbiff (an X11 program that notifies you when you have new mail) starts, it needs to set certain options.

Line 1 sets an xbiff-specific option regarding how frequently to ring the alarm to tell you that you have mail. Here, it's set to ring a single time when mail arrives. Other options are available to set how many times the alarm should ring, and at what intervals, if you prefer something other than a single ring.

Line 2 sets an option that belongs to the window manager and tells it how you want xbiff treated. Specifically, this tells the window manager not to bring xbiff to the front if it's behind other windows when it needs to notify you. Remember, X11 provides the display, and a separate window manager provides such things as window controls.

Line 3 tells xbiff where to find the mailbox that it's supposed to look at.

Because each client supports different options and allows the window manager different levels of control, and you'll need to consult each client's documentation to learn what you can configure, and what you need to do to configure it. As an idea of what you can do, and perhaps a sample you might like to play with, Listing 19.1 includes a commented listing of my .X11defaults file.

Example 19.1. A Typical .X11defaults File

!  ~/.X11defaults
!   This file is used by xrdb to initialize the server resource
!   database, which is used by clients when they start up.
!
! Default defaults
!
*Font:          *-courier-medium-r-*-*-*-120-*-*-*-*-*-*
*MenuFont:      *-courier-medium-r-*-*-*-140-*-*-*-*-*-*
*BoldFont:      *-courier-bold-r-*-*-*-120-*-*-*-*-*-*
!
! GNU Emacs
!
emacs*BorderWidth:      1
! emacs*Font:           9x15
!
! Clock
!
xclock*borderWidth:             0
xclock*wm_option.title:         off
xclock*wm_option.gadgets:       off
xclock*wm_option.borderContext: off
xclock*wm_option.autoRaise:     off
!
! Load meter
!
xload*font:                 *-courier-medium-r-*-*-*-100-*-*-*-*-*-*
xload*wm_option.title:          off
xload*wm_option.gadgets:        off
xload*wm_option.borderContext:  off
xload*wm_option.autoRaise:      off
!
! Mail notifier
!
xbiff*wm_option.title:          off
xbiff*wm_option.gadgets:        off
xbiff*wm_option.borderContext:  off
xbiff*wm_option.autoRaise:      off
xbiff*wm_option.volume:         20
!
! Terminal Emulator
!
!XTerm*Font:            9x15
XTerm*c132:             true
XTerm*curses:           true
XTerm*jumpScroll:       true
XTerm*SaveLines:        2048
XTerm*scrollBar:        true
XTerm*scrollInput:      true
XTerm*scrollKey:        true
!
XTerm*fontMenu.Label:              VT Fonts
XTerm*fontMenu*fontdefault*Label:  Default
XTerm*fontMenu*font1*Label:        Tiny
XTerm*VT100*font1:                 nil2
XTerm*fontMenu*font2*Label:        10 Point
XTerm*VT100*font2:         -*-lucidatypewriter-medium-r-*-*-*-080-*-*-*-*-*-*
XTerm*fontMenu*font3*Label:        14 Point
XTerm*VT100*font3:         -*-lucidatypewriter-medium-r-*-*-*-140-*-*-*-*-*-*
XTerm*fontMenu*font4*Label:        18 Point
XTerm*VT100*font4:         -*-lucidatypewriter-medium-r-*-*-*-180-*-*-*-*-*-*
XTerm*fontMenu*font5*Label:        24 Point
XTerm*VT100*font5:                 12x24
XTerm*fontMenu*fontescape*Label:   Escape Sequence
XTerm*fontMenu*fontsel*Label:      Selection
XTerm*VT100.Translations:       #override \n    <Key>L1:    set-vt-font(1) set-scrollbar(off) \n    <Key>L2:    set-vt-font set-scrollbar(on) \n    <Key>R4:    string("0x1b") string("[211z") \n    <Key>R5:    string("0x1b") string("[212z") \n    <Key>R6:    string("0x1b") string("[213z") \n    <Key>R7:    string("0x1b") string("[214z") \n    <Key>R9:    string("0x1b") string("[216z") \n    <Key>R11:   string("0x1b") string("[218z") \n    <Key>R13:   string("0x1b") string("[220z") \n    <Key>R15:   string("0x1b") string("[222z")
!
! Netscape
!
netscape*defaultHeight:     850
netscape*anchorColor:       maroon
netscape*visitedAnchorColor:    blue3
!
! screensaver config
!
xscreensaver*programs:     xfishtank -c black -r .1 -f 20 -b 20 \n     /usr/local/X11R5/bin/flame -root \n     /usr/local/X11R5/bin/maze -root
xscreensaver*colorPrograms:
xscreensaver*monoPrograms:

In addition to the server resources database, clients frequently have command-line options that can control the client's interaction with X11. For example:

> xterm -fg "black" -bg "white" -fn 6x10 -geometry 85x30+525+1

This starts an xterm terminal session with the following configuration: black foreground color, white as the background color (black text on a white window), and a 6x10 point font. It also sets the geometry information so that the window is 85 characters wide, 30 characters high, and is placed 525 pixels from the left edge of the screen and 1 pixel down from the top.

Again, different programs have different options available and your location documentation is your best source for up-to-date information on your exact configuration.

Finally, the applications that start when you start X11 (or most standardized installations of X11, including the default XFree86 installation) are configured by the execution of a file named .xinitrc in your home directory. This is a shell script file, containing a collection of commands that you want executed when X11 starts. Therefore, you can put in it lines that start xterm terminals, clocks, editors, and any other X11-based applications that you'd like to have start in your environment. The lines are exactly the commands you'd type at the command line to start these applications, so the earlier comments about the wide variability of the configuration options apply here as well. Listing 19.2 shows the contents of my .xinitrc file, which produces the X11 environment shown in Figure 19.1.

Example 19.2. A Typical .xinitrc File

#!/bin/sh

xrdb -load $HOME/.X11defaults
xset m 2 5 s off
xset fp+ /usr/X11R6/lib/X11/fonts

# xmodmap -e 'keysym BackSpace = Delete'
echo  "XTerm*ttyModes:erase ^H" | xrdb -merge

/usr/X11R6/bin/twm &

/usr/X11R6/bin/xclock -bg "slategrey" -fg "lightgrey"  -analog -geometry 60x60+220+1

      ccc.gif
    -padding 4 &

xterm -rw  -si -sl 2000 -cr  "slategrey" -bg "white" -fg "black" -fn 6x10 -geometry

      ccc.gif
    80x38+1+287 &
xterm -rw  -si -sl 2000 -cr  "slategrey" -bg "white" -fg "black" -fn 6x10 -geometry

      ccc.gif
    77x40+1+267 &
xterm -rw  -si -sl 2000 -cr  "slategrey" -bg "white" -fg "black" -fn 6x10 -geometry

      ccc.gif
    80x15+1+87 &

xterm -cr  "slategrey" -fg "black" -bg "white" -fn 6x10 -geometry 82x73+507+1 -xrm

      ccc.gif
    "XTerm*backarrowKey:false" -e emacs -nw &

xterm -rw -sf -si -sl 2000 -cr  "slategrey"  -bg "white" -fg "black" -fn 6x10 -geometry

      ccc.gif
    80x4+1+694 &
xterm -cr "slategrey" -fg "black" -bg "white" -fn 6x10 -title "CONSOLE"
    Â-C -geometry 80x24+1+1 -T Console -iconic

Finally, window managers have their own configuration files that control display options and, possibly, other parameters regarding the user experience.

Window Managers: twm, mwm

After you've started the X Window System environment, and confirmed that you want to switch into it with the dialog, you will be presented with a screen much like the one shown in Figure 19.9. This is the current default for a user who has no .xinitrc file to control what applications to start and where to put them, and no .twmrc file to control what the applications look and feel like. Remember that the X Window System provides only interface, component, and display functionality; additional programs are required to provide a useful user interface. In Figure 19.1, you are actually looking at the result of 10 programs running simultaneously (not counting the X Window System server and associated programs necessary for it to function) just to create the interface. Six are displaying windows, one is providing an application dock, one a clock, one an editor, and finally, the window manager, twm, is providing the title bars and border controls shown associated with the windows. Start up of the programs occurs in .xinitrc, and the configuration of their appearance is controlled by twm.

19fig09.jpg

Figure 19.9 The current default startup environment for XFree86. More interesting collections of windows and utilities are created by the use of .xinitrc startup scripts.

twm

One of the most common window managers is twm (tabbed window manager). Shown managing the display in Figure 19.1, twm provides very basic window management functions, and is the default window manager used by XFree86. Even though it is one of the less feature-filled window managers, twm is convenient and allows an extreme amount of user customization of the environment. If you choose to do so, you can create your own standard buttons that appear in your twm title bars, and cause them to execute arbitrary commands. You can also build your own pop-up menus, automatically execute commands when the cursor enters windows, customize window manager colors and actions by an application name and type, and a host of other customizations. Listing 19.3 is a portion of my .twmrc file, giving you an idea of the range of configuration options. It's only a portion because the entire file contains 284 individual configuration parameters. I'm particular about how my interface functions, and twm gives me the flexibility to configure every last one of the 284 tweaks it takes to get it how I like it.

Example 19.3. A Representative Sample of a .twmrc Configuration File for the twm X Window System Window Manager

Color
{
    BorderColor "maroon4"

    BorderTileForeground "bisque4"
    BorderTileBackground "darkorchid4"

    TitleForeground "darkslategray"
    TitleBackground "bisque3"

    DefaultBackground "bisque"
    DefaultForeground "slategrey"

    MenuForeground "slategrey"
    MenuBackground "moccasin"
    MenuTitleForeground "slategrey"
    MenuTitleBackground "bisque3"
    MenuShadowColor "bisque4"
    IconForeground "lightgrey"
    IconBackground "slategray"
    IconBorderColor "darkslategray"
    IconManagerForeground "darkslategrey"
    IconManagerBackground "bisque"
    IconManagerHighlight  "maroon4"
}

BorderWidth     4
FramePadding    2
TitleFont      "8x13"
MenuFont       "8x13"
IconFont       "6x10"
ResizeFont     "fixed"
NoTitleFocus

IconManagerGeometry   "=200x10+290+1"

ShowIconManager

IconManagerFont               "variable"
IconManagerDontShow
{
    "xclock"
    "xbiff"
    "perfmeter"
}

ForceIcons
Icons
{
    "xterm"    "terminal"
}

NoTitle
{
  "TWM"
  "xload"
  "xclock"
  "xckmail"
  "xbiff"
  "xeyes"
  "oclock"
}

NoHighlight
{
  "xclock"
  "dclock"
  "xload"
  "xbiff"
}

AutoRaise
{
  "nothing"
}

DefaultFunction f.menu "default-menu"
#WindowFunction f.function "blob"
#Button = KEYS : CONTEXT : FUNCTION
#—————————————————
Button1 =      : root   : f.menu "button1"
Button2 =      : root   : f.menu "button2"
Button3 =      : root   : f.menu "button3"

Button1 =      : title  : f.function "blob"
Button2 =      : title  : f.lower

Button1 =      : frame  : f.raiselower
Button2 =      : frame  : f.move
Button3 =      : frame  : f.lower

Button1 =      : icon   : f.function "blob"
Button2 =      : icon   : f.iconify
Button3 =      : icon   : f.menu "default-menu"
Button1 = m    : icon   : f.iconify
Button2 = m    : icon   : f.iconify
Button3 = m    : icon   : f.iconify
Button3 = c    : root   : f.function "beep-beep"

Function "beep-beep"
{
    f.beep
    f.beep
    f.beep
    f.beep
    f.beep
}

menu "button1"
{
"Window Ops"       f.title
"(De)Iconify"      f.iconify
"Move"             f.move
"Resize"           f.resize
"Lower"            f.lower
"Raise"            f.raise
"Redraw Window"    f.winrefresh
"Focus Input"      f.focus
"Unfocus Input"    f.unfocus
"Window Info"      f.identify
}

menu "button2"
{
"Window Mgr"       f.title
"Circle Up"        f.circleup
"Circle Down"      f.circledown
"Refresh All"      f.refresh
"Source .twmrc"    f.twmrc
"Beep"             f.beep
"Show Icon Mgr"    f.showiconmgr
"Hide Icon Mgr"    f.hideiconmgr
"Feel"             f.menu "Feel"
}

menu "button3"
{
"Clients"             f.title
"Xterm"               ! "xterm &"
"Emacs"               ! "emacs -i &"
"Lock Screen"         ! "xnlock &"
"Xman"                ! "xman &"
"X Text Exitor"       ! "xedit &"
"Calculator"          ! "xcalc &"
}

menu "default-menu"
{
"Default Menu"        f.title
"Refresh"             f.refresh
"Refresh Window"      f.winrefresh
"twm Version"         f.version
"Focus on Root"       f.unfocus
"Source .twmrc"       f.twmrc
"Cut File"            f.cutfile
"Move Window"         f.move
"ForceMove Window"    f.forcemove
"Resize Window"       f.resize
"Raise Window"        f.raise
"Lower Window"        f.lower
"Focus on Window"     f.focus
"Raise-n-Focus"
f.function "raise-n-focus"
"Zoom Window"         f.zoom
"FullZoom Window"     f.fullzoom
"Kill twm"            f.quit
"Destroy Window"      f.destroy
}

RightTitleButton "down" = f.zoom
RightTitleButton "right" = f.horizoom
LeftTitleButton "icon" = f.destroy

mwm

The Motif window manager (mwm) is a popular window manager evolved from a commercial product, and is also a popular window manager for others to attempt to emulate. It provides a somewhat different user experience than twm. The difference is partly because it automatically attaches things such as resize corners to all windows, and partly because of the pretty 3D look it gives to the controls. Figure 19.10 shows mwm managing the same collection of windows managed by twm in Figure 19.1.

19fig10.jpg

Figure 19.10 The mwm window manager, managing the same collection of windows shown in Figure 19.1.

The XFree86 distribution doesn't include any documentation for the mwm window manager, so we don't recommend that you choose it as your window manager unless you're already familiar with it.

Other Window Managers

There aren't many other X Window System window managers available for the XonX project just yet, but people will be creating ports regularly. Several will probably appear by the time this book is published, so we'll give a quick list of some of the interesting ones here:

Keep in mind, when running the X Window System, that the window controls such as title bars and scroll bars are provided by a separate window manager application. The point of repeating this yet again is that it is possible for the window manager to exit, leaving you with a collection of unmanaged windows. This is a slightly disconcerting state in which to find the X Window System because the window manager also controls the input focus. Figure 19.11 shows an X Window System session that has lost its window manager.

19fig11.jpg

Figure 19.11 An X Window System session that has lost its window manager.

Share ThisShare This

Informit Network