loading...
Cover image for Compositors in Linux

Compositors in Linux

l04db4l4nc3r profile image Angad Sharma ・5 min read

Linux Deep Dive (2 Part Series)

1) The Linux Desktop Deep Dive 2) Compositors in Linux

Compositors are a very important part of the aesthetics of any linux desktop environment. In this blog, we will be looking at the following:


What are Compositors

A compositor is a software which interacts with the window system as well as graphics in linux to produce:

  • Transparency in windows
  • Transition animations
  • Drop shadows around windows which give them a 3D effect
  • V sync: Waits for the display to update before updating the display

With compositor:

Alt Text

Without compositor:

Alt Text

As you can see, using compositors in a linux desktop environment adds flavour to the aesthetics. Now let us see how they work.


How Compositors Work

The compositer causes an entire sub-tree of a window hierarchy to be rendered to an off-screen buffer. Applications can then take the contents of that buffer and do whatever they like.

Alt Text

The off-screen buffer can be automatically merged into the parent window or merged by external programs, called compositing managers. Maintaining a buffer like this makes it easy to add additional frames during a window state change, such as fade-in and fade-out animations. Each frame of each running application goes through the compositor.

Alt Text


When to use a Compositor

A compositor should be used if there is a need of transparency, transition animations, v-sync and similar aesthetic features. Note that most desktop environments (like gnome) come with their own integrated compositors. Even some window managers like Compiz, Enlightenment, KWin, Marco, Metacity, Muffin, Mutter, Xfwm, do compositing on their own.

You would need to install a compositor separately if you are using a minimalistic desktop environment of window manager such as dwm, i3 or awesome. In such a case, since the environment is bare-bones (in the order of 1 to 5 megabytes), it is not shipped with a compositor off the shelf. In such cases, compositors like compton or picom can be used.


When NOT to use a Compositor

The mechanism behind a compositor revolves around maintaining an off-screen buffer and passing that around different windows. While this might add a lot of effects to your window manager or desktop environment, it is NOT ideal during gaming, where it causes latency.

While gaming, not using a compositor might lead to the lack of v-sync (unless you turn v-sync on in-game) and a lot of screen tearing, but it does away with latency between frames. I would recommend turning the compositor off while gaming. The drawbacks can be avoided if hardware V-sync is used, but it requires altering the X11 config for synchronization at a graphics driver level. Specifically, enabling the ForceFullCompositionPipeline option for use with nvidia graphics (and TearFree option in the case of Intel) . In such a case, the compositor would not have to be turned off while gaming since v-sync will be offloaded to the graphics driver instead of the compositor itself. This would of course require the v-sync in the compositor to be turned off.


Compton

Compton is a light weight and standalone compositor for the X Window System. It is a fork of the xcompmgr-dana compositor, which in turn is a fork of the xcompmgr compositor.

Alt Text

In addition to xcompmgr-dana, it supports the OpenGL backend, as well as colored drop-shadows. It can be easily installed for your distribution using official repos. For debain it can be installed like this:

# install comption
sudo apt install compton

# run compton in the background
compton &

Compton can be added as a startup script for the window manager of your choice.


Picom

Although compton is a pretty solid standalone compositor for X11 but sadly it is not regularly maintained anymore. Picom is an active fork of compton which aims to battle the code complexity of compton in order to draw more developers into contributing to the project.

Alt Text

For getting started with picom, I recommend building it from source. For debain based systems, the following dependancies need to be installed and subsequently, the following commands can be used to build picom:

# Debian specific command. The next few commands are for all distros
sudo apt install libxext-dev libxcb1-dev libxcb-damage0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-render-util0-dev libxcb-render0-dev libxcb-randr0-dev libxcb-composite0-dev libxcb-image0-dev libxcb-present-dev libxcb-xinerama0-dev libxcb-glx0-dev libpixman-1-dev libdbus-1-dev libconfig-dev libgl1-mesa-dev  libpcre2-dev  libevdev-dev uthash-dev libev-dev libx11-xcb-dev

# clone the project and go into it
git clone https://github.com/yshui/picom && cd picom

# Use the meson build system (written in python), to make a ninja build 
meson --buildtype=release . build

# Use the ninja build file to proceed
ninja -C build

# Copy the resultant binary into PATH
cp build/src /usr/local/bin

# Run picom in the background (this command can be added to the autostart)
picom & 

Configuring the Compositor

Compositors like compton and picom are highly configurable. From customized colored drop shadows, to the amount of transparency can be set both globally, and for certain windows in specific.

A sample config for picom can be found in /etc/xdg/picom.conf. Here is a copy of the same. To get started, simply copy the configuration to ~/.config/picom/picom.conf.

cp /etc/xdg/picom.conf ~/.config/picom/
vim ~/.config/picom/picom.conf

All of the available options are mentioned in the comments. After making a change, simply edit the configuration and save. The compositor will reload automatically.

To add a compositor to your window manager, simply put the following line in your ~/.xsession:

# Start compositor in the background
picom & # or compton & (in case you want to use compton)

# Execute window manager
exec awesome

Useful Links

GitHub logo yshui / picom

A lightweight compositor for X11 (previously a compton fork)

picom

This is a development branch, bugs to be expected

This is forked from the original Compton because it seems to have become unmaintained.

The current battle plan of this fork is to refactor it to make the code possible to maintain, so potential contributors won't be scared away when they take a look at the code.

We also try to fix bugs.

The original README can be found here

Call for testers

--experimental-backends

This flag enables the refactored/partially rewritten backends.

Currently, new backends feature better vsync with the xrender backend and improved input lag with the glx backend (for non-NVIDIA users). The performance should be on par with the old backends.

New backend features will only be implemented on the new backends from now on, and the old backends will eventually be phased out after the new backends stabilize.

To test the new backends, add the --experimental-backends flag to…

GitHub logo chjj / compton

A compositor for X11.

Compton

Join the chat at https://gitter.im/chjj/compton

Compton is a compositor for X, and a fork of xcompmgr-dana.

I was frustrated by the low amount of standalone lightweight compositors Compton was forked from Dana Jansens' fork of xcompmgr and refactored. I fixed whatever bug I found, and added features I wanted. Things seem stable, but don't quote me on it. I will most likely be actively working on this until I get the features I want. This is also a learning experience for me. That is, I'm partially doing this out of a desire to learn Xlib.

Changes from xcompmgr:

  • OpenGL backend (--backend glx), in addition to the old X Render backend.
  • Inactive window transparency (-i) / dimming (--inactive-dim).
  • Titlebar/frame transparency (-e).
  • Menu transparency (-m, thanks to Dana).
  • shadows are now enabled for argb windows, e.g. terminals with transparency
  • removed serverside shadows (and simple compositing)…

Picom Configuration

Offloading V-sync to the nvidia graphics

Linux Deep Dive (2 Part Series)

1) The Linux Desktop Deep Dive 2) Compositors in Linux

Posted on by:

l04db4l4nc3r profile

Angad Sharma

@l04db4l4nc3r

Backend Developer and DevOps SysAdmin

Discussion

markdown guide
 

I've only been using Linux on and off for couple of years, usually I'm gamer on Windows 10, but I'm compalled to learn as much I can about Linux ! I use Debian based distros,I love Compiz, however I only have got it to run on either KDE, Mate, and Unity. So my q6 I'd how can I get it to work on Gnome ? If not, is there some other similar Window-manager with eye candy around ?

 

GNOME is a desktop environment which comes with a compositor of it's own. You only need to install compositors separately for DEs or WMs that do not ship with one. When it comes to gaming, DEs that ship with compositors are generally well equipped to handle it. I hope this helps :)