[英]How to set icon name in X11 (Ubuntu)
I have written an application in C++, using an in-house toolkit (no Gnome or KDE).我使用内部工具包(没有 Gnome 或 KDE)用 C++ 编写了一个应用程序。 When I run it on Ubuntu (18.04), and press alt-tab, I can see the icon I have set for the application, but there is no icon name underneath the icon.
当我在 Ubuntu (18.04) 上运行它并按 alt-tab 时,我可以看到我为应用程序设置的图标,但图标下方没有图标名称。 See attached image: the terminal has a terminal icon and the word "Terminal" underneath, but my own application only has the word "Unknown".
见附图:终端有一个终端图标和下面的“终端”字样,但我自己的应用程序只有“未知”字样。
Presumably I need to set one of the many possible X11 window properties, but I don't know which one.大概我需要设置许多可能的 X11 窗口属性之一,但我不知道是哪一个。 xprops, when used with the terminal window, doesn't reveal any properties that have value "Terminal".
xprops 与终端窗口一起使用时,不会显示任何值为“终端”的属性。 I've tried setting property _NET_WM_ICON_NAME (a likely choice) to a name of my choice, but it doesn't help.
我已经尝试将属性 _NET_WM_ICON_NAME (可能的选择)设置为我选择的名称,但它没有帮助。
How can I change the word "Unknown" to something of my choice?如何将“未知”一词更改为我选择的内容? Again - this application is using an in-house toolkit, which is neither Gnome nor KDE.
再次 - 此应用程序使用内部工具包,它既不是 Gnome 也不是 KDE。
There is a function for that: XSetWMName.有一个函数:XSetWMName。 It takes an XTextProperty as argument:
它需要一个 XTextProperty 作为参数:
void VTXWidget::setName (const std::string &name)
{
XTextProperty tp;
char *props[1];
props[0] = strdup (name.c_str ());
if (0 == props[0])
{
return;
}
if (!XStringListToTextProperty (props, 1, &tp))
{
TR_ERR ("Failed to convert text property");
}
else
{
XSetWMName (m_display, m_window, &tp);
XFree (tp.value);
}
free (props[0]);
}
I had the same problem.我有同样的问题。 Using XSetClassHint solves the problem:
使用 XSetClassHint 解决了这个问题:
XClassHint *class_hint = XAllocClassHint();
if (class_hint)
{
class_hint->res_name = class_hint->res_class = (char *)application_name
XSetClassHint(display, window, class_hint);
XFree(class_hint);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.