Why do some open applications appear as "question marks" in the Unity launcher?

Solution 1:

What's happening

Problems like this relate to Unity's application matching framework. To simplify the technical details, program windows and applications are two separate things to Ubuntu. Ubuntu needs to 'guess' which application owns a particular window. And sometimes that guess fails, and a question mark appears in the launcher.

The failure may be due to:

  1. A bug in BAMF (the application matching framework mentioned above).
  2. A faulty application description (aka '.desktop' file).
  3. The lack of any application description at all. Executables that launch windows do not inherently have this metadata.

The application shown in the question (KeePass2) suffers from a type 1 problem that has been reported to the appropriate bug tracker.

Examples of problems

The below examples are technical, aimed at programmers who want their own application displaying properly in the Ubuntu launcher.

Problem 3 – No application description

In order for an application to integrate with Unity—that is to say, be searchable in the Dash and placed in the launcher—it needs to have a desktop entry. Such entries are placed in the /usr/share/applications/, /usr/local/share/applications/, and $HOME/.local/share/applications/ (the latter two being for third party software, system-wide and user-only respectively). They end with a .desktop extension and follow this basic format:

[Desktop Entry]
Type=Application
Name=My Application's Name
Icon=/file/path/of/my/icon
Exec=/file/path/of/my/executable

This entry starts a program by calling the Exec executable. Whenever that program displays a window or dialog, Unity will notice that its executable "belongs" to this application description, and use the given Name and Icon in the launcher.

This is a barebones example. The formal specification covers many advanced features.

Problem 2 – Faulty application description

Let us assume that my_app.desktop exists in a valid application directory, but:

  • /file/path/of/my/icon does not exist in the filesystem.
  • /file/path/of/my/icon is not an image.
  • the entry uses some incorrect syntax or invalid tags.

In any of the above case, Ubuntu will be unable to properly list the application window in the launcher.

Problem 1 – A bug in BAMF

As of Ubuntu 11.10, BAMF has a number of bugs that prevents correct application matching. Common (temporary) pitfalls include:

  • The Exec path being a symbolic link rather than a regular file
  • The executable being a script that launches the main executable.

In these cases, programmers have no option but to use a workaround, such as removing the symbolic link abstraction, or linking to the executable directly. Neither of these are required by the desktop entry specification itself.

Solution 2:

The window can only be matched to the application if the WM_CLASS property has been set. To do this in X11 you use:

XSetClassHint( display, window, &class_hints );

You need to pass a pointer to a XClassHint structure with field 'res_name' and 'res_class'.