H. Guijt
H. Guijt

Reputation: 3375

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

enter image description here

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.

Upvotes: 2

Views: 1566

Answers (2)

mar
mar

Reputation: 232

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


Upvotes: 4

JvO
JvO

Reputation: 3106

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

Upvotes: 2

Related Questions