loading...
Cover image for The Linux Desktop Deep Dive

The Linux Desktop Deep Dive

l04db4l4nc3r profile image Angad Sharma Updated on ・5 min read

Linux has definitely made a lot of sense even in a purely materialistic sense.

  • Linus Torvalds

In a world where existing software design practices led to monolithic mayhem, especially in the case of kernels and operating systems, the Linux community came up with software designed like a castle built out of lego.

To me, the best part of Linux is its unique form of simple complexity and complex simplicity in the form of customizability. Everything about Linux is modular and user-centric. The cogs work together like a well-oiled machine. It never ceases to amazes me.

The Linux desktop environment is one such pluggable GUI layer in a vast expanse of sedimentation. It feels like a system that truly cares about the freedom of its users. Like a hive mind with individuality. This is what has motivated me to do a series of "window manager hopping".

A typical Linux desktop is composed of the following moving parts:

A typical hierarchy looks like this:

Alt Text

Before getting into each and every component, let us look at what a linux system looks like without any graphical user interface.

When a linux machine is booted, it spawns 8 ttys by default. TTY essentially means a terminal console without any GUI. You can access these consoles by pressing <Ctrl> + <Alt> + [1-8]. For example, pressing <Ctrl> + <Alt> + 1 will show the following screen:

Alt Text

The 7th tty actually loads the GUI with the display manager which we will get to in the next section.


Display Manager

A display manager (also called login manager) is loaded after the end of the boot procedure in linux. It loads up an authentication screen, much like telnet, which prompts for the username and password. Its primary function is to handle authentication, and manage user session. It also loads the window system configured for the machine and it does so by running a .xsession script, which is used to setup initial clients (we will get to what an X Client is in the following section).

Alt Text

Some examples include lightdm, which comes out of the shelf for many linux systems and is easily one of the most versatile display managers out there. Some others include gdm, which is the display manager for gnome, and xdm for X11 (which we will get to shortly).

The best part about a display manager is that you don't have to roll with the one which is pre-installed on your system. Running a new DM is as easy as running the following commands:

sudo systemctl disable gdm
sudo apt install lightdm
sudo systemctl enable lightdm

The second best part about a DM is its customizability. Anything can be customized, from the colour to the greeter screen. For example, to customize a lightdm login manager, you need to edit /etc/lightdm/lightdm.conf.

To see your default display manager, simply run the following command:

cat /etc/X11/default-display-manager

Window System

A window system is the heart and soul of GUI in linux. It determines what needs to be drawn on the screen and how. In this particular blog, we are going to be talking about the most popular window system: X Window System, also called X or X11, which is the name I am going to use henceforth.

X11 uses a network approach to GUI in linux. It consists of the following elements:

Alt Text

  • X Server: It is a program that interacts with the hardware and controls display to draw boxes and buttons. Each X Server is made for a specific video card (it has hardware dependency). Note that X11 has a flipped view of the client-server architecture. Typically a server runs remotely in such an architecture, but in X11 the server actually runs on the host machine.

  • X Client: It is a program which uses the X Server to display itself on a specific screen, eg: xclock, xterm, xcalc. The best part about X11, which revolutionized how people think about GUI, is that the X Client and Server do not need to be on the same machine. What it essentially means is that I can send commands from my machine to display a particular program in a different machine, and vice versa. How cool is that!

  • Window Manager: We will get to WMs in the next section.

Alt Text

Both the X Client and the X Server speak a common tongue, and communicate to each other using the X protocol. The connection string looks something like this:

hostname:displaynumber:screennumber
  • Host Name: Name of the physically connected machine (display). If this part is left empty, then it defaults to the current machine. Host name can be a machine's node name, IP address, or blank.

  • Display Number: There might be a lot of displays connected to a particular device. This field specifies which display to connect to.

  • Screen Number: Every single monitor has multiple windows. This field represents which window to display to.

This connection string is stored in DISPLAY environment variable in linux, and to view which display you are outputting to, simply run the following command:

echo $DISPLAY

To start the GUI on a minimalist tty, simply run the following command in the terminal:

startx

This command is part of the xinit tool which specializes in initializing X11. If you don't already have it, you can always run the following command to install it:

sudo apt install xinit

Window Manager

A window manager is a special client application which controls the geometry, appearance, coordinates and graphical properties of X display. It is also responsible for re-shuffling and re-sizing windows in a stack. Some of the popular window managers are: dwm, i3, herbstluftwm, awesome, openbox etc.

Alt Text

A window manager also provides client side decorations, such as title-bars, buttons etc. Note that a lot of gtk applications have inbuilt client side decorations, and thus do not need window managers (eg: firefox, gedit).

The linux community has developed a lot of standalone WMs over the years. More and more are leaving full desktop environments and shifting to window managers for the following reasons:

  • Less bloated, and packed with the bare essentials
  • Faster and hence more productive
  • Highly customizable

Switching window managers is as easy as executing the following commands:

sudo apt install dwm
echo "exec dwm" > ~/.xsession

As mentioned earlier, the display manager runs the .xsession script. Adding exec dwm command in the aforementioned script indicated the DM to run the dwm window manager immediately after login.


Desktop Environment

A desktop environment can easily be called a superset of a window manager. In fact it is a bundled GUI which has a lot of features in addition to a WM, including wallpapers, toolbar, icons and desktop widgets. It is a full fledged graphic user interface. Some examples include gnome, XFCE, KDE etc.

Alt Text


Conclusion

This blog was a deep dive into how Window Systems and Managers work, and how you see the GUI that you have grown to love. In the subsequent parts of the series, I will be trying out various window managers and talking about the following:

  • WM Features
  • Installation and set up
  • Functionality in action
  • Verdict

If you want me to include some additional study metrics or want to suggest a window manager, do comment. Stay tuned for the upcoming parts ✌️.

Posted on by:

l04db4l4nc3r profile

Angad Sharma

@l04db4l4nc3r

Backend Developer and DevOps SysAdmin

Discussion

pic
Editor guide
 

That was an interesting read, thank you. I run Regolith OS, which is Ubuntu packaged with i3, and is a really nice way to get a working set-up of i3 without wading through configuration after configuration file.

 

Regolith is the most productive OS (variant) I've used in like 13+ years of using Linux on the desktop. I HIGHLY recommend it for anyone wanting to try a tiling WM.

 

That's great. I hadn't heard of it before. thanks ✌️

 

All these are pretty Ubuntu specific. For example, Fedora puts the display manager on the first terminal (instead of the 7th). Also, the TTYs are not started unless you switch to a specific terminal, so getty tty2 is only spawned when you press Alt-F2 (or Ctrl-Alt-F2 if you are currently in a graphical environment).

Also, Fedora runs GNOME on Wayland by default, and as far as i know Ubuntu is planning a slow transition, too[citation needed](en.wikipedia.org/wiki/Citation_(ho...]. Wayland is a completely different beast of which you could write a whole article. GNOME and KDE are actively developed to use Wayland, and there is also an i3 (a popular tiling window manager) replacement for Wayland called Sway.

 

Thanks for the info Gergely. I read up a bit about Wayland after your comment and it amazed me. I tried sway and was (quite amusingly) greeted by the following message:

Alt text

Ubuntu LTS more inclined towards stability. This is the reason why 18.04 did not come with Wayland by default. It does give you an option to switch though. I'll be interested to see if the next LTS comes wayland default

 

Yeah, NVIDIA is notoriously not supporting Linux for some reason. Yes, there is a Linux driver, but it’s far behind the Windows driver in terms of features, plus it doesn’t support a lot of newer interfaces related to Linux. Nuoveau is a good alternative (and is present in Ubuntu 18.04), but still with a lot of missing features.

About Wayland; i guess Ubuntu doesn’t support it by default because their mouth is still a bit sour that MIR (a very similar protocol, developed by Canonical) “lost” against Wayland. Let’s see if they can get pass that, as Wayland is a good way to proceed (although it has its own shortcomings). Also note that 18.04 is exactly two years old now. Wayland grew a lot in the past 2 years, so it may become default (or at least well supported) in the upcoming LTS.

 

The most popular DE is GNOME which by default uses Wayland, not X11. Wayland architecture is quite different so you should probably at least mention that. Perhaps add a separate section or even full post about it?

 

In fact, this article is already so old-fashioned...

 

Yeah. I wanted to get the fundamentals right before going into modern systems. I guess its how I learn :)

 

In the LTS release of ubuntu GNOME, there was an option to use both X11 as well as Wayland. But for ubuntu 18.04 at least, it was shipped with X11 by default.

 

Nice article!

I wrote not long ago an article for beginners to try i3. I try to explain everything, and I show how to build a basic configuration step by step.

Hope it can help!

thevaluable.dev/window-manager-mou...

 

Thanks Matthieu. The next article I was about to write was on i3 only :)

 

Your website looks awesome. Are you using a static site generator?

 

Thanks! I'm using Hugo, with this theme I modified: github.com/vjeantet/hugo-theme-casper

 

Excellent article! Very insightful. I knew most of this, but it confirmed and cemented a few things that were a bit shaky for me. Thanks!

Would you consider doing a full series of deep dives on Linux?

 

Thanks Jason. Right now I am doing a series on Window Manager Hopping. But I would love to do such a series!

 

For those folks who tried installing lightgdm and didn't work, you might see a message "/dev/nvme3/: clean" and you waited for a long time.

Try these commands. (Alt + F2 to login, if you are still stuck).
sudo service gdm3 status (in you case it might be gdm)

If its not already running try:
sudo service gdm3 start

 

Which display manager are you using in the screenshot that says Erik? That looks pretty cool

 

It is a lightdm configuration. I found it online. See this video for reference 😄 : youtu.be/_dYqisDIcC0

 

Awesome thank you!

 

Great post, Angad! I shared it in our Telegram newsletter/channel for devs. 👉🏼 Link

 

Thanks Utkarsh. I'm glad there is a telegram group for Dev 😄

 

It's kind of an unofficial thing, not endorsed by the DEV team. 😅 But we love to share the best dev resources, articles, videos, etc. there anyway. Hope to see you there. Cheers!

 

This post is amazingly useful and dead simple to understand.

Thank you so much!

 

I'm glad I could help :)

 

Love this technical Explanations!

 

I switched from cinnamon to i3wm and the experience is wonderful. Thanks for this article, it clarifies several things I wasn't sure how they work.

 

I'm glad this article helped :)

 

Cool post along with plenty of details (y). Any tools recommendation for record/replaying X11 events like 'cnee' but more human readable scripts?

 

Hmmmm I was hoping I could find any binding for higher level programming languages, but there are none! both PYPI and npm ran dry. This never happens often

 

Linux rules everything around me! <3

 

No wonder it runs 90% of the world :)

 

"A window manager also provides client side decorations, such as title-bars, buttons etc"
Window decoration drawn by the window manager is called server side decoration.

 

X11 has a flipped view of client and server: en.wikipedia.org/wiki/Client-side_...

 

Great Post!
When I used Linux Desktop, I didn't use any display managers. Instead I login to TTY console and run startx manually ;)

 

I've been using UNIX/X since the mid-90's, and still found your post enlightening...nice review of parts often forgotten behind the scenes. Keep 'em coming!

 

Thanks a lot Mike, appreciate it.