conda/menuinst

Linux shortcuts cannot be pinned to Dash

Closed this issue ยท 11 comments

@jaimergp,
When creating an installer for Spyder with the latest napari/label/bundle_tools_2 for Linux, the resulting shortcut cannot be pinned to the Dash. By changing the shortcut file name from spyder_spyder.desktop to spyder.desktop, the shortcut can then be pinned to the Dash. I suspect that this issue may be related to a mismatch between the shortcut name and the script name. ๐Ÿคท๐Ÿผโ€โ™‚๏ธ

The name of the shortcut file is set here:

fn = menu.name_ + shortcut['id']

Is there a reason for using self.name_ + shortcut['id'] instead of self.name?

Oops, sorry I had not seen this yet.

That line of code is from the 1.x series which is not really supported (it's only here as a historical artifact, AFAIK).

The line you are looking for is here.

Anyhow, the result is the same. Each "menu" can have more than one "menu item" (as directories with filenames, mimicking the Windows Start Menu structure). I guess that's why the filename was derived like this.

It's really strange that Dash has such a requirement ๐Ÿค” But if nothing else works... we'll have to come up with something (e.g. "only one menu item per menu on Linux").
I'll look into it, thanks for bringing it up!

Hm, maybe we need to populate the StartupWMClass field? See this AskUbuntu question.

with spyder.desktop and spyder_spyder.desktop I get

$ xprop WM_CLASS
WM_CLASS(STRING) = "Spyder", "Spyder"

Adding StartupWMClass=Spyder, Spyder to spyder_spyder.desktop does not seem to affect anything; I get the same result for xprop and still cannot be pinned to Dash. It remains that only spyder.desktop can be pinned to Dash.

I don't know that a menu hierarchy makes sense in Linux, since there is no "Menu" like there is on Windows. "menu items" just get stuffed into /home/user/.local/share/applications, so the {menu_prefix}_ seems superfluous.

My google searches returned a lot about StartupWMClass, as you found, but nothing about the .desktop name, which is the only effect I've found.

I think filename = f"{self.render_key('name', slug=True, extra={})}.desktop" is all that is necessary.

The current scheme is indeed modelled after Windows, but there are also elements in Linux that are similar. See section C in https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html.

Also, did you read this part of the spec? I think it might have to do with that (currently listed as a TODO). Does e.g. org.spyder.spyder.desktop work? Can you also try /home/user/.local/share/applications/spyder/spyder.desktop?

The current scheme is indeed modelled after Windows, but there are also elements in Linux that are similar. See section C in https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html.

Also, did you read this part of the spec? I think it might have to do with that (currently listed as a TODO). Does e.g. org.spyder.spyder.desktop work? Can you also try /home/user/.local/share/applications/spyder/spyder.desktop?

Interesting, unfortunately none of that seemed to help. There seemed to be some inconsistencies between section C and what the installer installed:

  1. _ instead of - in desktop name
  2. spyder.directory instead of spyder_spyder.directory
  3. menus/application.menu instead of menus/applications-merged/spyder_spyder.menu
  4. Contents of .menu include <Category>spyder</Category> (which doesn't exist?) instead of <Filename>spyder_spyder.desktop</Filename>

I tried bringing into compliance without any effect, including renaming org.spyder.spyder everywhere and trying spyder/spyder.desktop. Having applications/spyder.desktop remains the only way to exhibit the correct behavior ๐Ÿคท๐Ÿผโ€โ™‚๏ธ. Perhaps there is something I'm missing; do you see the same behavior for napari on Linux?

However to make one correction to the original post, I can add the application to the Dash by right-clicking the application from the Activities (Super key) screen and selecting "Add to Favorites". However this exhibits the problem of having two icons in the Dash when the application is open and the application still cannot be pinned to the Dash by right-clicking the icon in the Dash when it is open. See the screencast below.

desktop

I am able to repurpose the napari shortcut in Ubuntu 22.04 to launch Spyder. It can be pinned and everything. I just need StartupWMClass=Spyder in the .desktop file. Can you try?

image

Success! Thanks @jaimergp. Apparently I was not using the correct value for StartupWMClass

  • โŒ Spyder, Spyder
  • โŒ spyder
  • โœ… Spyder

I assume this is supposed to be the case-sensitive menu name.

I think it might come from the running process actually. For python -m turtle, the WM class was 'Tk'. I guess Qt is setting it via the Application name or something? My method was opening the app without the shortcut and seeing what name appeared in the top bar (next to Activities).

I could also reproduce your use case with a working napari installation. No changes are required in menuinst, but users should set StartupWMClass almost always. Something to add in the docs, for sure. I'll close here as solved though! Thanks for the report and, as always, the super detailed insights on the problem!

xprop returns the class name and the instance name (since each "window" can have several instances). We only want to the first item in the tuple (the class name).

In Qt, the class name seems to be set from QApplication's name and/or the basename of sys.argv[0]. Some refs for the future readers: