X Server-Client!! What the hell?
Are you a Linux fan? Do you hate to do things the easy way? Are you a pro who loves to put his computer’s life on the line to experiment and customize it to the extent of perfect satisfaction? Welcome to the club kid.
The best thing about Linux is that it not a massive black box like windows or mac, rather it is a master piece made out of Lego blocks, and we will be talking about a very import piece of this master piece — X server-client. The base of the modern GUI framework for UNIX like systems.
“Those who don’t understand Linux are doomed to reinvent it, poorly.”
Consistent and well designed software has always stood the test of time. X Server-Client architecture is no exception. It was developed in the year of 1987 by the MIT lab and since then it has been deployed on every UNIX like system known to man. Currently it is in its 11th iteration hence, it is also know as ‘X11’ or simply as ‘X’. If there is GUI, there is X server. This gives the OS an advantage; independence from GUI implementations, which means that the OS can be left very light weight and can be delivered fully functional without a GUI if the machine demands so. For example, the server blades that are installed in huge server farms will never need a GUI, so we won’t bloat them with unnecessary GUI, and hence its resources are well used.
This also gives the developers an advantage, as the X server-client architecture was designed to be cross platform, the developer can choose a framework to write the UI code on (for instance QT framework) and can rest assured that the UI will be rendered properly by X server no matter what the hardware is. In turn it gives the users a very smooth and consistent GUI experience. The GUI that each application will need to produce will be then outsourced to X, and hence the application doesn’t have to bother about the type of hardware, or the variant of Linux distro the person is using.
And to be honest, not everyone enjoys the hacker vibes that you get while using an all text TTY terminal. There are normal humans who enjoy a great looking GUI. So it is a good idea to take a look at what’s going on behind the scenes.
See, the Linux and UNIX like systems are used on powerful servers machines that have lot of processing power but may not be very portable. Also, these machines are very expensive to start with. So the smart guys came up with a solution, an architecture — X server-client. Even though SSH could be used to access a machine remotely, the output can only be displayed on a terminal and not on a window capable of displaying graphical contents (Bitmap display). Hence, X servers are closely related to displaying graphical contents. For example, you won’t be able to browse the web on your terminal as you do on Firefox.
We will talk about the client and server in detail, and at last I will tell you how does this give you the power to customize. Lets dive in….
Let us get this out of our way first. Any application that needs a GUI and is compatible to interact with the X Server is called an X Client. Mozilla firefox, Xterm etc are some of the examples. The terminal that you use in Ubuntu is also an X client!! Well, they are graphical terminals right? To be honest they are terminal emulators that are used to emulate a real TTY terminal on the graphics environment.
If you are getting confused between TTY, terminal and shell, check this link out.
PS: The terminal part might be confusing to understand, lets take a look again. Back in the good old days, a computer on every desk was not possible (too big, too expensive). So they had terminals / consoles which were machines that only took input and sent it to the main machine and rendered the output back on the console. That is why they were called the TTY ( teletype ). You have those on your Linux machine as well. Try Ctrl + Alt + F1. To come out of it press Ctrl + Alt + F7. There is too much theory in this too, but I will discuss it in detail in the second half of this article. Just remember that the terminal you use on your Desktop is an emulator, and in fact an X client too.
This is the real deal. The job of the X server is to take inputs from the keyboard, mouse or any other input device, and depending on the currently running X client, it send this data to the kernel for further processing (whatever your X client is supposed to do gets done here). Then the output is given to the X server again and now the X server renders it on your screen. pretty neat, right?
Now begins the fun…
In between this processed data and the final output, sit two important components. As shown in the image; one is the Window Manager and the other is the Display Manager/Graphical Interface. This very thing gives you the possibility to customize and choose whatever you think suits you best…
If you had opened an application with the window manager not running in the background, then you would not be able to re-position or even resize your windows. You won’t even have the close, maximize/restore and minimize buttons as you won’t be provided with the title bar. These things are part of the window manager. It also decides how your windows shall be put together (stack,tile etc). Now there are tons of window manager available out there — Compiz, I3, Awesome, Openbox etc. They are of different types as well — tiling, stacking etc. So it totally depends on you which one you wish to use. The default one for Ubuntu is Compiz.
PS: Now a days many X clients come with client decoration which includes the title bar with the client itself which means they will work without the window manager but that will not be the case for all clients. In fact the Ubuntu terminal does not come with client decoration.
Take a look at the diagram again.
Display manager is basically a Desktop Environment. It is a stage on which all the application windows are placed. Window Managers, File explorers, Dock etc, work hand in hand with the desktop environment to give you a uniform user experience. There are many different environments to choose from — KDE, Unity, GNOME etc. You can always have more than one of these installed on your machine and switch between them whenever you feel like.
Take a look at the diagram again.
The main idea here is that the whole OS stays as it is (The Kernel, the disto, the file system; everything), but your GUI components can be swapped in and out like Lego blocks. Ain’t that awesome?
The true power
Whatever I have told you so far might be good for cosmetics of your machine, but lets see what kind of power this lets us wield.
Remember that the stack shown in the diagram exists in every machine. Which means that even though you are using just one computer but the whole client server architecture exists which might be a bit confusing due to the use of ‘Client-Server’, but the thing is the server’s main task is to give you a consistent user interface no matter what application you are using. In fact, in the X server-client architecture, the Client Server relationship is inverted as the user interacts with the server directly but the client can be local as well as remote as explained in the paragraph below.
This architecture really shines when we use it in a network of computers. Now consider this; you don’t have a web browser(Firefox) on your machine but your friend has one. Well, you could ssh but the problem is Firefox needs GUI, and like I said before, GUI cannot be rendered on a terminal. So what you gotta do is use the X forwarding feature. What this basically does is lets you send your input over the network to your friend’s X client, and get the output(the commands on how to render the GUI) to your X server, hence forwarding. Thus the GUI that your friend’s machine generates gets rendered on your display. GUI over the network. Ain’t that cool?
PS: Notice that if you have Firefox on your machine with themes and all, and your friend’s Firefox is all raw, then X forwarding from his machine shall render a raw version of Firefox on your machine, indicating that the commands to render Firefox is indeed coming from your friend’s machine.
An interesting fact
If you watched the video by Jeo Collins I told you about, then you must have noticed how he deploys a window manager from his TTY terminal. The very instance your system boots, it opens 8 non graphical TTY terminals, which you can access using Ctrl+Alt+(F1 — F8). Your GUI is deployed on the 7th terminal, that’s the reason why you come back to your GUI when you hit Ctrl+Alt+F7. This means that you can log in from these other 7 terminals as different users and deploy a desktop environment there as well. The number of terminals is 8 by default which you can chance if you want to.
Few words before I leave…
Being a Linux user is a responsibility; a responsibility to learn, improve and preach. Never be afraid to experiment and never suppress the urge to change. Taking things for granted is a crime, always look under the hood…
“Learning is a journey, let’s learn together” — Mindorks