CSC128, : Introduction to Linux

X-windows


Overview

X-windows (sometimes just called X) is a low-level interface to the graphics display.  Each display is run by an X Server, which is a program that sends user input to the graphical applications (called X Clients) in the form of events.  The X Clients send messages to the X Server , telling it what to draw on the display.

The X Server and the X Clients (the X application programs) don't even need to be running on the same machine.  This way, you can run graphical programs that use X on any Linux machine that you have access to, and operate it on your display.

There are X Servers for many other operating systems besides Linux, including Microsoft Windows and MacOS.  A good, free, X Server  for Microsoft Windows can be found at
http://cygwin.com/xfree/.   These X Servers allow you to run an X Client application on a remote Linux machine, and view it on your machine, no matter what operating system it runs, as long as it's running an X Server.

Each display has its own name, which is of the format:
[hostname]:[display_number].[screen_number ]
Some machines have more than one display device.  It is also possible to have more than one virtual screen per display.  Most of the time, there is only one display (0) with one screen (o).

Most often, X is used with a local display. This display is called
:0.0
The primary X display on the machine called comet would be called
comet:0.0
To see what your display is set to you need to issue the command:
echo $DISPLAY

Starting X-windows

Many Linux machines that are used for user interaction  are set up with an X-based login program.  X comes with such a program, called xdm .  Often, other programs are used instead, such as   kdm or gdm .

startx
You can also start X manually with the command startx .  See man startx for more information.

When you type startx your session is usually configured mainly through the file /etc/X11/xinit/xinitrc or if you customze it you will place a .xinitrc in your home directory.

Configuration

Many X Client applications accept X options, that allow you to change their look.  Some options are:
-fg [color]
This will set the foreground color.  (A list of colors can be found in /usr/lib/X11/rgb.txt on some systems..)

-bg [color]
This will set the background color.

-fn [font]
This will set the default font.  (Use xfontsel to find available fonts on your system.)

-geometry [geometry]

This allows you to set the default size and position of the application.   [geometry] is of the form:
[xsize]x[ysize][+/-][ xposition][+/-][yposition]

For example:

-geometry 10x20+0+0

will set the size as 10 by 20, and locate the window in the upper-left corner.

-geometry 100x50-0+0
will set the size as 100 by 50, and locate the window in the upper-right corner.


 -geometry 320x240+200+100
will set the size as 320 by 240, and locate the window 200 units away from the left side of the screen, and 100 units away from the top.

There are many configuration files that X looks for in your home directory that define some of the characteristics of X sessions and X Clients that you start.

.xinitrc
.xsession

These are scripts that are run by X when it starts.  Usually, .xinitrc is used when X is started with startx , and .xsession is started when X is started by xdm or a similar display manager.  It is common to find that one of these files is a symbolic link to the other, as it is rarely useful for them to be different.

.Xdefaults

This text file contains specific information about how an X Client application will appear by default. Many attributes that can be specified on the command line (-fg, -bg, -geometry , etc.) can be specified here.

Special keys

Ctrl-Alt-keypadplus
Ctrl-Alt-keypadminus

This will change between the defined resolutions for the current X Server .

Ctrl-Alt-backspace
This will rudely kill the current X Server.  Only use this when you can't exit nicely.


Local and Remote Displays

xhost +
xhost -
xhost +[hostname]
xhost -[hostname]

This command controls what machines are and are not allowed to run X Clients on the current X Server
 xhost + turns off hostname checking, allowing all machines to use the X Server .  xhost - (the default) turns hostname checking back on;  only machines that are in the list of acceptable hosts are allowed to use the X Server .  To add a host to the list of acceptable machines, use xhost +[ hostname] , and to remove a host from the list of acceptable machines, use xhost -[hostname] .

When the
xhost s have been set up correctly, you can run X Client applications on a remote display with the -display X option.  For example:
xclock -display comet:0.0
This will run xclock on the local machine, but will export the graphical display to the X Server on comet (display 0, screen 0), instead of the local X Server.

The default X Server is defined by the environment variable
$DISPLAY .  You can change environment variables within bash using the commmand export .  For example, to change the default display to comet:0.0 :
export DISPLAY=comet:0.0
Now, all X Client applications will by default display on the X Server on comet , even though they will still actually run on the local machine.