简体   繁体   中英

Why does my SDL Linux application have the correct icon in the app menu, but not in the taskbar?

I am trying to debug a weird icon problem for my Linux app. When I search for the app in the application menu it shows the right icon but when I run the app itself the icon is broken (it shows the default icon, which is that square gear icon).

图标在应用程序菜单中有效 任务栏中的损坏图标

Here is the app's desktop file, which is installed to /usr/local/share/applications/com.example.Xjump.desktop

[Desktop Entry]
Version=1.0
Type=Application
Name=XJump
Comment=A jumping game
Exec=xjump
Icon=com.example.Xjump
Terminal=false
Categories=Game;ArcadeGame;

The application is implemented using SDL. The PNG icons are installed to /usr/local/share in 32x32, 64x64, and 128x128 versions. (eg /usr/local/share/icons/hicolor/32x32/apps/com.example.Xjump.png ).

Another thing that I noticed is that if I change the icon name to xjump , matching the executable name, then the taskbar icon works correctly! That is, if I change the desktop file to say Icon=xjump and rename the pngs to xjump.png then the icon works correctly on both the app menu and the taskbar. However, I don't think I can do that for real, because Linux packaging guidelines prefer if the app and icon name follow that "reverse URL" convention.

Once the application is running, GNOME looks at the windows's window class to determine the right icon, because it no longer knows what desktop file was responsible for launching it. It is the responsibility of the application to correctly initialize the window class during startup.

For SDL applications, the default behavior seems to be get the window class from environment variables and, if those are unset, use the executable name as the default. This is why I could get the icon to show when I gave my icon the same name as the executable.

The fix that ended up working for me was to set the environment variables. One way to do it is to call setenv before SDL_Init .

setenv("SDL_VIDEO_WAYLAND_WMCLASS", "com.example.Xjump", 0);
setenv("SDL_VIDEO_X11_WMCLASS",     "com.example.Xjump", 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM