How to fix Waybar WeChat icon error

Waybar is the status bar component of Sway or Wayland compositors. The status bar is called status bar in English. It is like the drinks on the bar. Is it easy to access? For software, it is convenient to display core system information and quickly interact with different software.

waybar

There is a very important module in waybar called taskbar, which is the taskbar. Windows users should all know it. Mac users can understand it as Dock, as shown in the middle of the figure below (wabar can be configured as left/center/right display).

waybar taskbar

The function is to click the software icon to switch different software to the foreground.

In my labwc environment, all Linux software icons are displayed correctly, but the WeChat icon of Wine is displayed incorrectly. Waybar and wine system tray cannot coexist harmoniously. When starting WeChat, a separate window will be displayed (there is no problem in the Gnome environment).

wine system tray wechat

It's obviously gone astray. Fortunately, you can close the window and it's not a big problem.

Back to the topic, in the taskbar of waybar, the WeChat icon is displayed incorrectly, and it is very wrong. The synaptic icon will be loaded. The old version of waybar loads another icon, which is wrong anyway.

After several days of troubleshooting (not continuous, I only thought of dealing with it when I had time), I finally found a fix. The following is a record of the solution process.

1. First confirm what error icon is loaded

When encountering program problems, if circumstances permit, it is generally a good habit to turn on debug mode, and waybar is no exception.

1waybar -l trace

Run the above command directly on the terminal. In the standard output, view line by line, you can see that the wrong synaptic icon is loaded.

1[2024-01-06 13:53:30.900] [debug] Task (12) overwriting app_id 'unknown' with 'wechat.exe'
2[2024-01-06 13:53:30.905] [debug] Task (12) WeChat [wechat.exe] <Amif> Loaded icon 'synaptic'
3[2024-01-06 13:53:30.905] [debug] Task (12) WeChat [wechat.exe] <Amif> changed
4[2024-01-06 13:53:30.905] [debug] Task (10) tmux ~ [Alacritty] <aMif> chang

The correct loading after repair is E282_WeChat.0

1[2024-01-06 16:37:20.663] [debug] Task (7) [unknown] <amif> Loaded icon from resource
2[2024-01-06 16:37:20.663] [debug] Task (0) overwriting app_id 'unknown' with 'wechat.exe'
3[2024-01-06 16:37:20.665] [debug] Task (0) WeChat [wechat.exe] <amif> Loaded icon 'E282_WeChat.0'
4[2024-01-06 16:37:20.665] [debug] Task (0) WeChat [wechat.exe] <amif> entered output 0x564841c811a0
5[2024-01-06 16:37:20.666] [debug] Task (0) WeChat [wechat.exe] <amif> now visible on eDP-1
6[2024-01-06 16:37:20.666] [debug] Task (0) WeChat [wechat.exe] <amif> changed

2. How to fix

In wine WeChat, under waybar, the app_id is recognized as wechat.exe. To find out how it came about, you need to look at the C++ source code of waybar. It is said that young people do not work hard and old people are sad. I did not learn C++ well when I was in school. I took a look at it. Hours, dizziness. Diving into the source code may cure the root cause, but there are easier ways to think about it afterwards.

I followed the source code logic that I understood and placed the icons in various locations in the system, but it didn't work (it must be that the code was misunderstood, and there was no way to go back and recreate it 😅). Trial and error, it seemed like we had reached a dead end.

Later, I remembered that the icons in the wofi launcher were displayed normally, and I got some inspiration.

wofi wechat

Since there is no problem with wofi recognition, there should be no problem with the link from the .desktop file to the icon.

Waybar itself is more suspicious, but we can't tell what the cause is from the debug log, and the source code can't be seen.

lsof checks the system icon cache and it loads normally.

1➜ ~ lsof -p 183863 | grep -i icon
2waybar 183863 mephisto mem REG 0,27 44472 904982 /usr/share/icons/hicolor/icon-theme.cache
3waybar 183863 mephisto mem REG 0,27 327184 160612 /usr/share/icons/Humanity/icon-theme.cache
4waybar 183863 mephisto mem REG 0,27 186604 503138 /usr/share/icons/Yaru/icon-theme.cache
5waybar 183863 mephisto mem REG 0,27 117372 852152 /usr/share/icons/Adwaita/icon-theme.cache
6waybar 183863 mephisto mem REG 0,27 6900 503298 /usr/share/icons/Yaru-purple/icon-theme.cache

Finally, I thought of strace to check what files were loaded in what order during startup.

1  strace waybar -l trace

The above will output tons of log files. Fortunately, I stopped quickly. For more scientific usage, please refer to this article

strace wechat

Fortunately, I searched for the keyword wechat and found that waybar has been looking for the wechat.exe.desktop file, and the wine WeChat startup file is called WeChat.desktop. The guidance file cannot be found, and it is not surprising that a strange icon is loaded.

The final solution is to rename the file according to waybar's logic 😅

 1➜ applications pwd
 2/home/mephisto/.local/share/applications
 3➜ applications mv WeChat.desktop wechat.exe.desktop
 4➜ applications cat wechat.exe.desktop
 5[Desktop Entry]
 6Name=WeChat
 7Exec=env WINEPREFIX="/home/mephisto/.wine" wine C:\\\\ProgramData\\\\Microsoft\\\\Windows\\\\Start\\ Menu\\\\Programs\\\\WeChat \\\\WeChat.lnk
 8Type=Application
 9StartupNotify=true
10Path=/home/mephisto/.wine/dosdevices/c:/Program Files/Tencent/WeChat
11Icon=E282_WeChat.0
12StartupWMClass=wechat.exe

As for why app_id is recognized as wechat.exe, after testing, it has nothing to do with StartupWMClass=wechat.exe. Generally speaking, app_id is passed to waybar from wayland compositors. How to operate waybar later depends on its source code. If you cannot change app_id, you can only change the desktop file name.

waybar searches for the desktop file based on app_id wechat.exe. The Icon in the desktop file determines the icon to be loaded, and then loads the correct icon from various icons paths in the system.

wofi is a desktop file that is read directly. When starting the file, search for the Name in desktop and start the corresponding program. There is no problem of not being able to find the desktop file. When the launcher is designed, it is naturally looking for the desktop file.

The logical link of waybar is: app_id > desktop file > icon. Combined with the [Quick Hide and Call Out Terminal] (https://mephisto.cc/tech/quake-like-terminal/) written before, it can be seen that app_id is the various identifiers under wayland. Application is very important. Taskbar naturally controls various behaviors of the software through app_id.

In conclusion, C and C++ are very important in the Linux ecosystem. If you don’t learn it well, you will have to take a lot of detours when you encounter problems. If you can understand the source code, you will be able to solve problems much more quickly and accurately. This is the real skill. Of course, only Some people do Linux-related development; in addition, the strace command is very useful when searching for files loaded by software, and there are often surprises. When there is a lot of output, it is best to find a way to filter it first, rather than searching in the massive output information.

Problems are encountered every day. I work hard at ordinary times and share them. It is not a profound content, but it does fill a small gap in the Chinese world and is beneficial to future generations.

Lastmod: Tuesday, January 9, 2024

See Also:

Translations: