tags:

views:

662

answers:

4

Hi,

I recently started using Linux (where I work is a Microsoft shop, so I only code in C#, work with MS products etc).

I'm trying to understand at a high level how some basic things in Linux hang together. I've been reading www.linfo.org which is an amazing resource.

Anyway I've never quite got what X is.

From reading this article it seems to me that X is layer that sits on top of the operating system (one X server sitting on top of the OS??) and X client applications make requests to the X server. I think KDE, Xfce and Gnome are display managers, are they X server clients then?

I'm quite confused where everything sits.

Any explanation would be really appreciated!

+1  A: 

Wikipedia has some info about it.

Zitrax
+22  A: 

It's all very modular and flexible; however this leads to complexity.

The "X Server" drives the display device. It provides graphics services to clients, and those services are pretty simple - such as:

"Give me a window frame to draw in"

"Put this bitmap here"

"Draw a horizontal black line 100px wide"

"Render the text 'hello' at (100,100)"

"Tell me if any mouse clicks or key presses have been aimed at my window frame"

There is a library called Xlib, provided by X, that has a standard interface for all these simple services. Any program that wants to use the X server's display eventually uses this client library and is called an X Client. Xlib knows how to connect to an arbitrary X server - on the local machine, or via TCP/IP across the LAN, or across the world - to call these services.

The Window Manager, which is just another X client program, is in charge of the "look and feel" of the desktop - how you move and arrange windows, etc. Because the window manager draws all the window decorations, it can make the desktop look like WindowsXP, or a Mac, or NeXTSTEP.

Part of the philosophy of X was to define "mechanism and not policy" - meaning, they give you tools to do it, but don't tell you how to use those tools. One such tool is the window manager, which can be replaced at will.

Many modern X applications are written to use a desktop enviroment such as Gnome or KDE. This offers these programs a consistent set of buttons and controls to draw, and a consistent interface for some things not traditionally included in X, but often considered part of a desktop - such as how to respond to drag-and-drop or how to present a standard file chooser dialog box.

The desktop environment usually provides an object model or programmatic interface that takes care of making all the simple X client requests and lets the program handle more important things. Removing these low-level calls yields another important benefit - platform independence.

Many desktop environments include a window manager, so that the look and feel of window controls and buttons is consistent and works with the desktop metaphor provided by the environment. However, it can usually still be switched out.

The separation of the X Server (running the display) and the X Client (wanting to use the display) has a few implications:

  • The graphics system is separate from the GUI programs, and they are separated about as completely as a web browser and web server are.

  • So the GUI program might not be displaying on the local machine - just like a web browser doesn't have to point at a web server on the local machine.

  • A machine can run JUST the client, with the X server elsewhere.

  • The machine with the display doesn't have to run the client - it can run JUST the X server, and all the clients can run on a dedicated machine. This is the original thin client: big programs running on big central server - with graphical user interaction handled by dedicated hardware on the desk in front of the user.

  • You need to know what your X server's network address is so you can tell GUI programs where to display their GUI. (this is usually done by setting the DISPLAY environment variable)

  • You can display many programs, from many different machines, all on the same desktop at the same time. It is all handled seamlessly, including cut-and-paste.

Joe Koberg
GNOME and KDE are not GUI frameworks. They are Desktop Environments. GTK+ and kdelibs are the frameworks behind them. Also, note that Window Managers are X client themselves, as well as all GUI applications in the DE.
strager
The way the window managers work is pretty cool... they have a hook that gets called when a new client connects and they grab the client's window and stick it inside a child window of themselves. it's this child window that draws the border and close/maximize buttons, etc. (I think)
rmeador
I was about to write an answer, but this one is more extensive than what I've written. Just one thing: I'd add that the window manager is just another X client. And that X is usually refered to as "X", "X11" or "X Window System"). I prefer "X11" because it's short and pretty unambiguous.
Joachim Sauer
Your answer is looking much better than it initially did. However, you refer to the X server as the server as well as "the display." Keep a consistent vocabulary and say "X server." Also, "this" in "This has a few implications" is a bit ambiguous. Mention that you're talking about the X11's design.
strager
Thanks for the commentary
Joe Koberg
An excellent explanation! When I first started to use X11, it seemed like magic. Now that I know a bit more, it's still magic. ;-)
Jon Ericson
"A machine can run JUST the client, with the display elsewhere." -- I think you should use "X server" here in place of "display." Otherwise, looks pretty good. You finally get my +1. ;P
strager
+1, this is a very refined and well presented answer.
Tim Post
thanks for the explanation, very much appreciated!
bplus
+3  A: 

X11 is a network protocol, currently at release 7 (hence X11R7). It encapsulates graphics and input information, and connects an X client (application or window manager) running on a local or remote machine to the X server currently driving the local screen and input devices.

Gnome, KDE, XFCE, and LXDE are desktop environments; they contain pieces that talk to/with the X server (metacity, kwin, etc.), but also consist of specifications that applications must follow and libraries that are available in order for an application to "belong" to the DE.

Ignacio Vazquez-Abrams
Your average application also talks with the X server, though usually indirectly through a toolkit library (e.g. GTK or Qt).
strager
+1  A: 

In addition, it's worth remembering that the X server is just another program that gets run under linux. There's nothing special about it, it just happens to know how to grab onto the graphics card and take over the monitor using video drivers. You can (theoretically) run linux very happily without ever running an X server - although of course, you would be limited to the command line programs.

That's how linux organises itself - kernel at the base, then a set of programs that provide functionality to higher level programs, which themselves provide functionality to higher level programs, all building up into a complete stack of software oriented to whatever the job of the machine is (say, general desktop, software development, web server, etc).

Beyond the kernel and it's modules, nothing is 'special'.

Jim T