I have two screens attached to my desktop and sometimes I like to pop open XBMC on the second one to watch something. However, I have some issues with overscan on that screen and trying to fullscreen XBMC on it does not have the intended effects. So I end up having to manually resize XBMC to nicely fit without me having to endure seeing edges or not seeing parts of what I watch.

Doing this manually every time is a drag. Luckily I am nerdy enough to look into automating it. I use Xfce these days on my desktop and from what I could tell xfwm, its window manager, does not have a built in way of resizing and positioning new windows as they are made. I first had a look into doing what I wanted with a wmctrl script, but eventually switched out that idea in favour of using a nifty little program called Devil’s Pie (devilspie).

Devil’s Pie is exactly what I needed. It has simple Lisp-based scripts and all the features that I wanted. To start using it, simply create a .devilspie directory in your $HOME folder and add .ds scripts to it as you need them. For my XBMC needs, I added the following script as xbmc.ds.

(if
  (or
    (is (application_name) "xbmc.bin")
    (is (application_name) "XBMC Media Center")
  )
  (begin
    (unmaximize)
    (pin)
    (undecorate)
    (geometry "1830x1030+1722+24")
  )
)

If you know Lisp or one of its derivatives, you are probably hurrahing at the simplicity by now (and possibly booing at how much newlines I have thrown in) and can skip to the next paragraph. If not, never fear! (well, if you do not know anything whatsoever about programming: fear slightly) We will quickly step through things. A quick thing to note is that you always want your parentheses matched up and that the first thing after an opening ( is a command or function name, the rest being parameters. The first line starts an if clause. This expects a condition and two branches: one if the condition is true, another if the condition is false. The second branch can be omitted (as is the case here). Our condition is split up in two by means of the or. In other words (or ...) is the condition. If either part of the (or ...) is true, the entire condition is met. The (begin ...) group is our branch if the condition is true. The begin groups all the following commands, running them in order. With that basic knowledge, continue.

Devil’s Pie runs the script against every window, (application_name) depends on the window currently comparing to and returns, you guessed it, the application name. Note that I compare to both xbmc.bin as XBMC Media Center as it often happens that the XBMC window does not have its proper name yet when Devil’s Pie kicks into action. To see this “improper” name for a window you are trying to match, simply look at what Devil’s Pie outputs right after you open the window.

Next, I simply use Devil’s Pie’s provided commands to change the XBMC window to my liking. I unmaximize it, I pin it to every workspace, I remove the window decoration and finally adjust the size and position using geometry (WIDTHxHEIGHT+X_OFFSET+Y_OFFSET). There are many more of these kinds of commands available, simply check man devilspie.

To actually have Devil’s Pie react to windows opening, it has obviously got to be running. The simplest and cleanest way it probably to just have it running at the start. Check your DE or distribution for your way of adding devilspie to the start up items. If it was not running and you had already opened some windows with special rules, you can always run it as devilspie -a to also apply things to all windows that are already open.