设置 WM_CLASS(使用 wnck、xprop 或其他)

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

我正在尝试在 Ubuntu 14.04 中将多个 Chrome 独立 windows 分组到同一个启动器下。似乎不可能简单地在 .desktop 文件中指定多个 WM_CLASS 变量(参见 this answer 上的注释)。

我想到的第一个解决方案是在短暂延迟后使用 xprop 将额外 windows 的 WM_CLASS 更改为与选定的主 window 相同。如果我没有在命令行指定要更改的 window,让它给我一个十字准线,然后单击任性的 window,使用这样的命令,这将起作用:

xprop -f WM_CLASS 8s -set WM_CLASS crx_kphgejagakmceapfinpoopapfdnkkepf

(从 this 对同一问题的回答中得到的理解不多)

它获得了新的 WM_CLASS,并且 Ubuntu 立即将其重新组合在选定的启动器下,而不是 Chrome。

然而,尽管 window 的所有外观都具有非常简单的名称 Todoist(这是标题栏上显示的内容,xprop | grep -i name 给出

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

所以,我决定 xprop 不可信。

相反,我发现我可以使用 python 包 wnck 来访问这个 window,经过一段时间:

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

那么,我如何使用这个 object todoist 来改变基础 WM_CLASS

我意识到这完全是一个 xy-problem 问题,因此我对完全不同的方法持开放态度。

如果您愿意,

WM_CLASSa 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(我通常会这样做,但由于完全缺乏文档而望而却步)。

Fmstrat@github pointed out that xdotool (man) 可以做到:

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

在与 Microsoft Teams window 名称斗争时找到了答案。

我使用 window class 在我的桌面上显示 window 的列表,我使用 class 的右侧部分来获取应用程序名称,例如如:

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

将显示“Firefox”

但是团队在 class 名称中使用 space:

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

所以我的任务栏根本没有显示名字。

我用过:

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

修改class的左右两部分,xprop显示为: WM_CLASS(STRING) = "Microsoft", "Teams",and thus my taskbar now works.