3

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.

Community
  • 1
  • 1
tsbertalan
  • 1,453
  • 1
  • 21
  • 30

3 Answers3

4

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).

Tgr
  • 27,442
  • 12
  • 81
  • 118
  • I eventually solved a similar problem, though with Firefox, using xprop and [this method](https://superuser.com/questions/1118101/use-multiple-firefox-wm-classes-in-same-profile). Your script does seem to change the second segment if I pass the window class as something like `0x5800001`, so I'll mark it as the answer, and maybe make use of it later; thanks. – tsbertalan Sep 15 '16 at 18:20
  • Also, for posterity, I compiled it as `gcc set_wm_class.c -lX11 -o set_wm_class`. – tsbertalan Sep 15 '16 at 18:21
3

Fmstrat@github pointed out that xdotool (man) can do it:

apt install -y xdotool
xdotool search --name "Title of App" set_window --class "New WM Class"
Tgr
  • 27,442
  • 12
  • 81
  • 118
1

Found the answer while struggling with Microsoft Teams window name.

I use the window class to display a list of window on my desktop and I use the right part of the class to get the app name such as:

 0x0320002c  0 Navigator.Firefox     LSA-XPS-13-9310 Messages pour le Web - Mozilla Firefox

will display "Firefox"

However teams is using a space in the classname:

0x04800005  0 microsoft teams - preview.Microsoft Teams - Preview  LSA-XPS-13-9310 Microsoft Teams

So my taskbar didn't display the name at all.

I used:

xdotool search --name "Teams" set_window --class "Microsoft"
xdotool search --name "Teams" set_window --classname "Teams"

to modify both the right and left part of the class, which is displayed as this by xprop : WM_CLASS(STRING) = "Microsoft", "Teams", and thus my taskbar now works.

ouflak
  • 2,458
  • 10
  • 44
  • 49
myrkur
  • 25
  • 7