Unable to Get Application Icons to Display with GTK4 under Ubuntu

Viewed 138

Recent articles about GTK4 detail the changes required for displaying application icons. This article in particular is very helpful in explaining how to deploy desktop files and icons.

I am seeing an issue where the application icons display correctly with GTK3 apps, but the default widget icon displays for GTK4 apps. One thing to mention up front is that I am running Ubuntu 22.04 LTS with the latest updates inside a VirtualBox VM hosted under Windows 10.

To test this behavior, I have created a file called HelloWorld.c that contains the following code, which is derived from The GTK Project's Getting Started page and compiles successfully under both GTK3 and GTK4:

#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  gtk_window_present (GTK_WINDOW (window));
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

The file resides in a folder called "$HOME/Projects/HelloWorld3,4" and is compiled to produce executables named HelloWorld3 and HelloWorld4 as follows:

gcc `pkg-config --cflags gtk+-3.0` HelloWorld.c -o HelloWorld3 `pkg-config --libs gtk+-3.0`
gcc `pkg-config --cflags gtk4` HelloWorld.c -o HelloWorld4 `pkg-config --libs gtk4`

HelloWorld3.desktop is as follows. To simplify matters for this example, I am not installing any custom icons. There is already an icon called "preferences-color.png" under /usr/share/icons/hicolor/(icon size)/apps. Of course, "(my home folder)" is simply a placeholder for this example; the actual file on my system contains the correct full path to the executable.

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=Hello World GTK 3
Exec=/(my home folder)/Projects/HelloWorld3,4/HelloWorld3
Comment=Hello World with Application-Specific Icon
Icon=preferences-color
Terminal=false
Categories=Utility;GTK;
X-Desktop-File-Install-Version=0.26

HelloWorld4.desktop is as follows (again, "(my home folder)" is simply a placeholder for this example):

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=Hello World GTK 4
Exec=/(my home folder)/Projects/HelloWorld3,4/HelloWorld4
Comment=Hello World with Application-Specific Icon
Icon=preferences-color
Terminal=false
Categories=Utility;GTK;
X-Desktop-File-Install-Version=0.26

According to the article I referenced at the top of this post, the desktop files can either be copied to $HOME/.local/share/applications or installed under /usr/share/applications using desktop-file-install. Both methods have been attempted, with the same results. For sake of completeness, the latter method was used as follows:

sudo desktop-file-install --dir=/usr/share/applications ./HelloWorld3.desktop
sudo desktop-file-install --dir=/usr/share/applications ./HelloWorld4.desktop

After all is said and done, launching HelloWorld3 shows the preferences-color icon, but launching HelloWorld4 shows the default widget icon. Rebooting has no effect on the outcome.

Hopefully I have provided enough information, but please let me know if you have any questions. Any suggestions on where the issue may lie would be very helpful.

0 Answers
Related