Foundation Of The Linux GUI
Imagine a world of black screens with white text or dark green screens with light green text. You may or may not remember it, but that used to be the primary interface for users to access computers. Computing has moved on significantly and has adopted the graphical user interface (GUI) as standard on most desktop and workstation platforms. Not only that, but GUIs have gradually changed and evolved over time. This tutorial covers low-level information about what lies underneath the GUI, whereas Tutorial 4, “Ubuntu Desktop Options,” covers desktop software options, starting with the default, GNOME.
Foundations and the X Server
Many Linux distributions are switching to Wayland (see the nearby sidebar). For 20.04 LTS, however, Ubuntu continues to use the X Window System, the classic and stable graphical networking interface that provides the foundation for a wide range of graphical tools and window managers.More commonly known as just X, it can also be referred to as X11R7 and X11. Coming from the world-renowned Massachusetts Institute of Technology, X has gone through several versions, each of which has extended and enhanced the technology. The open source implementation is managed by the X.Org foundation, whose board includes several key figures from the open source world. On September 15, 2017, X11 turned 30 years old, which is a very long time for any software to remain usable and be in active development. Ubuntu will eventually move away from X to Wayland by default, but that is not yet the case as of the release of Ubuntu 20.04 LTS, and many third-party applications are not yet fully adapted to work as well on Wayland as they Many Linux distributions are switching to Wayland (see the nearby sidebar). For 20.04 LTS, however, Ubuntu continues to use the X Window System, the classic and stable graphical networking interface that provides the foundation for a wide range of graphical tools and window managers. More commonly known as just X, it can also be referred to as X11R7 and X11. Coming from the world-renowned Massachusetts Institute of Technology, X has gone through several versions, each of which has extended and enhanced the technology. The open source implementation is managed by the X.Org foundation, whose board includes several key figures from the open source world. On September 15, 2017, X11 turned 30 years old, which is a very long time for any software to remain usable and be in active development. Ubuntu will eventually move away from X to Wayland by default, but that is not yet the case as of the release of Ubuntu 20.04 LTS, and many third-party applications are not yet fully adapted to work as well on Wayland as they do on X. Wayland is available to users as an option on the login screen, should you prefer to give it a try.
The short answer is that Wayland is intended as a simpler window manager replacement for X.
The more complex answer is that Wayland is a compositing window manager protocol that defines how to communicate between the compositor in the Wayland window manager server and its application window clients. It also includes a C library implementation of that protocol. A compositor is an application that provides a separate region of physical memory storage for each GUI window (this memory location is called a buffer). Each frame of each running application uses a separate memory location, and the window manager then composites them together. When done well, this provides a smoother desktop experience with little or no flickering, along with the ability to perform additional processing on buffered windows, such as flashy effects. Compositing is different from how X works, as X builds bitmaps to create the graphical user interface, where each item on the screen corresponds to one or more bits of information, most often defining a display place and color for each pixel.
The best way to think about how X works is to see it as a client-server system. The X server provides services to programs that have been developed to make the most of the graphical and networking capabilities that are available under the server and in the supported libraries. X.Org provides versions for many platforms, including Linux and macOS
A desktop environment for X provides one or more window managers and a suite of clients that conform to a standard graphical interface based on a common set of software libraries. When used to develop associated clients, these libraries provide graphical consistency for the client windows, menus, buttons, and other onscreen components, along with some common keyboard controls and client dialogs
Basic X Concepts
The underlying engine of X11 is the X protocol, which provides a system of managing displays on local and remote desktops. The protocol uses a client-server model that allows an abstraction of the drawing of client windows and other decorations locally and over a network. An X server draws client windows, dialog boxes, and buttons that are specific to the local hardware and in response to client requests. The client, however, does not have to be specific to the local hardware. This means that system administrators can set up a network with a large server and clients and enable users to view and use those clients on workstations with totally different CPUs and graphics displays.
Because X offers users a form of distributed processing, Ubuntu can be used as a very cheap desktop platform for clients that connect to a powerful X server. The more powerful the X server, the larger the number of X-based clients that can be accommodated. This functionality can breathe new life into older hardware, pushing most of the graphical Because X offers users a form of distributed processing, Ubuntu can be used as a very cheap desktop platform for clients that connect to a powerful X server. The more powerful the X server, the larger the number of X-based clients that can be accommodated. This functionality can breathe new life into older hardware, pushing most of the graphical
X is hugely popular in the UNIX and Linux world for a variety of reasons. That it supports nearly every hardware graphics system is a strong point. This and strong multiplatform programming standards give it a solid foundation of developers committed to X. Another key benefit of X is its networking capability, which plays a central role in administration of many desktops and can also assist in the deployment of a thin-client computing environment. Being able to launch applications on remote desktops and being able to standardize installations are examples of the versatility of this powerful application.
More recent versions of X have also included support for shaped windows (that is, nonrectangular), graphical login managers (also known as display managers), and compressed fonts. Each release of X brings more features designed to enhance the user experience, including being able to customize how X client applications appear, right down to buttons and windows. Most office and home environments run Linux and X on their local machines. Enlightened companies and users harness the power of the networking features of X, enabling thin-client environments and allowing the use of customized desktops designed specifically for them. Having applications launch from a single location makes the lives of system administrators a lot easier because they have to work on only one machine rather than several.
X.Org (www.x.org) is the X server that is used with Ubuntu. The base distribution consists of many packages, including the server, support and development libraries, fonts, various clients, and documentation. An additional 1,000 or more X clients, fonts, and documentation are also available in the Ubuntu repositories.
The /usr directory and its subdirectories contain the majority of the Xorg software (along with a lot of other stuff; the location is not exclusive to X). Some important subdirectories are as follows:
- /usr/bin—This is the location of the X server and various X clients. (Note that not all X clients require active X sessions.)
- /usr/include—This is the path to the files necessary for developing X clients and graphics such as icons.
- /usr/lib—This directory contains software libraries required to support the X server and clients.
- /usr/lib/X11—This directory contains fonts, default client resources, system resources, documentation, and other files that are used during X sessions and for various X clients. You will also find a symbolic link to this directory, named X11, under the /usr/lib directory.
The main components required for an active local X session are installed on your system if you choose to use a graphical desktop. These components are the X server, miscellaneous fonts, a terminal client (that is, a program that provides access to a shell prompt), and a client known as a window manager. Window managers administer onscreen displays, including overlapping and tiling windows, command buttons, title bars, and other onscreen decorations and features.
Elements of the xorg.conf File
Traditionally, the most important file for Xorg has been the xorg.conf configuration file. This file used to contain configuration information that was vital for X to function correctly and was usually created during the installation of Ubuntu.
Ubuntu is designed to work no matter what might happen. So in the event of some cataclysmic event that destroys your main X system, you still have some graphical way of getting yourself back into a fully functional X-based system. An additional upside is that much of the complexity of the information in this tutorial is unnecessary for most users; in fact, the files are not even created or used by default and are used only if you create them. The downside to this is that much of the configurability of the X server is now overwritten when an upgrade happens.
Modern versions of Xorg do not create an xorg.conf file by default. Instead, various files ending in *.conf reside in the /usr/share/X11/xorg.conf.d directory and are automatically loaded by X at boot, prior to reading any xorg.conf. These files can each contain one or more sections in the same format used by xorg.conf. Users can create the file and continue making custom configurations in /etc/xorg.conf as has been traditionally done, but the file is not created by default. What is included in the previously mentioned individual files should not be changed, but you may override those settings by creating your own /etc/xorg.conf file.
We refer to using an xorg.conf file from here on, but you should keep the preceding information in mind to prevent confusion.
Let’s take a look at the potential contents of xorg.conf so that you can get an idea of what X is looking for. The components, or sections, of the xorg.conf file specify the X session or server layout, along with pathnames for files that are used by the server, any options related directly to the server, any optional support modules needed, information relating to the mouse and keyboard attached to the system, the graphics card installed, the monitor in use, and the resolution and color depth that Ubuntu uses. These are the essential components:
- ServerLayout—Defines the display, defines one or more screen layouts, and names input devices
- Files—Defines the locations of colors, fonts, or port number of the font server.
- Module—Tells the X server what graphics display support code modules to load.
- InputDevice—Defines the input devices, such as the keyboard and mouse; multiple devices can be used.
- Monitor—Defines the capabilities of any attached display; multiple monitors can be used.
- Device—Defines one or more graphics cards and specifies what optional features (if any) to enable or disable.
- Screen—Defines one or more resolutions, color depths, perhaps a default color depth, and other settings.
The following sections provide short descriptions of these elements; the xorg.conf man page contains full documentation of all the options and other keywords you can use to customize your desktop settings
The ServerLayout Section
As noted previously, the ServerLayout section of the xorg.conf file defines the display and screen layouts, and it names the input devices. A typical ServerLayout section from an automatically configured xorg.conf file might look like this:
Section "ServerLayout" Identifier "single head configuration" Screen 0 "Screen0" 0 0 InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" InputDevice "DevInputMice" "AlwaysCore" EndSection
In this example, a single display is used (the numbers designate the positions of a screen), and two default input devices, Mouse0 and Keyboard0, are used for the session.
The Files Section
The Files section of the xorg.conf file might look like this:
Section "Files" RgbPath "/usr/lib/X11/rgb" FontPath "unix/:7100" EndSection
This section lists available session colors (by name, in the text file rgb.txt) and the port number to the X font server. The font server, xfs, is started at boot and does not require an active X session. If a font server is not used, the FontPath entry could instead list each font directory under the /usr/lib/X11/fonts directory, as in this example:
FontPath "/usr/lib/X11/fonts/100dpi" FontPath "/usr/lib/X11/fonts/misc" FontPath "/usr/lib/X11/fonts/75dpi" FontPath "/usr/lib/X11/fonts/type1" FontPath "/usr/lib/X11/fonts/Speedo" ...
These directories contain the default compressed fonts that are available for use during the X session. The font server is configured by using the file named config under the /etc/X11/fs directory. This file contains a listing, or catalog, of fonts for use by the font server. By adding an alternate-server entry in this file and restarting the font server, you can specify remote font servers for use during X sessions. This can help centralize font support and reduce local storage requirements (even though only 25MB is required for the almost 5,000 fonts installed with Ubuntu and X).
The Module Section
The Module section of the xorg.conf file specifies loadable modules or drivers to load for the X session. This section might look like this:
Section "Module" Load "dbe" Load "extmod" Load "fbdevhw" Load "glx" Load "record" Load "freetype" Load "type1" Load "dri" EndSection
These modules can range from special video card support modules to font rasterizers. The modules are located in subdirectories under the /usr/lib/modules directory.
The InputDevice Section
The InputDevice section configures a specific device, such as a keyboard or mouse, as in this example:
Section "InputDevice" Identifier "Keyboard0" Driver "kbd" Option "XkbModel" "pc105" Option "XkbLayout" "us" EndSection Section "InputDevice" Identifier "Mouse0" Driver "mouse" Option "Protocol" "IMPS/2" Option "Device" "/dev/input/mice" Option "ZAxisMapping" "4 5" Option "Emulate3Buttons" "yes" EndSection
You can configure multiple devices, and multiple InputDevice sections might exist. The preceding example specifies a basic keyboard and a two-button PS/2 mouse (actually, a Dell touchpad pointer). An InputDevice section that specifies use of a USB device could be used at the same time (to enable mouse use with PS/2 and USB pointers) and might look like this:
Section "InputDevice" Identifier "Mouse0" Driver "mouse" Option "Device" "/dev/input/mice" Option "Protocol" "IMPS/2" Option "Emulate3Buttons" "off" Option "ZAxisMapping" "4 5" EndSection
The Monitor Section
The Monitor section configures the designated display device as declared in the Server-Layout section, as shown in this example:
Section "Monitor" Identifier "Monitor0" VendorName "Monitor Vendor" ModelName "Monitor Model" DisplaySize 300 220 HorizSync 31.5-48.5 VertRefresh 50-70 Option "dpms" EndSection
Note that the X server automatically determines the best video timings according to the horizontal and vertical sync and refresh values in this section. If required, old-style modeline entries (used by distributions and servers prior to XFree86 4.0) might still be used. If the monitor is automatically detected when you configure X, its definition and capabilities are inserted in your xorg.conf file from the MonitorsDB database. This database contains more than 600 monitors and is located in the /usr/share/hwdata directory.
The Device Section
The Device section provides details about the video graphics chipset used by the computer, as in this example:
Section "Device" Identifier "Intel Corporation Mobile 945GM/GMS,\943/940GML Express Integrated Graphics Controller" Driver "intel" BusID "PCI:0:2:0" EndSection
This example identifies an installed video card as using an integrated Intel 945 graphics chipset. The Driver entry tells the Xorg server to load the intel kernel module. Different chipsets have different options. For example, here’s the entry for a NeoMagic video chipset:
Section "Device" Identifier "NeoMagic (laptop/notebook)" Driver "neomagic" VendorName "NeoMagic (laptop/notebook)" BoardName "NeoMagic (laptop/notebook)" Option "externDisp" Option "internDisp" EndSection
In this example, the Device section specifies the driver for the graphics card (neomagic_drv.o) and enables two chipset options (externDisp and internDisp) to allow display on the laptop’s LCD screen and an attached monitor.
The Xorg server supports hundreds of different video chipsets. If you configure X11 but subsequently change the installed video card, you need to edit the existing Device section or generate a new xorg.conf file, using one of the X configuration tools discussed in this tutorial, to reflect the new card’s capabilities. You can find details about options for some chipsets in a companion man page. You should look at these sources for hints about optimizations and troubleshooting.
The Screen Section
The Screen section ties together the information from the previous sections (using the Screen0, Device, and Monitor Identifier entries). It can also specify one or more color depths and resolutions for the session. Here’s an example:
Section "Screen" Identifier "Screen0" Device "Videocard0" Monitor "Monitor0" DefaultDepth 24 SubSection "Display" Viewport 0 0 Depth 16 Modes "1024x768" "800x600" "640x480" EndSubSection EndSection
In this example, a color depth of thousands of colors and a resolution of 1024x768 is the default, with optional resolutions of 800×600 and 64x480. Multiple Display subsection entries with different color depths and resolutions (with settings such as Depth 24 for millions of colors) can be used if supported by the graphics card and monitor combination
You can also use a DefaultDepth entry (which is 24, or thousands of colors, in the example), along with a specific color depth to standardize display depths in installations.
You can also specify a desktop resolution larger than that supported by the hardware in your monitor or notebook display. This setting is known as a virtual resolution in the Display subsection. This allows, for example, an 800×600 display to pan (that is, slide around inside) a virtual window of 1024×768.
You can start X sessions in a variety of ways. The Ubuntu installer sets up the system to have Linux boot directly to an X session using a display manager called GDM, for GNOME Display Manager. This is an X client that provides a graphical login. After you log in, you use a local session (running on your computer) or, if the system is configured to do so, an X session running on a remote computer on the network.
If you log in via a display manager, you must enter a username and password. You can also start X sessions from the command line. The following sections describe these two methods.
If you have used the Server install, your system boots to a text login. See Tutorial 10, “Command-Line Beginner’s Class,” for more information about what to do here.
Using a Display Manager
An X display manager presents a graphical login that requires a username and password to be entered before access is granted to the X desktop. It also enables you to choose a different desktop for your X session.
Changing Window Managers
Ubuntu makes it fairly painless to switch to another window manager or desktop environment. Desktop environment refers to not only the window manager but also the suite of related applications, such as productivity or configuration tools.
You need to ensure that you have the relevant desktop environment installed on your system; the easiest way to do this is by installing the relevant *-desktop package. You can do this by installing the package kubuntu-desktop, for example (in the case of a KDE desktop); just search for “desktop” and look for Xubuntu or Kubuntu, and so on. After the download and installation is complete (you might want to grab a coffee while you wait because these packages include a ton of dependencies and take some time to download, install, and configure), you are all set to change environments.
Next, you need to log out of Ubuntu. When you return to the login page, select your name as usual and then select the session named for the desktop you want to use. Tutorial 4 provides a brief introduction to some of the most common desktop environments available, including the default, GNOME