Thursday, November 2, 2017

16.04 - Why does my custom launcher file create two icons on the launcher bar?



I made a .desktop file to be able to launch my python script from the launcher bar.



I set the python script as an executable and it runs fine if I double click and run it from the file manager. It also runs fine from terminal.



The desktop file is located in /.local/share/applications/ and looks like:



[Desktop Entry]

Version=1.0
Name=Simple Timer
Comment=Timer
Exec=python3 /home/user/app/timer.py
Icon=/home/user/app/icon/timer.png
Path=/home/user/app/timer/
Terminal=false
Type=Application
Categories=Utility;Application;



If I search "Timer" in Dash, it shows up. I can run it from there. Running it would create two duplicate icons on the launcher bar as pictured.



enter image description here




  • First icon will pulsate for about 10 seconds and then disappear. This icon is lockable to the launcher. If this icon is locked to the launcher bar, it will also pulsate for a few seconds after the application window closes, during which, it will be unclickable.

  • Second icon is not lockable to the launcher and will only disappear if the application window is closed.




If I run the script from file manager. It creates 1 launcher icon that behaves normally.



I have verified that there are no duplicate .desktop files in /usr/share/applications/. My created .desktop file only exists in /.local/share/applications/ and if removed, I will no longer be able to search for my timer on Dash or lock it to launcher bar.



How can I fix both the pulsating/unclickable issue and the double icon issue here?



Launcher does not recognize the window as "his"



Specifically Tkinter windows do not recognize their "own" window (class). This makes the icon blink in vain, waiting for its window. Once the window appears, the launcher doesn't recognize its own window and pops out of the launcher when timeout has passed.
Since a "normal" window is always represented by an icon in the launcher, you are left with a generic icon (usually, if there is no duplicate launcher) or a different one (see further below).




You can simply fix that by adding:



StartupWMClass=Tk


to your launcher (since it is a Tkinter window)



Look at the difference (I gave the launcher the firefox icon for testing):





  1. without the line, when opening multiple windows. Watch the three generic icons + a blinking firefox icon, disappearing after 10 seconds or so.



    enter image description here


  2. Now I add the line StartupWMClass=Tk, all windows are grouped in the same icon:



    enter image description here




Why no generic icon in your case?




Adding the WM_CLASS to your .desktop file will fix your issue. I am pretty sure however, you accidentally created an extra launcher (or have Unity created one automatically). Look in /.local/share/applications/ and make your launchers executable. The icon will show. Most likely, your dupe will have "unity" in its name.



In general, how to find the WM_CLASS of a window?




  • Open a terminal, type



     xprop WM_CLASS


  • Subsequently click on the window. two strings appear, separated by a comma. The one in Title case is the one yoiu need to add.




Notes



Not your issue, but:



You don't need to set the lines below:





  • Version=1.0 (no harm, but not needed)

  • Since your script is executable, you don't need python3 (you can have the script call the interpreter directly)

  • Path=/home/user/app/timer/ (unnecessary)

  • Terminal=false (this is the default)


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...