Fixing a good old notes app on Linux with devilspie2

Daniel Haek
3 min readFeb 11, 2021

--

It’s not really easy giving up your favorite app just because a bug will never get fixed or the project is simply abandoned. If you do have the time, knowledge and desire you could simply go on, fork the project or open a PR on the project’s repository and fix it. If you lack any of these, you can search for alternatives. On Linux, there’s a great little tool called devilspie2, that can help doing all kind of tweaks to your application. What’s really great is that it works with both KDE and Gnome.

A little history

devilspie2 is a rewrite of a program written by Ross Burton called … you guessed it, devilspie.

As the documentation explains it:

Devilspie2 is a window matching utility, allowing the user to perform scripted actions on windows as they are created.

The difference between the 2 of them is that:

The difference is that Devilspie2 has replaced the symbolic expressions of the original with a LUA interpreter, making it much easier to maintain and extend.

How I can use it to fix my windows

It should be noted that this may fail with Wayland / XWayland. There’s a feature request to make it work on Wayland too, but looks like it’s a won’t fix for the time being. You can check your current display server with echo $XDG_SESSION_TYPE . This works with x11

On my particular context, I needed a fix for the xpad sticky notes utility which looks like it’s not really maintained anymore. You can get it on most linux flavors using the builtin package manager:

apt install xpad # Ubuntu basedzypper install xpad # suse/opensuse

There are probably better alternatives already, but I guess I’m just used with it. One of the annoyances of xpad is the fact that it looses it’s “stickyness” when Show desktop is called, meaning that it will simply get minimized when that happens. Let’s fix it with devilspie2.

You should get without hassle devilspie2 using your OS’s package manager:

apt install devilspie2 # ubuntu basedzypper install devilspie2 # suse / opensuse# sorry windows / mac folks ... nothing here that I know of

We will start by having a look at the devilspie2 documentation and also some lua docs.

After a short read, you will get something similar to:

if string.match(get_class_instance_name(), "xpad") then   set_window_type("WINDOW_TYPE_DESKTOP");end

If you wish to find out the value to get_class_instance_name compared against you can use

xprop | grep -i wm_class

We need this saved in the default devilspie2 folder, so mkdir -p ~/.config/devilspie. Now we will have to create a file there with whatever name you wish … we will go with xpad.luafor the sake of this example. You can do that with code ~/.config/devilspie2/xpad.lua if you use VScode, paste the above contents and save it. Any other editor should be just fine.

Now, let’s test it by running

xpad 
devilspie2 --debug
# you can use -f <other_location> if you used a different path

The xpad windows will now remain sticky on the desktop and be immune to any Show desktop actions

One last tip

Ok, now this is amazing, but how can I make it work between restarts. Let’s fiddle a bit with systemd’s service files then. Let’s create a user directory to hold systemd’s user service files if it’s not there already:

mkdir -p ~/.config/systemd/user/

After that, lets create a service file in order to be able to run devilspie2 automatically at startup:

echo "[Unit]
Description=Devilspie2

[Service]
ExecStart=/usr/bin/devilspie2
[Install]
WantedBy=default.target" > ~/.config/systemd/user/devilspie2.service

Now let’s enable the newly created service and also start it:

systemctl --user enable devilspie2 # enable for automatic startup
systemctl --user start devilspie2 # start it now

Final credits

Photo by Yoksel 🌿 Zok on Unsplash

--

--