Customizing X Windows Tips Jim Knoble, jmknoble@mercury.interpath.com V1.1.1, March 1996 1. Preface ``Red Hat Tips'' are documentation meant to help Red Hat users with specific tasks. Some of these documents are for new users, some are for advanced users. Hopefully each document will also be of help for both new and advanced users. If you have contributions to make, please send them to tech-sup@redhat.com. If you have changes that need to be made to individual Tips, send them to the author of that document. 2. Introduction This document explains the basics of customizing various aspects of the X Window System on Red Hat Linux, giving pointers to other information. It is intended chiefly for users new at customizing X, although moderately experienced users may benefit also. 3. Parts is Parts Several different pieces come together to form the X Window System: not only is there a ``server'' program, which takes care of knowing about the display and keyboard, but there are also ``window managers'' to take care of putting titles on program windows and icons, and many ``client'' programs can be customized through various ``resources''. In addition to those parts, Red Hat Linux provides a startup script, which runs often-used programs each time you start X Windows. 4. The Startup Script Red Hat Linux is configured to run a script called Windows using the startx command. If you login to X using xdm (the X Display Manager), the startup script is called programs in each script by making .xsession a symbolic link to .Xclients (done by default in the root account) using the following commands (don't type the lines beginning with #): # change to your home directory. cd ~ # if `.xsession' already exists, rename it in case # there's something important in it. mv .xsession .xsession.orig # link `.xsession' to `.Xclients'. ln -sf .Xclients .xsession If you already had a file named .xsession in your home directory, the second command above renames it. Once you're certain there is nothing important in it, you can delete it with: rm .xsession.orig 4.1. Some Background for .Xclients start X, and when the script finishes running, X Windows ends as well. Normally, commands in a shell script are run ``in the foreground''---that is, each command runs when the previous command finishes running. Unfortunately, this won't work for an X Windows startup script, since the first X client you start would have to exit before the second one could start, and what you really want to be able to do is to start them all one right after the other, ``in the background''. You can run commands in the background by putting an & (ampersand) character at the end of the command, e.g.: xclock & This is how you should run most of the X clients in your LAST command in .Xclients in the FOREGROUND (i.e., without the &), otherwise X will start, run your startup script, and then exit immediately. Under Linux, the convention is to make the last command start your window manager, so that when you exit your window manager, you exit X Windows. 4.2. How to Make a .Xclients Script You can make a .Xclients script using your favorite text editor (e.g., vi, emacs, joe, jed, ed, etc.). Since it's a script, make sure the first line contains the name of the shell you want to use to run it, e.g., for sh (the Bourne shell): #!/bin/sh or for csh (the C shell): #!/bin/csh (if you don't know which shell to use, you may wish to use the example script below as a starting point). The commands you typically put in your startup script are X clients that you want to run every time you start X Windows, such as a clock, a mailbox checker, a terminal window, or a button bar. The last command should start your window manager. Here is an example of a simple .Xclients script: #!/bin/sh # # .Xclients: startup script for X Windows # # start a clock in the upper lefthand corner. xclock -geometry +0+0 & # # start a program to check for new mail. xbiff & # # start a terminal window for typing commands, # with a login shell. xterm -ls & # # start a window manager in the foreground; # when we exit this, we exit X Windows. # the `exec' command isn't necessary, but it # saves a little bit of memory. exec fvwm # # -------- End of .Xclients -------- When you're done creating the script, save it to .Xclients in your home directory, and then make sure you can run it as a script using the following command: chmod ug+x .Xclients 5. Customizing the X Server The ``X server'' is the program that knows how to draw windows on your screen, read keypresses from the keyboard, and read points, clicks, and drags from the mouse. All of these parts together are called the ``X display''. The X server allows some degree of customization of the display using the xset program. 5.1. Changing X Display Settings Some of the settings you can change using `xset' are: o the ``beep'' setting o mouse acceleration o the builtin screensaver 5.1.1. Turning the Beep On or Off If you don't want the X display to beep (for instance, when you send a control-G or ``bell'' character to xterm), you can turn it off using: xset b off to turn the beep on, use: xset b on 5.1.2. Mouse Acceleration If you want to ``accelerate'' mouse motion (so that you don't have to move the mouse very far to move the cursor from one edge of the screen to the other), you can change the acceleration: xset m is a number (such as `4' or `3/2') such that, when you move the mouse fast, it travels that many times further than normal. 5.1.3. The Default Screensaver If you want the builtin screensaver to come on after a certain amount of inactivity, you can turn it on or change the time period that it waits. To turn on the screensaver, use the following command: xset s on To make sure the screen is blanked, use: xset s blank To change the number of seconds after which to activate the screensaver, use: xset s 5.1.4. Notes and Pointers NOTE that these settings will only affect the current X Windows session. If you want to change the settings every time you use X Windows, put the commands in your .Xclients script (you don't need to run xset in the background). See the manual page for xset for more information. 5.2. Changing Root Window Settings In X Windows, the ``root window'' is the first window that gets created; all other windows get drawn on top of it. In effect, the root window acts as a ``backdrop'' for your X session. The root window has several properties that you can change to suit your taste: o the color of the root window o the shape of the mouse cursor 5.2.1. Root Window Color To set the color of the root window to gray, use the following command: xsetroot -gray To set the color of the root window to any solid color, use the following command: xsetroot -solid is either the name or the hexadecimal value of a color. For example, both of the following are equivalent: xsetroot -solid white xsetroot -solid '#ffffff' You can find names of colors in the ``RGB database'', located in /usr/X11R6/lib/X11/rgb.txt. 5.2.2. Mouse Cursors You can change the shape of the mouse cursor when it is above the root window (this doesn't change the cursor when it is above other windows) using the following command: xsetroot -cursor_name is one of the ``standard'' X Windows mouse cursor shapes. Here is a list of some interesting ones to try out: xsetroot -cursor_name draped_box xsetroot -cursor_name hand1 xsetroot -cursor_name hand2 xsetroot -cursor_name iron_cross xsetroot -cursor_name left_ptr xsetroot -cursor_name plus xsetroot -cursor_name top_left_arrow xsetroot -cursor_name watch In fact, you can use this feature of xsetroot in your are starting up, and then change it to a cursor of your liking just before the end of the script. For example: #!/bin/sh # # .Xclients: startup script for X Windows # # show a watch cursor to indicate # that we're starting things up xsetroot -cursor_name watch # # start clock xclock & # # (other X clients here) # # change to a regular pointer to show # that we're ready for use xsetroot -cursor_name top_left_arrow # # and finally, start window manager exec fvwm # # -------- End of .Xclients -------- The full list of cursors is available in the X Windows include file /usr/X11R6/include/X11/cursorfont.h; each cursor shape is called XC_---you should leave off the XC_ prefix when using these names with xsetroot. 5.2.3. Notes and Pointers NOTE that, much like xset the above commands will only affect the current X Windows session. If you want to change the settings every time you start X Windows, put the commands in your background). For more information, see the manual page for xsetroot. For information about putting color graphic pictures (``wallpaper'') in the root window, see the manual page for xv (from the xv package) and xpmroot (from the fvwm package). 6. Customizing the Window Manager The ``window manager'' is the program that puts ``decorations'' (title bars and borders) on your X programs' windows and allows you to move them around, resize them, iconify them, deiconify them, send them to the back or front of the display, and otherwise ``manage'' them. Most modern window managers allow for some degree of customization. The window managers that ship with Red Hat Linux are: o twm, which is part of the XFree86 package, comes with almost all X Windows distributions, and many people who have used X before will know who to use twm. o fvwm is a free window manager created by Rob Nation; it is designed to use less memory than twm, and it provides many useful features. fvwm is widely used by users of Linux. Both twm and fvwm are highly configurable, with too many options and features to list here. See their extensive manual pages for information on how to configure them. Additionally, both twm and fvwm come with a ``stock'' configuration file which you can copy to your home directory and modify to suit your tastes. Here are the locations of these configuration files and the names you should copy them to: # for `twm' cp /etc/X11/twm/system.twmrc ~/.twmrc # # or, for `fvwm' cp /etc/X11/fvwm/system.fvwmrc ~/.fvwmrc For yet more information about fvwm, see the Fvwm Web Page at http://www.hpc.uh.edu/fvwm/. 7. Customizing X Clients Many programs written for X Windows (``X applications'' or ``X clients'') share a common way of configuring things like fonts, colors, default window size and placement (``geometry''), etc. These configurable items are called ``X resources'' or just ``resources''. Some X clients, in fact, need to have certain resources configured by default in order to run correctly. There are two main places that X Windows programs will look for resource settings when you run them: o in their ``application defaults'' or ``app-defaults'' file o in the ``X resource database'' 7.1. Application Defaults Each X application has a separate app-defaults file, which is located in the directory /usr/X11R6/lib/X11/app-defaults/ and is called by the ``application name'' or ``class name'', which does not necessarily have to be (and very often isn't) the same as the name of the program. For instance, the xcalc program for X Windows looks for its application defaults in the file /usr/X11R6/lib/X11/app- defaults/XCalc. This is true even if we rename xcalc to myxcalculator. Each resource in an app-defaults file automatically has the class name of the application prepended to it---by definition, an app-defaults file doesn't usually apply to more than one X application (although it applies to all COPIES of that application). Note also that the resource settings in the app-defaults file apply to an X Windows program no matter who is running it---everyone gets to use the app-defaults. For this reason, it is generally a good idea to leave most of the resource settings in the app-defaults file alone and copy them to your .Xdefaults file instead (see below). 7.2. Your .Xdefaults file The ``X resource database'' is a conglomeration of resources very similar to the ``environment'' for the Unix shell. When you start an X Windows session, any resource settings which are defined in a file in your home directory called .Xdefaults are automatically loaded into the resource database. Each resource setting in your .Xdefaults file should start with an application name, UNLESS you intend for the resource setting to apply to more than one application (see below). Resource settings in your .Xdefaults file only get loaded every time YOU start an X session---they don't affect anyone else. For this reason, your .Xdefaults file is a good place to put customized resource settings, such as foreground and background colors, application fonts, etc. If you wish to customize an application's resource settings, you can copy the relevant portion from the app- defaults file and put it in your .Xdefaults file---don't forget to add the application name at the beginning of each resource setting. 7.3. Setting Resources Since the syntax of resource settings is rather complex, it is best illustrated by example. Here is a simple .Xdefaults file, specifying several different types of resource settings: ! sample .Xdefaults file ! ! (exclamation points start comments) ! (resource names are on the left) ! (resource values appear on the right of the colon) ! ! set a general background color for most applications ?*Background: gray ! note---this could also be simply ! `*Background: gray' ! ! some settings for xterm ! ! the first title here is superseded by the second one, ! not because of position (first/second), but because ! of precedence rules. Resources starting with ! ``program names'' (e.g., `xterm') supersede those ! starting with ``class names'' (e.g., `XTerm'). *XTerm*title: This Title Doesn't Work *xterm*title: Terminal ! ! here, the first setting is again superseded by the ! second one because of precedence rules. Although ! the resources both begin with ``class names'', the ! second one is more specific (a `*' is a sort of ! ``wildcard'' character, while the `.' is not). *XTerm*font: fixed *XTerm.font: lucidasanstypewriter-12 ! ! this setting overrides the Background setting above, ! but only for XTetris. Again, more specific resource ! settings supersede more general ones. *Xtetris*Background: #303030 ! ! -------- End of sample .Xdefaults -------- The best place to find out what resources an X application will accept is the documentation or manual page accompanying the application. The next best place is in the app-defaults file---just copy the entries you need, put them in your the same as name of the app-defaults file) at the beginning of each resource. You can also use an X Windows program called editres to find out what resources an application responds to; you need to be running X to use it. See the editres manual page for more information. 7.4. Notes and Pointers NOTE that, since your .Xdefaults resources are loaded each time you start an X Windows session, any changes you make won't take effect until you quit X and login (or start X) again. Or, to add changes to the resource database, see the manual page for xrdb. For further information on X resources, see the manual page for X. For information on names of fonts to use in X resources, see the manual pages for xlsfonts and xfontsel. 8. Other Sources of Information X is a very complex windowing system, and customizing it is not always simple. If the manual pages don't have the information you need, there are several other places to look: o The X Consortium (the folks who maintain X) have a Web Page with all manner of information, including info about X, about the X Consortium, various projects which are underway, etc. All of this is available at http://www.x.org/. o O'Reilly and Associates publishes a complete multivolume set of books on all aspects of the X Window system. Visit O'Reilly's web page for more information at http://www.ora.com/. o Usenet News has several newsgroups dedicated to the X Window System: news:comp.os.linux.x (for Linux-related questions) news:comp.windows.x.i386 (for questions about XFree86) news:comp.windows.x (for general questions about X) news:comp.answers (for FAQs and regular postings related to X Windows) 9. Copyright Notice This document is Copyright (C) 1996 by Jim Knoble. Redistribution of this document is permitted as long as the content remains completely intact and unchanged. In other words, you may reformat and reprint or redistribute only.