Search code examples
pythonlauncherwnck

Set WM_CLASS (with wnck, xprop, or something else)


I'm trying to group multiple Chrome standalone windows under the same launcher in Ubuntu 14.04. It doesn't seem to be possible simply to specify multiple WM_CLASS variables in the .desktop file (see comments on this answer).

The first solution I hit on is to use xprop to change the WM_CLASS of the extra windows to be the same as a chosen master window, after a short delay. This works if I don't specify which window to change at the command line, let it give me a crosshair, and click on the wayward window, with a command like this:

xprop -f WM_CLASS 8s -set WM_CLASS crx_kphgejagakmceapfinpoopapfdnkkepf

(taken without much understanding from this answer to the same question)

It gets the new WM_CLASS, and Ubuntu immediately regroups it under the chosen launcher rather than Chrome.

However, despite the window to all appearances having the very simple name Todoist (this is what appears on the title bar, and xprop | grep -i name gives

WM_NAME(UTF8_STRING) = "Todoist"
_NET_WM_NAME(UTF8_STRING) = "Todoist"
WM_LOCALE_NAME(STRING) = "en_US.UTF-8"

So, I decide xprop can't be trusted.

Instead, I found I can use the python package wnck to access this window, after a fashion:

import wnck
todoist = [w for w in wnck.screen.get_defaults().get_windows()
           if 'todoist' in w.get_name().lower()][0]

So, how can I use this object todoist to change the underlying WM_CLASS?

I realize this is totally an xy-problem question, and so am open to completely different approaches.


Solution

  • WM_CLASS is a tuple of name and class and xprop can't set properties which take multiple values (or rather, it can only set the first value). I didn't find any tool that could do it and ended up writing this small c script in the end. You could probably translate it into Python using python-xlib if you prefer that (I normally would but was deterred by the total lack of documentation).