Web lists-archives.com

Re: What controls the default ordering of which application handles an opened file?




On Thu, Nov 16, 2017 at 4:24 AM, Nate Graham <pointedstick@xxxxxxxx> wrote:
> Howdy all,
> I'm working on adding Krita file support to Gwenview
> (https://phabricator.kde.org/D8751) and my patch works, but has the side
> effect of causing Krita files to prefer being opened in Gwenview rather than
> Krita itself. Krita should take preference when it's installed, but how is
> the default application ordering determined? Where should this change be
> made?

I'm CCing David as I think he isn't on the list but knows better than
anyone how this works...

It's complicated. For educational purposes I'll go into greater detail
than we need to solve the problem at hand. But long-story short: there
is no such thing as a (non-global) default under the current
specifications.

Basically, between two desktop files supporting the same mime type it
is undefined behavior which gets picked as first choice [1] (as far as
the desktop files are concerned anyway). Preference is meant to be
regulated by mimeapps.list (respectively kde-mimeapps.list) files [2].
AFAIK we do not actually use them as a means to supply defaults,
distributions however might and we fully support that. The problem
with this file is that it assumes centralism where there is none.
Namely since there is one central mimeapps.list we'd have to curate a
file which then would conflict with other desktop's curated version OR
distros would have to programmatically inject entries at runtime so as
to avoid this file conflict, which they don't do because then they may
as well curate their own version altogether. It's a fairly
disappointing situation really.

You, as application developer, have no say in the default choice or
that you must always be the first choice for your own mime type. It's
kind of solvable when utilizing an installer of some kind as the
installer can simply mangle the global mimeapps.list accordingly. Or
the application can do it on first (manual) start.

The KService frameworks supports a special desktop entry key [3]
`X-KDE-InitialPreference` meaning to solve this. It assigns a custom
preference score (higher=more preferred) to all mime types associated
with the desktop file.
To solve the problem with krita there probably needs to be a separate
krita desktop file which is `NoDisplay=true` and only associates with
the krita mimetype `MimeType=application/x-krita;` and sets
`X-KDE-InitialPreference=10` to gain preference over gwenview. This
will only impact kde-frameworks based software though, other xdg spec
compliant mimetype handlers do not necessarily respect our
InitialPreference score!

In the end I don't think there is a proper cross-desktop way of doing
this by default. Usually people simple set X-KDE-InitialPreference and
move on.

[1] https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#mime-types
[2] https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html#associations
[3] https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#kde-items

HS