47

I run gnome shell 3.6 and Eclipse 4.2. I installed Eclipse manually, in my /opt directory, because the Ubuntu package for Eclipse is very outdated.

I've created a .desktop file for it, and placed in in ~/.local/share/applications. It looks like this:

[Desktop Entry]
Type=Application
Name=Eclipse
Comment=Eclipse Integrated Development Environment
Icon=/opt/eclipse-4.2.1/icon.xpm
Exec=/opt/eclipse-4.2.1/eclipse
Terminal=false
Categories=Development;IDE;Java;

I can run Eclipse from the Activities menu; if I hit the super menu and type in "Eclipse" and run it, it starts just fine, and shows up in my launcher/sidebar/dock/whatever it's called.

But if I right-click on its icon, there is no "Add to favorites" option.

(I notice this is also the case if I run some very old programs, like xeyes and xcalc. it's amazing these are still distributed!)

So what is it about a program that determines whether or not the "Add to favorites" option is available? if I knew and understood that, maybe it'd set me on the right path to fixing this Eclipse problem.

0

10 Answers 10

31

Found the answer elsewhere. The .desktop file needs to be named EXACTLY the same as the binary that's launching.

Mine was something like eclipse_ide.desktop and the binary that runs is just "eclipse". Gnome shell does not seem to like that.

5
  • 9
    For future reference, this answer did not solve it for me. The only way I could do it was right-clicking the application from the actual "Applications" menu and adding it as a favorite. I could not do it while the program was running on the dock.
    – J.W.F.
    Commented Jan 8, 2015 at 13:06
  • 3
    I think Gnome isn't looking for the binary file, but for the WM_CLASS, as mentioned in the other answer here. Once I found that (by using xprop) it started working. Commented May 22, 2018 at 13:13
  • Upvoted! This also fixed status bar icon issue for me. Now it is nice and flat. Earlier it was vertically elongated weird looking icon (a different icon).
    – retromuz
    Commented Apr 11, 2020 at 2:54
  • Been struggling for a year, but found solution now. Can't believe it was this simple Commented Nov 9, 2020 at 14:56
  • Solved! Thanks a lot :)
    – neun24
    Commented Oct 16, 2021 at 17:33
20
  1. Install alacarte program.
  2. Run this program (its name is Main Menu).
  3. In the appropriate Menu category from right side panel add your eclipse menu item (by introducing icon, name and command)
  4. Now gnome shell show your manual installed eclipse in its search and you can search it or add it to favorite easily.

It works for all manual installed program in gnome shell.

2
  • By far the best way to do this!
    – mal
    Commented Mar 1, 2016 at 16:44
  • 3
    ... except that in gnome 3.14 you cannot right click anymore on a menu item to add it to the favorites
    – Francois
    Commented Nov 23, 2016 at 18:56
13

In Gnome 3.16 I managed to add an application to favorites by naming the .desktop file exactly as the window WM_CLASS.

To know the window WM_CLASS:

  1. open a terminal window
  2. execute the xprop command: the cursor turns in a cross
  3. click on the relevant window
  4. read the command output in the terminal, looking for the WM_CLASS property (it is a comma separated list of values, just pick the first one)

In case you are using multiple versions of Eclipse at once and you get conflicting WM_CLASS values (typically "Eclipse" for any version, AFAIK), you can set your own (i.e. "Eclipse Luna") by editing the relevant plugin.xml in the Eclipse package you installed.

I.e. for Eclipse Luna JEE the file to edit is <install_dir>/plugins/org.eclipse.epp.package.jee_4.4.<some_version>/plugin.xml

2
  • This did it for me. I had a Firefox Developer Edition shortcut, where I changed the WM_CLASS by appending --class=firefoxdev to the Exec command. Changing the name to that class made me able to add it to the favorites. Commented May 22, 2018 at 13:08
  • That also allows you to combine the running app icon with the anchored/favorite icon of that app, so that you only see one icon. That desktop file also needs to be in /usr/share/applications.
    – WesternGun
    Commented Nov 2, 2022 at 9:09
7

I found that if I right-click the app when it appears in the search "Add To Favorites" is available: Create its *.desktop file to make it available in the "Activites" overview -> Press "Activities"/super key -> Type app name -> Right Click it as it appears in the search -> "Add To Favorites" should now be available.

In my case I had this problem with Android Studio (android-studio/bin/studio.sh) running gnome-shell 3.16.2-2.

6

I had to add StartupWMClass= to the *.desktop file. To get the window WM_CLASS, you can click on the window, using the xprop command in a terminal.

2
  • Added another full answer below. Idea is the same, but a bit more details and no terminal :) Commented May 2, 2018 at 19:32
  • 1
    I tried your trick for DbVisualizer, but no luck. WM_CLASS(STRING) = "sun-awt-X11-XFramePeer", "DbVisualizer" I tried all combinations. Nothing allows me to add to favorites. Commented Feb 15, 2021 at 14:53
5

Create a .desktop file

The solution is actually very easy: in the installation folder, create an empty file, name it Eclipse.desktop and copy paste this code:

[Desktop Entry]
Version=Neon
Name=Eclipse
Comment=Eclipse is an IDE
Exec=/home/username/path/to/eclipse
Path=/home/username/path/to/eclipse/
Icon=/home/username/path/to/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=Utility;Application;Development;

Then, change the properties of the files so it can be executed. Just double click on it, and Eclipse should start. You will be able to lock the icon to the Launcher.

eclipse-in-the-launcher

Of course, please change the path to your Eclipse installation. And if you have many installations, you can change the name field to make it more clear in the menu. You can also change the filename.

Add Eclipse to your menu

You now have a cool desktop launcher, but it is not yet available in your menu. To do that, copy the Eclipse.desktop file in:

/home/username/.local/share/applications

If you still can’t find Eclipse in the menu, just log out from your session or restart your computer. That should be good.

eclipse-in-the-launcher

Source: http://blog.ttoine.net/en/2016/06/30/how-to-add-eclipse-neon-launcher-in-gnu-linux-menus-and-launchers/

2
  • So the problem was, that the *.desktop-file wasn't executable, wasn't it? Commented Nov 25, 2017 at 11:37
  • After copying it to /usr/share/applications I am able to find it in "Show Applications" searching. After copying it to ~/.local/share/applications I am able to add it to favorites. Thanks a lot. Also, Aligning WM_CLASS value vrom xprop with desktop file name will also combine the icon of running app with the anchored/favorite app icon on the dash. For example, WM_CLASS for my Intellij IDEA window is jetbrains-idea-ce, so desktop filename is jetbrains-idea-ce.desktop, but StartupWMClass line has value idea.sh, aligned with executable name(/opt/data/idea-2021/bin/idea.sh).
    – WesternGun
    Commented Nov 2, 2022 at 9:19
0

Be sure the Icon=/opt/eclipse-4.2.1/icon.xpm line in the .desktop file points to the right file. That was the problem in my case.

0
0

I was having trouble making my custom Firefox shortcut to be added to favorites (under Fedora 30).

Right-clicking from the "Activities" screen was possible, but that was not enough for the windows manager to group several windows from that same application.

The solution was in details … I had to rename the .desktop file using the content of "StartupWMClass" attribute. Windows are now correctly grouped (in other words, identified as same application), the Add to favorites entry now appears in the context menu (when right-clicking the icon inside the dock) and I can now place that icon as I see fit by dragging it around.

dock context menu screen capture

0

The list of favourite applications can be obtained by

dconf read /org/gnome/shell/favorite-apps

It is a list of strings where each element is the name of .desktop file (from either /usr/share/applications or ~/.local/share/applications). Only entries for existing files will appear in the application menu.

To set the value either use dconf-editor GUI app or run this command:

dconf write /org/gnome/shell/favorite-apps "['firefox.desktop', 'eclipse.desktop']"

Note: you will need to provide all entries, so in the example above you will have only two items in Favourites menu.

0

I got the same problem after upgrading Ubuntu 16.04 -> 18.04 effectively switching Unity -> GNOME. A got an old .local/share/applications/eclipse-photon.desktop file was able to start Eclipse, but its icon immediately turned into an ugly one and you were not allowed to right-click it and add to favorites.

The problem appeared to be in the absence of StartupWMClass=Eclipse IDE line in the .desktop file. It somehow worked in Unity, but failed in GNOME.

Anyway, I took MenuLibre menu editor, and it allowed me to select a window to which the menuitem belongs (Advanced -> Startup WM Class; you'll need to start your eclipse first).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .