Graphics On Linux

This article discusses how Linux provides a Graphical User Interface (GUI). If you’re very new to computers, you might find the whole article interesting; otherwise, you will probably want to use the Table of Contents, below, to skip to the “How Does Linux Work With Graphics?” section.

How Graphics Work

Although a proper discussion of graphics is out of scope for this article, suffice it to say that there are usually numerous software components involved, in order to make something appear on the computer's monitor. For example, suppose I'm a Windows user, using the WordPad application, and I want to open a file. I use the File->Open menu, and I see this on my screen:

file.jpg
dialogstack.jpg

What happened, to make this appear, was probably something like this:

  1. Windows provides a set of “standard dialogs,” one of which is the File dialog above. So TextPad talks to part of the Windows operating system — for lack of a better term let's call it the “Dialog Manager” — and requests a File dialog, with certain parameters. (e.g. a specific directory in which to start the search, the types of files to open, etc.)
  2. The “Dialog Manager” now knows that it has to draw a dialog on the screen, which is, really, just a type of window. So it calls another part of the Windows operating system — let's call it the “Window Manager” — and asks it to draw a window. A size will be given for the window, a title for the titlebar, it will be specified whether or now the window should have a “Close” button, etc.
    • In addition to the main window, the “Dialog Manager” will also give instructions for each of the individual pieces within the dialog; the buttons, drop-downs, etc.
  3. The “Window Manager” now knows what has to be shown on the screen. So it will talk to another part of Windows — let's call it the “Graphics Subsystem” — and ask it to draw the individual pieces. e.g. for the main dialog, the graphics subsystem will be asked to draw a blue rectangle for the titlebar, and then asked to draw some white text above that title bar, with the text “Open,” and then a blue border around the area where the dialog will be, etc.
  4. Finally, the “Graphics Subsystem” will talk to the device drivers for the computer's monitor, which will talk to the video card, which will instruct the monitor to show the appropriate pixels of the appropriate colours in the appropriate spots.

Keep in mind, however, that this is just for discussion purposes. There may be other libraries involved in drawing a File Dialog on the screen (and Microsoft probably doesn't use these names for these components).

Now let's compare how Windows works with graphics, vs. how Linux does it.

How Does Windows Handle Graphics?

As the example above demonstrated, everything involved in drawing that dialog on the screen was part of the Windows operating system. The whole sequence of events is broken down into pieces, but those pieces are all part of the much larger Windows operating system. (People use the term monolithic to describe the fact that Windows is all one big operating system, instead of numerous, interlocking systems.)

Because all of these operations are under the control of Windows, the operating system has a much better opportunity to provide a consistent look and feel to the user. Any window on the system will look basically the same, with a blue titlebar, white text in that titlebar, a blue border, etc. Almost every window will have a little red ‘`X'’ button in the top right-hand corner, that the user can use to close the window, and many windows will also have “minimize” and “maximize” buttons. Because all windows work the same, in Windows, users can quickly learn how to manage any windows which might be open on their desktop. They can also use any other computer, which might be running Windows, with no learning curve.

Of course, the user can configure Windows to use different colours and fonts, but even then, the changes will take place system wide, so all windows will use the new colours and fonts. And there is only so much configuration the user can do; for example, users can’t change the fact that the ‘`X'’ close button always shows up on the top right-hand corner of the window. So if I use someone else's computer, even if they’ve changed the colours or fonts, I can easily use the system.

Windows also has something called the Taskbar, where it shows buttons for all of the currently open windows. A Windows user knows that the Taskbar is always there, and can be used to switch to another application, by clicking its button in the Taskbar. Like the colours and fonts for windows, the user can configure the Taskbar a bit; it can be moved to the right, left, or top of the screen, instead of the bottom, and it can be set to automatically hide itself when not in use. It can even be resized, to fit more buttons in view.

And Windows also has something called the Start Menu, which can be used to launch applications. Again, there is a bit of customization the user can do to the Start Menu, but it works basically the same on all Windows systems.

How Does Linux Work With Graphics?

The part of Ubuntu which is called “Linux” is actually just the kernel; the core software at the heart of it all. But there is a lot of software which has to run on top of the kernel, to have a functioning operating system.

As opposed to Windows, however, Linux is not a monolithic operating system; it's modular. In terms of graphics, there are a number of inter-dependent systems working together:

  • The computer monitor and device drivers, just as with Windows
  • A low-level Display Protocol
  • A Window Manager
  • A Desktop Environment
  • High-level applications
linuxgraphics.jpg

In a way, this means that Linux works similar to how Windows does; if an application wanted to save a file, it could call a subroutine to open a “File” dialog, and numerous sub-systems would be used to make that happen. The difference, however, is that with Linux, you can change which software is used any particular piece. When choosing a Desktop Environment, there are different options you have, and if you don't like one option, you can install a different one. The same for the Window Manager, or Display Protocol.

For Ubuntu, the default install uses the following software:

  • Display Protocol: X Window System
  • Window Manager: Compiz
  • Desktop Environment: GNOME
ubuntugraphics.gif

The following sections will go into a bit more detail about what these components do.

Display Protocol: X Window System

The X Window System, often shortened to X — or X11, since the current version of the protocol is 11 — wasn't invented for Ubuntu; it's been around for a long time (since 1984), on other Linux distros and even on Unix. Which means that it's a very popular set of protocols. (I've seen numerous Unix computers which would initially start up in a “character-based” mode, like the Terminal we use in Linux, and the user would have to type in a command such as startx to launch the X subsystem. This is often used when an application is using an install program with a GUI; the user would startx to launch X, and then the install program would use X for its interface.)

X is actually a low-level set of protocols, for providing a GUI. It works in a client/server manner; the “client” (the application) requests services from the “server” (the X Window System). For example, if you're using the Firefox web browser to view a web site, meaning that Firefox is showing a window on the screen, Firefox is actually using X to draw the window on the screen, and X is the software which is actually doing the drawing1.

When you're logged into a local computer, the fact that X is a set of client/server protocols won’t make any difference to you. However, there is a big benefit to the client/server nature of X: It makes it very easy to remotely connect to another computer, using the same interface as if you were logged into the computer. Of course, you can also log onto a remote Windows system, using Remote Desktop. However, with X, things work a bit differently; with Remote Desktop, all of the work happens on the remote Windows computer; Remote Desktop simply shows you a picture of what the desktop looks like. With X, your remote computer is a client of X in the same way that a local user’s applications would be a client of X; everything works the same.

Although, in theory, you could install a different display protocol, there aren’t really that many competitors to X. So if you're using a graphical user interface on Unix or Unix-like systems, such as Linux, you're almost guaranteed to be using X.

Desktop Environment: GNOME

The Desktop Environment provides the components responsible for launching applications, working with files, and managing windows and tasks. GNOME provides some of the most obvious UI controls you see in Ubuntu; the bar along the top of the window, containing the clock and applications menu; the taskbar along the bottom of the window, with buttons for the currently active applications, the icons on the desktop, etc.

GNOME also provides drag 'n drop capabilities to the operating system. For example, if you drag a file from the Nautilus File Manager to Gedit for editing, GNOME is providing those drag 'n drop capabilities.

Window Manager: Compiz

The Window Manager works with X when drawing windows on the screen. It controls the appearance of windows, and also their placement on the screen.

According to the Wikipedia article:

When a window manager is running, some kinds of interaction between the X server and its clients are redirected through the window manager. In particular, whenever an attempt to show a new window is made, this request is redirected to the window manager, which decides the initial position of the window. Additionally, most modern window managers are reparenting, which usually leads to a banner being placed at the top of the window and a decorative frame being drawn around the window. These two elements are controlled by the window manager rather than the program. Therefore, when the user clicks or drags these elements, it is the window manager that takes the appropriate actions (such as moving or resizing the window).

While the main aim of a window manager is, as suggested by its name, to manage the windows, many window managers have additional features such as handling mouse clicks in the root window, presenting panes and other visual elements, handling some keystrokes (e.g., Alt-F4 may close a window), deciding which application to run at start-up, etc.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.