Per-application transparency

From ArchWiki
Revision as of 19:28, 23 July 2009 by BurntSushi (talk | contribs) (initial post)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This article details how to achieve transparency automatically on an application-by-application basis. (Specifically, I have only tested this with Openbox, but it should conceivably work with any window manager that complies with EWHM.)

While transparency assuredly makes your desktop look a little nicer, I maintain that it has some practical usages as well. Specifically, with terminals and text editors. It can be useful to overlay them with some transparency when copying pieces of code, or reading from a manual. However, I find it distracting for use with things like a browser or an image viewer.

Usually, the case is that you can either make all windows transparent with xcompmgr, or make some special windows transparent for applications that support it natively (i.e., urxvt). There have also been numerous tutorials on how to use transset-df to set transparency on individual windows, however, this requires that you manually set the transparency for each window that opens.

Adding devilspie to the mix however, will allow you to achieve per application transparency automatically.


Firstly, you will need to make sure that xcompmgr, transset-df, and devilspie are installed. xcompmgr and devilspie can be found in the extra repository, and transset-df in the community repository. To install:

pacman -S xcompmgr devilspie transset-df

Once installed, run xcompmgr (if you don't already have it running).

xcompmgr & 

(You do not need to pass any arguments to it, but if you would like some other effects, check out the Xcompmgr page.)


Now that what you need is installed, we need to configure devilspie. Essentially, devilspie acts as a window matching utility. It runs as a daemon, and allows you to specify rules to match certain windows, which then provides the functionality to execute some command (usually pertaining to that window), much like Openbox's rc.xml, however, Openbox alone does not give us the power that we need in this case.

First, create an opacity.ds file in ~/.devilspie (create that directory if it doesn't already exist):

mkdir -p ~/.devilspie
cd ~/.devilspie
touch opacity.ds

Now put something like the following in your opacity.ds file:

( if
( contains ( window_class ) "Gvim" )
( begin
( spawn_async (str "transset-df -i " (window_xid) " 0.85" ))

As you can see, the rule checks to see if the window_class contains the string "Gvim." If it does, it executes a command using the transset-df utility to lower the opacity to 0.85. (Any value from 0 to 1 is valid- with the former being completely transparent, and the latter being completely opaque.) The key here is the availability of the window_xid variable, and thus, the power of devilspie in this example.

Finding the Window

The other trick here is knowing how to match the desired window. Sometimes you might want to use application_name instead of matching against window_class. It all depends on how devilspie reads the window information. To see how to identify your window, run this in a terminal:

devilspie -a

And then start your desired application. The terminal should output some identification details that you can use in your opacity.ds file. Alternatively, you could use xprop.

Matching Different Applications

While I was content with simply making GVim transparent, you might want to do this with more than one application. Here's an example configuration that makes all GVim, Mirage, and Chromium windows transparent. (Adding more windows should be apparent from this example.)

( if
( or
( contains ( window_class ) "Gvim" )
( contains ( application_name ) "mirage" )
( contains ( application_name ) "chrome" )
( begin
( spawn_async (str "transset-df -i " (window_xid) " 0.85" ))

Starting With X

Simply place the following in your X startup script (i.e., ~/.xinitrc) to have per application window transparency load:

xcompmgr &
devilspie -a &

Advanced Configuration

Comprehensive documentation of the devilspie configuration file.

Alternatively, gdevilspie is a GUI configuration editor for devilspie. It can be found in the AUR.


Thanks goes to HashBox (4th post) for pointing me in the right direction.