Gratuitous Window Dressing, Part 3
Let me first begin with this brief non-paid, non-political statement. Ahem...I was the victim of an outdated style guide! Thanks to everyone who helpfully pointed out that it is X window and not X-Windows. I appreciate that you took the time to write and try to save me some embarrassment. As it turns out, I already knew this, but my last two columns were corrected according to a somewhat flawed editorial style guide. Last I heard, the Linux Journal staff were holding a bonfire and roasting marshmallows on said guide. [Sorry about that Marcel.--Ed.]
But we were talking about not getting enough (X, that is), so let me get back to this. In order to explore this state of more, you will need to be able to log in and out of X fairly readily. If you use a login manager like xdm, gdm or kdm, you might want to start your desktop with startx instead. Then, when you leave X, you return to a text console and a command prompt. On my Red Hat system, I can decide to use the graphical login manager (or not) based on this entry in my /etc/inittab file.
# Run xdm in runlevel 5 # xdm is now a separate service x:5:respawn:/etc/X11/prefdm -nodaemon
Once I comment out the last line and save my changes, I am almost ready. Assuming you are using a graphical login, you could, at this time, reboot your system and the new changes would take effect. You would boot up into a beautiful, text-only console screen. Ah, simplicity. I could also tell you that in order for the changes to take effect, you could just get init to re-read the /etc/inittab file. You do that like this (but don't do it yet).
If you happen to be running a Debian system, (or Storm or Corel), your graphical login manager may be started from one of the rc files. Those are the ones you find under /etc/init.d. In that case, you can terminate the login manager in this manner. Be careful though--if you do it while you are in the session, then your graphical manager session will terminate, X will close and you may lose any work you had open. All that to say you should now save your work, close any applications you had running and log out of the desktop.
This brings up another problem. How do you get to a shell prompt to run init q without being logged into your desktop?
You can, without affecting your current X window session, jump out of that session by hitting Ctrl-Alt-F1. Function key 1 could just as easily be 2, 3, 4, 5 or 6. If you started X from the command line with X, you'll probably see the dialog for the session when you click on Ctrl-Alt-F1. The F2, F3 (and so on) versions should provide you with a text-based login screen. By the way, in case you did not already know this, you can switch from any of these "virtual" terminals (VTs) to another simply by typing Alt-F# (where "#" is the number). To get back to your X window session, you click Ctrl-Alt-F7. Go ahead and try it. Flip back and forth. When you are feeling comfy with this, head on back to a text screen (Ctrl-Alt-F1).
Now that you have a text screen, we'll move on to some fun things. By the way, if you were among those running X from the graphical login manager, now is the time to cancel it, either with init q or through the appropriate rc script. All right. Back to those virtual terminals. So, function keys 1 through 6 represent your virtual terminal numbers while function key 7 is your first X session. What about 8, 9, and 10?
Well, let's try something fun.
The reason our first X terminal is usually at six is because virtual terminals one through six are spoken for in our default /etc/inittab file. Here's the relevant section from my /etc/inittab:
# Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6
What do you think would be affected if you were to log in as root, take your favorite editor (vi, Emacs, pico, nano) and comment out the last line? Give it a try. Like the previous change to the inittab, you still need to get init to re-read the /etc/inittab file.
Now, switch to virtual terminal number six. Suddenly, this is no longer a usable terminal. There is no login prompt. Cool? Well, maybe not, but try this now. Start your X session with this simple command. You might just remember this from the last column:
This gives you a really boring, plain X screen with a single X terminal up in the top left hand corner. You have no way to move it and nothing to be done. Today, we're going to use it to demonstrate something. While you are in that screen, flip back over to your first virtual terminal (Ctrl-Alt-F1). Great. Now, from the text console, go back into your X session by hitting Ctrl-Alt-F7. Was something wrong? Try Ctrl-Alt-F6 instead. Aha!
What happened here is that startx (or xinit) in this case started X on the first available free VT which is now number six (because we turned off the getty on VT 6. Here comes cool trick number two. Leave your boring X session running, and go back to the text console. Now, so that we don't confuse one boring xterm session with another, type this command:
xinit /usr/X11R6/bin/xcalc -- :1
If you switch back to your text console now, you'll notice some interesting things if you try to revisit your X session. Ctrl-Alt-F6 (assuming you still have VT 6 commented out of the inittab) will take you to your xterm. To get to your xcalc session, type Ctrl-Alt-F7. Since you can't type exit at the command prompt of xterm, you need to use the X window escape hatch to close that session. The "oh, my God, I've tried everything and I can't get out of X" escape clause is this -- Ctrl-Alt-Backspace.
Here's something else that you might find interesting. You can also define which virtual terminal you want X to start on. Say that ten is your lucky number and you like your X session to start on VT 10.
startx -- :1 vt10
I said that I would get back to some of these ".X" files, and this time around I want to talk about your .Xresources file. By now, you may have already started to get the idea that your desktop is an amazingly configurable environment. While the window manager does some things, you can exert further control still. For instance: If I start an xterm session, I get a nice flashing blue cursor. Let's say I wanted that cursor to be red or blue. I would change that either by creating or modifying my .Xresources file.
Before we get into the nitty-gritty of the file structure, you should know that you already have a global file that handles all of this for you. Actually, you have several. Change directory to /usr/X11R6/lib/X11/app-defaults, and you will find a number of files that pre-define some of the standard X applications. In your home directory, you may also find a .Xdefaults file that does more or less the same thing. Mine has some defaults set up for several applications including Emacs, rxvt and xterm.
Back to my xterm. What changes do I need to make? Well, if I check out the man page for xterm with man xterm and look for the X resources, I find that cursorColor is the attribute that affects the color of the cursor. If I exit my .Xdefaults or .Xresources file and add those changes, I get this. Oh, and I've changed my mind. I would rather have my cursor as a hard-to-read wheat color:
Notice that I preface the resource with XTerm* to tell my X resource file what this resource belongs to (or affects). Since I want these changes to take place without logging out of my X session and logging back in, I need to have the system re-read my configuration and incorporate the changes. This is how I do it:
xrdb -merge $HOME/.Xdefaults
xrdb, by the way, is the X resource database utility. This program usually gets run somewhere along the way when you start an X session. On my system, it is called by /etc/X11/xinit/xinitrc. If I had created a .Xresources file instead, then my command would have been as follows:
xrdb -merge $HOME/.Xresources
I start a new xterm and behold, the cursor is a wheat color. Let's try a more interesting example. For instance, when I start Netscape, I get a menubar with the word "Help" over on the right. I also get the word "Location" beside my URL address bar. Let's just say, for fun, that when I need help, it's more like an S.O.S. than a simple request for help. I'd like my browser to say S.O.S. for help and URL for my location bar. This is how I tackle this one. At the end of my .Xdefaults or .Xresources file, I add the following lines.
Netscape*menuBar.helpMenu.labelString: S.O.S. Netscape*urlLocationLabel.uneditedLabelString: URL:
Before we continue, we need to re-run xrdb to merge those resources. Now, if I close my browser and restart it, I get things displayed the way I want them to be. By the way, I found the X resource or Netscape in the accompanying documentation distributed with the browser. On my machine, (and with Netscape 4.75) this documentation lives at /usr/doc/netscape-common-4.75/Netscape.ad .
Whoa! I've been going on for far too long. It's extremely easy to get caught up in all of this. The X Window System is so incredibly flexible that playing around with it can be quite addictive. Until next time, take care everyone, and remember that a little gratuitous window dressing never hurt anyone. X needs no warning labels.
- diff -u: What's New in Kernel Development
- Divx# Watch The Other Woman Full HD Online Streaming Viooz
- Numerical Python
- Great Scott! It's Version 13!
- Use Linux as a SAN Provider
- RSS Feeds
- Adminer—Better Than Awesome!
- NSA: Linux Journal is an "extremist forum" and its readers get flagged for extra surveillance
- Linux Kernel Testing and Debugging
- It Actually Is Rocket Science