Demystifying The Linux Desktop Environment

TAGS: ARCH, SYSTEMD

Recently, I wondered how a Linux desktop environment that really fit my needs would look like.

Well, okay. I was bored and could not do much else being sick, so the only thing left was idle reading and tinkering in between bouts of tiredness.

I learned a lot! And I think it could be fun to share what I have discovered while playing around.

Into The Unknown

In recent years, I was using Ubuntu for my desktop/working needs. The installation worked on my hardware, I could get to coding or whatever I was up to, the stable LTS releases lasted long enough to almost forget about them.

In the same vein, choosing a Gnome desktop environment was the natural thing for me to go with. It just worked, did not require much attention and was familiar.

Until I got a new laptop where the Ubuntu installer, for some reasons, was crashing.

So I switched to using Arch Linux.

Yes I had to mention this. It’s relevant. Oh, did I mention that I am using Arch?

To be precise, it was Manjaro - it’s a distribution based on Arch with a less steep installation learning curve. It comes with a convenient installer which, for me, worked out of the box, and a selection of ready-to-go desktop environments. My beloved i3 among them.

As a coincidence, it’s also a pretty light-weight and understandable setup. So it was the perfect environment to try out some other graphical setups!

Back To The TTY

When it comes to exploring your OS, you really don’t need a graphical desktop.

All you need is to know your login credentials (the username is something which might be forgotten if you’re never prompted for it), a bit of knowledge of terminal commands and that’s it. Well, I’ll be honest, another device with a browser and a stable internet connection is something I would not want to miss :) Gotta Google a bunch of stuff.

Note: the following commands may get you into a hard-to-escape situation. Caution is advised.

First, let’s see what your current boot target is:

sudo systemctl get-default

It probably says graphical.target let’s remember that for later.

NOTE: you can see all available targets with systemctl list-unit-files --type target. And all currently active targets with systemctl list-units --type target. If you’re curious about how they build up to each other, systemd-analyze critical-chain graphical.target shows you the order.

ANOTHER NOTE: you can read about targets with man 7 systemd.special. You can check out what the target looks like with systemctl cat graphical.target. (Spoiler: it wants the display-manager.service to be started, at least on my machine.)

The first thing I did, was switch to the stage before the graphical.target. That is the multi-user.target:

sudo systemctl set-default multi-user.target

The OS is ready to be used by multiple users, but nothing else is started. You will face a full-screen TTY, where you can log in.

After a reboot, systemd will not start your usual graphical environment, but will stop at the TTY stage.

Launching Your Own Window Manager

How is your current graphical session started? You can probably find out by looking at systemctl cat display-manager.service.

In my case, it was running /usr/bin/gdm, which is the login screen you may know from your Gnome environment. The one where you click the user and enter the password.

We don’t need to use systemd to launch a graphical session though.

You can do it from your TTY. Just log in, and run startx. That should run your currently configured graphical environment!

What if we want to change that?

startx is using the configs in your local $HOME/.xinitrc!

There’s a bunch of setup happening, but eventually the last exec line runs your graphical session. (xinit is used behind the scenes, but lets skip that for now.)

What if you want to run another environment?

You’d first need to install it, and then you can adjust your .xinitrc to start the newly installed thing.

In my case, here is what happened:

sudo pacman -S i3wm

i3 is a tiling window manager, and I find it a blast to work with, at least when you get used to the commands.

To run it with startx, I commented out the last exec line in the .xinitrc and added a new line:

exec i3

After that was done, startx was dropping me into a default i3 session.

NOTE: there is a lot to be said about that, how to configure a nice environment and all that. For now, all you need to know is that pressing WindowsKey + Shift + E gets you out of i3. Well, after you confirm by clicking a button in the upper right corner.

Detour: Configuring i3

The configs live in $HOME/.config/i3/config. You usually copy a ready-made config and adjust it as time goes on. Probably, you’ll need to choose what terminal to open.

i3 only handles key combinations and arranging windows.

It comes with some batteries included, like a default status bar, but you will need to take care of installing an app launcher, like dmenu.

You can also replace most of those configurations! I chose polybar for a bar, as it can be made to look really nice quite easily, and rofi as a less-bare-bones app launcher.

You can use feh to set a wallpaper. If you want to adjust your screen resolution, xrandr is the tool to use. You’ll have to configure the behaviour of your touchpad via xinput config files. It’s actually quite convenient once you get used to it!

You have to add a bunch of calls to your .xinitrc, and some to the i3 config file to be run by i3 on startup.

NOTE: there is a subreddit, especially for sharing screenshots and configs for custom desktop environments. You can find it here. Don’t be scared by the name! It’s SFW.

Why Startx?

There is an interesting detail hiding behind the startx command.

Beneath most conventional graphical linux environments, there is a X11 graphical server. Hard at work.

The “x” in startx and initx refer to it. It’s a fancy architecture, with the 11th version originating in the 1980s. It was designed in a different times, with requirements which were sensible back then.

Mostly, it’s a client/server architecture, which is designed to make it possible to render graphics on a remote machine, and receive them on your local graphical terminal.

NOTE: is it also a standard?

As with anything older, there is a competing thing. In this case, it’s Wayland. It is designed to be faster at drawing interfaces, and with other assumptions in mind. At the moment, there’s no standard around it, and only one implementation (I think…).

You can’t just take an application which was written to work with X11 and run it on Wayland though! It needs to know about Wayland, and be able to handle its way of doing things.

NOTE: also, it expects the things it runs to do more than X11 does. A window manager also needs to take care of managing inputs, displays and act as a composer among other things. The X11 way of doing things is arguably more modular and allows for single tools to do one thing. Only window management, or only handling key combinations for example, as is the case with bspwm (a tiling window manager) needing to have something like sxhkd to call commands upon key combinations is quite elegant! i3 does both jobs.

Anyway, the above divide leads to basically re-implementations of things built for X11, but for Wayland.

  • i3 -> sway
  • rofi -> wofi
  • polybar -> waybar
  • (and more like that)

One caveat! Sway is responsible for functionality, you would use a mix of tools for with i3. xrandr, xinput, picom (a compositor, responsible to draw windows nicer and add animations) - all of those functionalities are combined within sway (you can use shared libraries, and there are upsides for both ways for doing things).

You also don’t use the startx command to run your wayland window managers. Instead, you call the directly. Typing Hyprland or sway instead.

That Was A Lot!

Whew! Okay, so now we have taken a look around how to get out of a default graphical environment, and into the TTY.

And also, how to run whatever you want when it comes to graphics from your command line.

I hope it was an interesting experience!

What I haven’t mentioned in detail: with a custom graphical environment (or window manager, or desktop manager), you will notice how much a completely integrated setup like Gnome is taking care of!

The clipboard working between applications for example. Or unlocking your keychain, having a lockscreen, being able to right-click, taking screenshots, displaying the state of the system, being able to get to the settings… That and running into holes in your configuration make the experience more suited for a hobby, than productive work.

NOTE: alacritty is a great terminal, but lacks tabs, or a right-click menu (at least to my knowledge). But my window manager can provide tabs, so that’s alright I guess?

However! If you really take the time, and set up a system which is configured exactly the way you need it, you’ll have a very hard time to go back to an out-of-the-box default setup.

If you’re curious, take the time! Give i3, or any other window manager (TODO: link) which catches your eye (TODO: link to subreddit) a try.

If you have seen enough, make sure to re-enable your graphical target:

sudo systemctl set-default graphical.target

and reboot with sudo reboot, back to your usual setup. I hope this was a fun excursion!

NOTE: awesome-polybar is a cool github repo for inspiration

Subscribe to my newsletter!
You'll get notified via e-mail when new articles are published. I mostly write about Docker, Kubernetes, automation and building stuff on the web. Sometimes other topics sneak in as well.

Your e-mail address will be used to send out summary emails about new articles, at most weekly. You can unsubscribe from the newsletter at any time.

F├╝r den Versand unserer Newsletter nutzen wir rapidmail. Mit Ihrer Anmeldung stimmen Sie zu, dass die eingegebenen Daten an rapidmail ├╝bermittelt werden. Beachten Sie bitte auch die AGB und Datenschutzbestimmungen .

vsupalov.com

© 2024 vsupalov.com. All rights reserved.