x11: ensure WM class is not null even if display is initialized early
authorVincent Bernat <vincent@bernat.ch>
Sat, 31 Jul 2021 10:29:47 +0000 (12:29 +0200)
committerVincent Bernat <vincent@bernat.ch>
Tue, 10 Aug 2021 07:14:36 +0000 (09:14 +0200)
commit2ebde276d1ce27876a788e28d7445417681e22fe
tree74599c2e71b965d25f4610fefaebb46b3ec8c4ca
parentae5e7dc65decb0ef726d75ad8d6238f05b60e621
x11: ensure WM class is not null even if display is initialized early

With gtkmm, when using `Application()`, the display is initialized
before we know the application name and therefore, the program class
associated to the display is NULL.

Instead of providing a default value, we set it equal to program name
when NULL. Moreover, we give up on capitalizing the class name to keep
the code super simple. Also, not using a capitalized name is
consistent with `gdk_x11_display_open()`. If someone has a good reason
to use a capitalized name, here is how to do it.

```c
  class_hint = XAllocClassHint ();
  class_hint->res_name = (char *) g_get_prgname ();
  if (display_x11->program_class)
    {
      class_hint->res_class = (char *) g_strdup (display_x11->program_class);
    }
  else if (class_hint->res_name && class_hint->res_name[0])
    {
      class_hint->res_class = (char *) g_strdup (class_hint->res_name);
      class_hint->res_class[0] = g_ascii_toupper (class_hint->res_class[0]);
    }
  XSetClassHint (xdisplay, impl->xid, class_hint);
  g_free (class_hint->res_class);
  XFree (class_hint);
```

Fix eff53c023a26 ("x11: set a default value for program_class")
gdk/x11/gdkdisplay-x11.c
gdk/x11/gdksurface-x11.c