|You are currently reading post #48. Go to the main index.|
Control panel [+/-]
"Using the new Devil’s Pie s-expression configuration"
Devil’s Pie is a nice utility which can apply various properties on the fly to your desktop windows. Until version 0.13, it used an XML config file. After, it switched to s-expressions, and seriously lacked documentation. This is an attempt to clear the mist.
Many thanks to Ross Burton, the creator, for Devil’s Pie itself, and because he was glad to help me.
I won’t insist on the old XML configuration, because that’s all gone now. 0.13 was a complete rewrite.
2. Introduction to the X desktop
For those readers who are not familiar with the quirks of the X desktop, here’s a short introduction.
2.1. The X server
The graphical desktop which people use on operating systems such as Linux or BSD is based on a master application called “X Window”, or “X server”. By itself, the application doesn’t do much: it simply makes it possible for other applications to use the graphics card in your computer.
We gotta have certain things for a desktop to be usable. At the very least we need a desktop background and windows.
2.2. Workspaces aka virtual desktops
X differs from other graphical desktops (such as Microsoft Windows) in that it natively provides one more thing: workspaces, aka “virtual desktops”. This means that instead of having one single desktop, you can have as many as you’d like. I have 5, for instance.
Each workspace has a number (1-5) and it can hold completely different applications. I can switch between them at will, and I can move windows among them. It can be quite useful once you get used to the concept: you can use one workspace for browser windows, one for terminal windows, one for the image editor and browser, one for the music player, and so on.
2.3. The window manager
The essential stuff, like the background and windows, are handled by another special application running on top of the X server, which is called a window manager.
A window manager creates, decorates and manages windows. As graphical applicatons start, they ask the manager for a window, and it provides one according to their specifications. The application runs inside the window, and the manager will take care of stuff such as moving the window, switching between windows, minimizing and maximizing, and so on. It will talk to the application inside the window at all times, so the window is in sync with the application.
Here’s a nice collection of windows managers.
2.4. Window properties
At any given moment, a window will have a lot of properties.
Some of them are obvious: position, size, title, what kind of buttons it has active.
Some of them are less obvious, but easy to understand once you think about it: maximized, minimized, focused.
Some of them are also easy to understand, but are specific to X and you may not have seen them before: shaded (the window keeps only its title bar and hides the rest), pinned aka sticky (appears on all workspaces at once), undecorated (only shows the central part of the window, and hides all the borders and bars and buttons), always on top/bottom (will stay like this in spite of which window has focus).
And then there are some of them which are never obvious, even though they are very important and often used. These are special window modes, which are used internally by the window manager. You won’t have to bother with them, since changing these states is not allowed for the user, only the application decides what they should be, internally, and the window manager obeys. If you must have an example, here it is: modal windows, such as the “open file” dialog; such a window is special in several ways — it is groupped with the “main” window of the application, but while it is open you can’t focus the main window, and closing it won’t close the application, only the file window.
3. How Devil’s Pie works
Devil’s Pie belongs to a category of applications called “window matching utilities”. Their job is to run in the background, match windows based on certain properties, and apply certain actions to them.
Naturally, you need to: start
3.1. Configuration files
It’s important to note that, since version 0.13, Devil’s Pie needs several config files. The reason is that each file can only hold one (1) window matching definition. (This is expected to change in the future.)
So the trick is to create a central directory, such as
By default, Devil’s Pie will look for
Note: This is quite different from how pre-0.13 version used to work. Before 0.13, there was only one central config file (
3.2. Starting when X starts
Most often, you can add
Or just the following, which is by default the equivalent of the above:
3.3. What it does
Devil’s Pie will load your config files and learn your preferences. Basically, you tell it what windows it should take care of, and what it should do with them.
It recognizes windows based on a limited range of characteristics. We’re talking about things such as their titles here. Sorry, it doesn’t do stuff like “take the window that is on workspace 3, near the top-left corner, and focused”. That’s too complicated. Besides, recognizing windows by name is plenty useful as it is.
Once it recognizes a window, it will do stuff to it. Here you have a lot more things to choose from. Almost all the things that can be done to a window can be applied via Devil’s Pie. It depends on you to imagine cool tricks to do.
3.4. Disabling a config file
You can either edit the file and add a semicolon (
4.1. Introduction to s-expressions
Devil’s Pie now uses its config files to load s-expressions. Emacs users probably know what that is, but the rest of the world doesn’t. An s-expression is an expression written with a lot of round brackets, which makes a condition and decides what to do if it is met.
4.2. Basic s-expression example
Here’s an example:
Such an expression is evaluated from the inside-most and left-most set of brackets, to the right and outside. They usually are formed like this:
Here’s the above example, explained:
4.3. Logical operations
The logical operations are the methods which you use to compare window properties to your own texts. There’s three (3) of them currently:
4.4. Matchers aka matching window properties
Matchers are window properties you can use to identify windows with. There’s currently four (4) of them:
You can use any of these to match against with the logical conditions above.
The following actions were extracted from the source code, from
You can look at the window documentation for the Blackbox window manager. It’s a modern manager, so its docs cover pretty much all the above window actions. It will help you understand them better.
4.6. Regular expressions
Since the values of the window properties can vary wildly sometimes, it can be very useful to have not only simple texts to match against them, but regular expressions.
Regular expressions are a complicated thing themselves and I’m afraid I’m not going to go into that. You can read up on them on the Web.
5. Tips and tricks
5.1. How to find out window properties
One way is to run devilspie in debug mode, either with the
Another way is to run the
5.2. Syntax highlighting for the .ds files
If you use NEdit, you can syntax-highlight the
FIXME: more example wanted! Especially ones that use more actions or combine several logical operators with
7. Other tutorials
|All contents and presentation on this website are Copyright ©2001-2006 Zuavra. All rights are reserved.|