<?xml version='1.0' encoding='UTF-8'?>

<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/xorg-config.xml,v 1.19 2006/11/28 20:01:21 nightmorph Exp $ -->

<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide link="/doc/en/xorg-config.xml">

<title>The X Server Configuration HOWTO</title>

<author title="Author">
  <mail link="sven.vermeulen@siphos.be">Sven Vermeulen</mail>
</author>

<abstract>
Xorg is the X Window server which allows users to have a graphical
environment at their fingertips. This HOWTO explains what Xorg is, how to 
install it and what the various configuration options are.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
<license/>

<version>1.15</version>
<date>2006-11-28</date>

<chapter>
<title>What is the X Window Server?</title>
<section>
<title>Graphical vs Command-Line</title>
<body>

<p>
The average user may be frightened at the thought of having to type in commands.
Why wouldn't he be able to point and click his way through the freedom provided
by Gentoo (and Linux in general)? Well, *big smile*, of course you are able to
do this :-) Linux offers a wide variety of flashy user interfaces and 
environments which you can install on top of your existing installation.
</p>

<p>
This is one of the biggest surprises new users come across: a graphical user
interface is nothing more than an application which runs on your system. It is
<e>not</e> part of the Linux kernel or any other internals of the system. It is
a powerful tool that fully enables the graphical abilities of your workstation.
</p>

<p>
As standards are important, a standard for drawing and moving windows on a
screen, interacting with the user through mouse, keyboard and other basic, yet
important aspects has been created and named the <e>X Window System</e>,
commonly abbreviated as <e>X11</e> or just <e>X</e>. It is used on Unix, Linux
and Unix-like operating systems throughout the world.
</p>

<p>
The application that provides Linux users with the ability to run graphical 
user interfaces and that uses the X11 standard is Xorg-X11, a fork of
the XFree86 project. XFree86 has decided to use a license that might not be
compatible with the GPL license; the use of Xorg is therefore recommended. 
The official Portage tree does not provide an XFree86 package anymore.
</p>

</body>
</section>
<section>
<title>The X.org Project</title>
<body>

<p>
The <uri link="http://www.x.org">X.org</uri> project created and
maintains a freely redistributable, open-source implementation of the X11
system. It is an open source X11-based desktop infrastructure. 
</p>

<p>
Xorg provides an interface between your hardware and the graphical software
you want to run. Besides that, Xorg is also fully network-aware, meaning you
are able to run an application on one system while viewing it on a different
one. 
</p>

</body>
</section>
</chapter>

<chapter>
<title>Installing Xorg</title>
<section>
<title>Using emerge</title>
<body>

<p>
Enough chitchat, let's get to business shall we? To install Xorg, you just 
need to run <c>emerge xorg-x11</c>. Installing Xorg does take a while 
though, so you might want to grab a snack while you are waiting.
</p>

<p>
Before installing Xorg you have to configure two important variables in the
<path>/etc/make.conf</path> file.
</p>

<p>
The first one is <c>VIDEO_CARDS</c>. This is used to set the video drivers that
you intend to use and is usually based on the kind and brand of card you have.
The most common settings are <c>nvidia</c> for Nvidia cards or <c>fglrx</c> for
ATI Radeon cards. Those are the proprietary drivers from Nvidia and ATI
respectively. If you would like to use the open source versions, use <c>nv</c>
rather than <c>nvidia</c> in the variable, but bear in mind that using this
driver means no 3d acceleration at all. Use <c>radeon</c> in case you have an
ATI card for the same. <c>VIDEO_CARDS</c> may contain more than one driver, in
this case list of them should be separated with spaces.
</p>

<p>
The second variable is <c>INPUT_DEVICES</c> and is used to determine which
drivers are to be built for input devices. In most cases setting it to
<c>keyboard mouse</c> should work just fine.
</p>

<p>
Now you should decide which drivers you will use and add necessary settings to
the <path>/etc/make.conf</path> file:
</p>

<pre caption="Sample make.conf entries">
<comment>(For mouse and keyboard support)</comment>
INPUT_DEVICES="keyboard mouse"
<comment>(For Nvidia cards)</comment>
VIDEO_CARDS="nvidia"
<comment>(OR, for ATI Radeon cards)</comment>
VIDEO_CARDS="fglrx"
</pre>

<p>
More instructions on how to configure Nvidia and ATI cards can be found in
<uri link="/doc/en/nvidia-guide.xml">Gentoo Linux nVidia Guide</uri> and in
<uri link="/doc/en/ati-faq.xml">Gentoo Linux ATI FAQ</uri>. If you don't know
which drivers you should choose, refer to these guides for more information.
</p>

<note>
If the suggested settings don't work for you, you should run <c>emerge -pv
xorg-x11</c>, check all the options available and choose those which
apply to your system. In different versions of Xorg and on different
architectures displaying these variables can be done with <c>emerge -pv
xorg-server</c> command rather than the one above. The example is for x86
architecture and xorg-x11-7.0.
</note>

<pre caption="Displaying all the driver options available">
# <i>emerge -pv xorg-x11</i>

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] x11-base/xorg-x11-7.0-r1  USE="-3dfx" INPUT_DEVICES="keyboard
mouse -acecad -aiptek -calcomp -citron -digitaledge -dmc -dynapro -elo2300
-elographics -evdev -fpit -hyperpen -jamstudio -joystick -magellan -magictouch
-microtouch -mutouch -palmax -penmount -spaceorb -summa -synaptics -tek4957
-ur98 -vmmouse -void -wacom" VIDEO_CARDS="nvidia -apm -ark -chips -cirrus
-cyrix -dummy -fbdev -fglrx -glint -i128 -i740 -i810 -imstt -mach64 -mga
-neomagic -nsc -nv -r128 -radeon -rendition -s3 -s3virge -savage -siliconmotion
-sis -sisusb -tdfx -tga -trident -tseng -v4l -vesa -vga -via -vmware -voodoo" 0
kB
</pre>

<p>
After setting all the necessary variables you can install the Xorg package.
</p>

<pre caption="Installing Xorg">
# <i>emerge xorg-x11</i>
</pre>

<p>
When the installation is finished, you might need to re-initialise some
environment variables before you continue. Just run <c>env-update</c> followed
by <c>source /etc/profile</c> and you're all set.
</p>

<pre caption="Re-initialising the environment variables">
# <i>env-update</i>
# <i>source /etc/profile</i>
</pre>

</body>
</section>
</chapter>
<chapter>
<title>Configuring Xorg</title>
<section>
<title>The xorg.conf File</title>
<body>

<p>
The configuration file of Xorg is called <path>xorg.conf</path> and it
resides in <path>/etc/X11</path>. The Xorg-X11 package provides an example
configuration as <path>/etc/X11/xorg.conf.example</path> which you can use to
create your own configuration. It is heavily commented, but if you are in need
of more documentation regarding the syntax, don't hesitate to read the man page:
</p>

<pre caption="Reading the xorg.conf man page">
# <i>man 5 xorg.conf</i>
</pre>

<p>
Happy reading for those of you willing to. We surely don't so we'll continue
with checking out how we can create the file automatically.
</p>

</body>
</section>
<section>
<title>Default: Automatic Generation of xorg.conf</title>
<body>

<p>
Xorg itself is able to guess most parameters for you. In most cases, you 
will only have to change some lines to get the resolution you want up and 
running. If you are interested in more in-depth tweaking, be sure to check the 
resources at the end of this chapter. But first, let us generate a (hopefully 
working) Xorg configuration file. 
</p>

<pre caption="Generating an xorg.conf file">
# <i>Xorg -configure</i>
</pre>

<p>
Be sure to read the last lines printed on your screen when Xorg has finished
probing your hardware. If it tells you it failed at some point, you're forced to
manually write an <path>xorg.conf</path> file. Assuming that it didn't fail, it
will have told you that it has written <path>/root/xorg.conf.new</path> ready
for you to test. So let's test :)
</p>

<pre caption="Testing the xorg.conf.new file">
# <i>X -config /root/xorg.conf.new</i>
</pre>

<p>
If all goes well, you should see a simple black and white pattern.  Verify if
your mouse works correctly and if the resolution is good. You might not be able
to deduce the exact resolution, but you should be able to see if it's too low.
You can exit any time by pressing Ctrl-Alt-Backspace.
</p>

</body>
</section>
<section>
<title>Alternative: Semi-Automatic Generation of xorg.conf</title>
<body>

<p>
Xorg provides a tool called <c>xorgconfig</c> which will ask you for various
information regarding your system (graphical adapter, keyboard, ...). Based on
your input it will create a <path>xorg.conf</path> file.
</p>

<pre caption="Semi-Automatic Generation of xorg.conf">
# <i>xorgconfig</i>
</pre>

<p>
Another tool, also provided by Xorg, is <c>xorgcfg</c>, which will first
attempt to run <c>Xorg -configure</c> and then start the X server for more
final tweaking.
</p>

<pre caption="Using xorgcfg">
# <i>xorgcfg</i>
<comment>(In case X crashes or the configuration fails, try:)</comment>
# <i>xorgcfg -textmode</i>
</pre>

</body>
</section>
<section>
<title>Copying over xorg.conf</title>
<body>

<p>
Let us copy over the <path>xorg.conf.new</path> to
<path>/etc/X11/xorg.conf</path> now, so we won't have to continuously run
<c>X -config</c> -- typing just <c>X</c> or <c>startx</c> is far more easy :)
</p>

<pre caption="Copying over xorg.conf">
# <i>cp /root/xorg.conf.new /etc/X11/xorg.conf</i>
</pre>

</body>
</section>
<section id="using_startx">
<title>Using startx</title>
<body>

<p>
Now try <c>startx</c> to start up your X server.  <c>startx</c> is a script
that executes an <e>X session</e>, that is, it starts the X servers and some
graphical applications on top of it.  It decides which applications to run
using the following logic:
</p>

<ul>
  <li>
    If a file named <path>.xinitrc</path> exists in the home directory, it will
    execute the commands listed there.
  </li>
  <li>
    Otherwise, it will read the value of the XSESSION variable and will execute
    one of the sessions available in <path>/etc/X11/Sessions/</path>
    accordingly (you can set the value of XSESSION in <path>/etc/rc.conf</path>
    to make it a default for all the users on the system).
  </li>
<li>
    If all of the above fail, it will fall back to a simple window manager,
    usually <c>twm</c>.
  </li>
</ul>

<pre caption="Starting X">
# <i>startx</i>
</pre>

<p>
If you see an ugly, loathsome, repulsive, deformed window manager, that's
<c>twm</c>. To finish the twm session, type in <c>exit</c> or Ctrl-D in the
upcoming xterms. You can also kill the X session using the Ctrl-Alt-Backspace
combination. This will however make X exit disgracefully -- something that you
might not always want. It doesn't hurt though :)
</p>

</body>
</section>
</chapter>
<chapter>
<title>Tweaking xorg.conf</title>
<section>
<title>Setting your Resolution</title>
<body>

<p>
If you feel that the screen resolution is wrong, you will need to check two
sections in your configuration. First of all, you have the <e>Screen</e> section
which lists the resolutions, if any that your X server will run at. By
default, this section might not list any resolutions at all. If this is the
case, Xorg will estimate the resolutions based on the information in the
second section, <e>Monitor</e>.
</p>

<p>
What happens is that Xorg checks the settings of <c>HorizSync</c> and
<c>VertRefresh</c> in the <e>Monitor</e> section to compute valid resolutions.
For now, leave these settings as-is. Only when the changes to the <e>Screen</e>
section (which we will describe in a minute) don't work, then you will need to
look up the specs for your monitor and fill in the correct values. You can also
use a tool that searches for your monitor's specs, such as
<c>sys-apps/ddcxinfo-knoppix</c>.
</p>

<warn>
Do <b>not</b> "just" change the values of these two monitor related variables
without consulting the technical specifications of your monitor. Setting
incorrect values lead to out-of-sync errors at best and smoked up screens at
worst.
</warn>

<p>
Now let us change the resolutions. In the next example from
<path>/etc/X11/xorg.conf</path> we add the <c>Modes</c> lines and the
<c>DefaultDepth</c> so that our X server starts with 24 bits at 1024x768 by
default. Don't mind the given strings -- they are examples and will most likely
differ from the settings on your system.
</p>

<pre caption="Changing the Screen section in /etc/X11/xorg.conf">
Section "Screen"
  Identifier  "Default Screen"
  Device    "S3 Inc. ProSavage KN133 [Twister K]"
  Monitor   "Generic Monitor"
  <i>DefaultDepth  24</i>
  <comment># Skipping some text to improve readability</comment>
  SubSection "Display"
    Depth   24
    <i>Modes   "1024x768"</i>
  EndSubSection
EndSection
</pre>

<p>
Run X (<c>startx</c>) to discover it uses the resolution you want :)
</p>

</body>
</section>
<section>
<title>Configuring your Keyboard</title>
<body>

<p>
To setup X to use an international keyboard, search for the <e>InputDevice</e>
section that configures the keyboard and add the <c>XkbLayout</c> option to
point to the keyboard layout you want. As an example, we show you how to apply
for the Belgian layout. Just substitute the country-keycode with yours:
</p>

<pre caption="Changing the keyboard layout">
Section "InputDevice"
  Identifier  "Generic Keyboard"
  Driver    "keyboard"
  Option    "CoreKeyboard"
  Option    "XkbRules"  "xorg"
  Option    "XkbModel"  "pc105"
  <i>Option    "XkbLayout" "be"</i>
EndSection
</pre>

</body>
</section>
<section>
<title>Configuring your Mouse</title>
<body>

<p>
If your mouse isn't working, you will first need to find out if it is detected
by the kernel at all. Mice are (device-wise) seen as
<path>/dev/input/mouse0</path> (or <path>/dev/input/mice</path> if you want to
use several mice). In some cases <path>/dev/psaux</path> is used. In either 
case you can check if the devices do represent
your mouse by checking the output of those files when you move your mouse. You
will usually see some junk on your screen. To end the session press
<c>Ctrl-C</c>.
</p>

<pre caption="Checking the device files">
# <i>cat /dev/input/mouse0</i>
<comment>(Don't forget to press Ctrl-C to end this)</comment>
</pre>

<p>
If your mouse isn't detected, verify if all the necessary modules are loaded.
</p>

<p>
If your mouse is detected, fill in the device in the appropriate 
<e>InputDevice</e> section. In the next example you'll see we also set two other
options: <c>Protocol</c> (which lists the mouse protocol to be used -- most
users will use PS/2 or IMPS/2) and <c>ZAxisMapping</c> (which allows for the
mousewheel (if applicable) to be used).
</p>

<pre caption="Changing the mouse settings in Xorg">
Section "InputDevice"
  Identifier  "TouchPad Mouse"
  Driver    "mouse"
  Option    "CorePointer"
  <i>Option    "Device"    "/dev/input/mouse0"</i>
  <i>Option    "Protocol"    "IMPS/2"</i>
  <i>Option    "ZAxisMapping"    "4 5"</i>
EndSection
</pre>

<p>
Run <c>startx</c> and be happy about the result :) Congratulations, you now
(hopefully) have a working Xorg on your system. The next step is to remove this
ugly lightweight window manager and use a high-feature one (or even a desktop
environment) such as KDE or GNOME, but that's not part of this guide :)
</p>

</body>
</section>
</chapter>
<chapter>
<title>Resources</title>
<section>
<title>Creating and Tweaking xorg.conf</title>
<body>

<p>
First of all, <c>man 5 xorg.conf</c> provides a quick yet complete reference
about the syntaxis used by the configuration file. Be sure to have it open on a
terminal near you when you edit your configuration file!
</p>

<p>
A second point of resources on your system is the
<path>/usr/X11R6/lib/X11/doc</path> directory with various <path>README</path>'s
for individual graphical chipsets.
</p>

<p>
There are also many online resources on editing <path>xorg.conf</path>. We only
list few of them here, be sure to <uri link="http://www.google.com">Google</uri>
for more :) As <path>xorg.conf</path> and <path>XF86Config</path> (the
configuration file for the XFree86 project) use the
same syntaxis for most configuration options and more information about
<path>XF86Config</path> is available, we'll list those resources as well.
</p>

<ul>
  <li>
    <uri link="http://tldp.org/HOWTO/XFree-Local-multi-user-HOWTO/">The XFree
    Local Multi-User HOWTO</uri>
  </li>
  <li>
    <uri
    link="http://www-106.ibm.com/developerworks/edu/os-dw-linuxxwin-i.html">An
    Introduction to XFree 4.x</uri> by Chris Houser
  </li>
</ul>

</body>
</section>
<section>
<title>Other resources</title>
<body>

<p>
If you want to update your system from the old monolithic Xorg to the newer,
modular Xorg 7, you should refer to the <uri
link="/proj/en/desktop/x/x11/modular-x-howto.xml">Migrating to Modular X
HOWTO</uri>.
</p>

<p>
More information about configuring different packages to work in X environment
can be found in the <uri link="/doc/en/?catid=desktop">Gentoo Desktop
Documentation Resources</uri> section of our documentation.
</p>

</body>
</section>
</chapter>
</guide>
