Graeme's Wiki

x11 tips

Starting X from the Console by Using startx

If you have Ubuntu set to boot to runlevel 1, a text-based console login, you can start an X session from the command line. You use the startx command (which is actually a shell script) to do so. You launch the X server and an X session by using startx, like this:

$ startx

startx first looks in your home directory for a file named .xinitrc. This file can contain settings that will launch an alternative desktop and X clients for your X session. The default system .xinitrc is found in the /etc/X11/xinit directory, but a local file can be used instead to customize an X session and launch default clients. For example, you can download and install the mlvwm window manager, which is available from in the /usr/local/bin directory. You can then use the mlvwm desktop for your X session along the xterm terminal client by creating an .xinitrc file that contains the following:

xterm &
exec /usr/bin/mlvwm

Using a custom .xinitrc is not necessary if you're using Ubuntu's desktop, which runs X and either a GNOME-aware window manager or KDE as a desktop environment.

You can also use the startx command with one or more command-line options. These options are passed to the X server before it launches an X session. For example, you can use startx to specify a color depth for an X session by using the -depth option, followed by a number such as 8, 16, 24, or 32 for 256, thousands, or millions of colors (as defined in the X configuration file and if supported). Using different color depths can be useful during development for testing how X clients look on different displays, or to conserve use of video memory, such as when trying to get the highest resolution (increased color depth can sometimes affect the maximum resolution of older video cards).

For example, to start a session with thousands of colors, you use the startx command like this:

$ startx -- -depth 16

Another option that can be passed is a specific dots-per-inch (dpi) resolution that is to be used for the X session. For example, to use 100 dpi, you use the -dpi option followed by 100, like this:

$ startx -- -dpi 100

You can also use startx to launch multiple X sessions. This feature is due to Linux support for virtual consoles, or multiple text-based displays. To start the first X session, you use the startx command followed by a display number, or an X server instance (the first is 0, using screen 0) and a number that represents a virtual console. The default console used for X is number 7, so you can start the session like this:

$ startx -- :0 vt7

After X starts and the window manager appears, you press Ctrl+Alt+F2 and then log in again at the prompt. Next, you start another X session like this, specifying a different display number and virtual console:

$ startx -- :1 vt8

Another X session starts. To jump to the first X session, press Ctrl+Alt+F7. You use Ctrl+Alt+F8 to return to the second session. If you exit the current session and go to another text-based login or shell, you use Alt+F7 or Alt+F8 to jump to the desired session.

Using startx is a flexible way to launch X sessions, but multiple sessions can be confusing, especially to new users, and are a horrific resource drain on a system that does not have enough CPU horsepower and memory. A better approach is to use multiple workspaces, also known as virtual desktops, as discussed in the following section.

Changing the X11 keyboard layout for all desktop environments

For some reason if I install Slackware 13.1 and during the installation I configure my keyboard layout to Dvorak, it only applies to the console. As soon as I start up X11, it defaults back to US Qwerty!! :-(

I do not want to configure each DE with keyboard settings, I want to apply it to X11, which must then filter to all DE I might use.

For some reason the following change also did not do the trick.
Section "InputDevice"
  Option "XkbLayout" "us"
  Option "XkbVariant" "dvorak"

Strange, because this used to be all that was required. Clearly somewhere the new Xorg has lost the plot! After lots of searching I found the solution. Apply the above changes, and then to forcefully activate them it X11, you have to add the following configuration section in the xorg.conf file too.

Section "ServerFlags"
  Option "AutoAddDevices" "False"
  Option "AllowEmptyInput" "False"

Now all desktop environments seem to default to Dvorak! Finally!!