简体   繁体   中英

How to set icon name in X11 (Ubuntu)

I have written an application in C++, using an in-house toolkit (no Gnome or KDE). 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. 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. xprops, when used with the terminal window, doesn't reveal any properties that have value "Terminal". I've tried setting property _NET_WM_ICON_NAME (a likely choice) to a name of my choice, but it doesn't help.

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.

There is a function for that: XSetWMName. It takes an XTextProperty as argument:

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:



    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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM