community
community copied to clipboard
Kivy does not set X11 WM_CLASS property, resulting in the kivy app not to display correctly in the gnome-shell dash.
Software Versions
- Python: 3.9.1
- OS: Fedora 33 with gnome-shell 3.38.2
- Kivy: 2.0.0
- Kivy installation method:
pip install -r requirements.txtin a virtualenv without any version specification
Describe the bug
The Kivy application doesn't show up correctly in the gnome-shell dash with the application icon and name because the X11 WM_CLASS is not set correctly.
Activities:
Dash:

If I make a .desktop file for my kivy app, the application shows up correctly in the gnome-shell activities overview, but when I launch it, the dash entry for it does not show an icon, and the tooltip is python3.
Expected behavior
The gnome-shell dash should show the actual application name in the tooltip, and the correct icon as well.

To Reproduce
Copy the desktop file below to ~/.local/share/applications/MyKivyTestApp.desktop. Make sure to adjust the path names so they point to your virtualenv and the location of the kivy test.py file. With line 56 of test.py commented (the one with self.set_wm_class()), you should see the wrong behavior, with that line present, the app behaves as expected.
The code can also be found on https://github.com/dolfandringa/kivy_playground/tree/master/kivy_app_icon
Code and Logs and screenshots Desktop file:
[Desktop Entry]
Name=MyKivyTestApp
StartupNotify=true
Exec=/home/dolfandringa/.virtualenvs/kivy_playground/bin/python test.py
Terminal=false
Path=/home/dolfandringa/kivy_playground/kivy_app_icon/
Icon=idle3
Type=Application
StartupWMClass=MyKivyTestApp
test.py:
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("MyKivyTestApp", "python3")
display.sync()
def on_start(self):
if platform == 'linux':
# pass
self.set_wm_class()
MyKivyTestApp().run()
Additional context I first checked on the gnome forums about this issue: https://discourse.gnome.org/t/in-the-gnome-shell-dash-the-application-icon-is-blank-and-app-shows-up-as-python-instead-of-its-real-name/5243
They said that gnome uses the WM_CLASS property of the X11 windows to link the application window to the menu entry in order to find the icon and application name displayed in the dash. Unfortunately, kivy apps get a default WM_CLASS of python3, python3 (you can check by launching xprop and click on the kivy window).
Even though they are set correctly from self.title and self.icon, the WM_NAME and _NET_WM_ICON X11 properties aren't used by gnome to display the application in the gnome-dash.
By depending on the Xlib, I was able to change the WM_CLASS of my kivy app, to work around the issue. But this makes my app depend on python-xlib. For a cross platform framework, I think this is undesirable, and should be handled by kivy or the underlying libraries (sdl2?)?
For the time being, do you have similar workarounds for other platforms as well? Thanks
For the time being, do you have similar workarounds for other platforms as well? Thanks
No sorry, this is very specific of Gnome on linux using X11. If you are having similar issues on other platforms, I would suggest opening a new ticket.
It would be nice to hear a confirmation that this problem still applies to Kivy 2.2.1
it does, one very easy fix is just to set SDL_VIDEO_X11_WMCLASS environment variable before starting the app.
example
os.environ["SDL_VIDEO_X11_WMCLASS"] = "float-override"
SDL will automatically detect that... there were some discussion about this on discord too (although its been some time
Thanks, @p0lygun!
This sounds to me like a workaround, and that there is still a bug in Kivy, so I am leaving this open.
Let us know if I have misunderstood, and this is documented, expected behaviour.
For what it's worth, one way to fix it in kivy would probably be to set SDL_VIDEO_X11_WMCLASS (SDL2), SDL_VIDEO_WAYLAND_WMCLASS (SDL2), and SDL_APP_ID (SDL3) before SDL_Init is called. I haven't tested this yet, but I assume they should be picked up by SDL then.