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

时间:2016-04-15 15:12:58

标签: python launcher wnck

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.

2 个答案:

答案 0 :(得分:2)

WM_CLASSa tuple of name and classxprop无法设置带有多个值的属性(或者更确切地说,它只能设置第一个值)。我找不到任何可以做到这一点的工具,最后写了this small c script。如果您愿意,可以使用python-xlib将其翻译成Python(我通常会因为完全没有文档而被阻止)。

答案 1 :(得分:2)

Fmstrat @ github pointed outxdotoolman)可以做到:

apt install -y xdotool
xdotool search --name "Title of App" set_window --class "New WM Class"