It turns out however that in NixOS wmctrl didn't work well. I had 3 windows opened, and wmctrl -l only showed one. Since gnome3 is still young in nixos, the first thought was that mutter did something wrong when returning the list of clients, due to some possible packaging mistake.
However, xprop -root correctly listed 3 window ids for the _NET_CLIENT_LIST atom, so mutter did its job.
Therefore it might be a problem of wmctrl. I'm always sure in these cases Debian has a patch, however I wanted to find out by myself.
Let's prepare an environment for hacking wmctrl:
$ nix-shell ~/nixpkgs -A wmctrl
$ cd $sourceRoot
$ ./wmctrl -l
Ok it runs. Now let's dive into the code.
- Open main.c
- Search for _NET_CLIENT_LIST
- Note the for loop in list_windows function right below, it uses client_list_size / sizeof(Window) in the condition. That may be the culprit.
- We make use of the most advanced debugging technique: before the for loop add a printf("%lu\n%lu\n", client_list_size, sizeof(Window));
$ ./wmctrl -l
Bingo! client_list_size is 12 (3 windows x 4 byte) while sizeof(Window) is 8 instead of 4. Definitely a bug for 64-bit systems.
Of course Debian has the patch: http://ftp.de.debian.org/debian/pool/main/w/wmctrl/wmctrl_1.07-7.debian.tar.gz
- Exit the nix-shell and delete the wmctrl source directory.
- Copy debian/patches/01_64-bit-data.patch under ~/nixpkgs/pkgs/tools/X11/wmctrl/64-bit-data.patch.
- Edit ~/nixpkgs/pkgs/tools/X11/wmctrl/default and add patches = [ ./64-bit-data.patch ]; in the derivation.
- Finally install the patched wmctrl with nix-env ~/nixpkgs -iA wmctrl and see that wmctrl -l now works.
- Commit, push to nixpkgs master, profit.