In the Gnome-Shell dash, the application Icon is blank and app shows up as "python" instead of its real name

Hi all,

I am writing a python application that I am adding a .desktop file for. The application starts fine and shows up correctly in the activities (with its icon), but in the dash on the left, it has no icon, and shows up with a “python3” tooltip.

image

How does the icon and tooltip in the gnome dash get determined? Is it from the .desktop file or some other way?
This is my .desktop file

[Desktop Entry]
Name=MyTestApp
StartupNotify=true
Exec=/home/dolfandringa/.virtualenvs/kivy_playground/bin/python test.py
Terminal=false
Path=/home/dolfandringa/kivy_playground/kivymd_app_icon/
Icon=/home/dolfandringa/kivy_playground/kivymd_app_icon/logo.png
Type=Application

I am currently running Fedora 33 with Gnome 3.38.2 and both Wayaland and Xorg (tried separately).

If you want to replicate, you can try https://github.com/dolfandringa/kivy_playground
To get it running, clone it and then

mkvirtualenv -p /usr/bin/python3 kivy_playground
pip install -r requirements

Then copy kivymd_app_icon/MyTestApp.desktop to ~/.local/share/applications and adjust the path names in it and launch MyTestApp from gnome shell.

It should be some minor issue in your desktop file, though I don’t know which one, but I suggest you looking at how a system app’s desktop file looks and add essential parameters as required.
If I recall correctly, there should be a Dispaly-Name parameter :thinking:, not sure, but please check a system app’s desktop file.
Also, How to set an application's name?

From the .desktop file.

The tricky bit is matching a window 1950570720 to a .desktop file foo.desktop. There are various heuristics in place to do that (flatpak sandbox ID, GTK application bus name etc.), the most generic one is the WM_CLASS (X11) or application_id (wayland).

Look for some way to set that to MyTestApp, and the app should start behaving correctly.

It was indeed the WM_CLASS that was set to python3, python3 by default. I raised an issue with kivy: https://github.com/kivy/kivy/issues/7312

For others looking for a workaround, I manually managed to set the WM_CLASS of my kivy app with python-xlib like this:

from kivy.app import App
from kivy.metrics import dp
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.utils import platform

if platform == 'linux':
    from Xlib.display import Display
    from Xlib import X

KV = """
Screen:
    canvas:
        Color:
            rgba: 0.9764705882352941, 0.9764705882352941, 0.9764705882352941, 1
        Rectangle:
            pos: self.pos
            size: self.size
"""

class MyKivyTestApp(App):
    def build(self):
        self.title = "MyKivyTestApp"
        self.icon = '/usr/share/icons/hicolor/apps/48x48/apps/idle3.png'
        screen = Builder.load_string(KV)
        screen.add_widget(
            Button(
                text="Hello, World",
                pos_hint={"center_x": 0.5, "center_y": 0.5},
                size_hint=(None, None),
                size=(dp(110), dp(35)),
            )
        )
        return screen

    def set_wm_class(self):
        """
        Set the X11 WM_CLASS. This is used to link the window to the X11
        application (menu entry from the .desktop file). Gnome-shell won't
        display the application icon correctly in the dash with the default
        value of `python3, python3`.
        """
        display = Display()
        root = display.screen().root
        windowIDs = root.get_full_property(display.intern_atom('_NET_CLIENT_LIST'), X.AnyPropertyType).value
        for windowID in windowIDs:
            window = display.create_resource_object('window', windowID)
            title = window.get_wm_name()
            if title == self.title:
                window.set_wm_class(self.title, "python3")
                display.sync()

    def on_start(self):
        if platform == 'linux':
        #    pass
             self.set_wm_class()

MyKivyTestApp().run()

It’s not ideal, but it works.

I am wondering though, why doesn’t gnome shell just use the WM_NAME and _NET_WM_ICON X11 properties to set the tooltip and icon in the dash? They are set correctly for my app, but don’t seem to have any influence on the way the app is displayed in the dash:

image

Only if the WM_CLASS is set and matches the name in the .desktop file, does the dash display the application name and icons from the .desktop file. But still the other X11 properties are ignored.

WM_NAME is the window title, not the application name:
For instance I’m typing this in GNOME Web, but the window title is In the Gnome-Shell dash, the application Icon is blank and app shows up as “python” instead of its real name

We also don’t use it to push developers to fix their apps, because icon/name aren’t the only broken bits when failing to associate a window with its .desktop file (grouping in dash/alt-tab, adding the running app to favorites etc.).

NET_WM_ICON is supposed to be used as fallback for X11 clients (there is no corresponding property on wayland). The blank icon suggests that there’s an issue with the icon loading, as it’s not the default fallback icon that is used in the no-icon case.