[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Changing default XDB browser w/o GNOME etc.


Am 2015-12-13 10:19, schrieb Eduard Bloch:
Observation: various programs use the XDG mechanism (freedesktop
configuration method) to start a specific browser to visit a hyperlink.
Easy to verify with the xdg-open tool.

Note that xdg-open is just a single implementation and most GUI
toolkits provide their own implementation of the XDG specifications
that are related to this - so changing xdg-open will typically not help
you, I don't think I'm using any software that actually uses it; it's
useful for scripting though.

But how can I change this setting in a persistent way especially when I
don't use Gnome or Kde or Xfce? I tried LxQt once and apparently the
stupid thing has reset some configuration and now xdg-open starts
Qupzilla which I don't like. Before, some other stupid program has reset
it to Chromium which I don't like either.

How can I configure this, and do that in a way that is set persisently?
i.e. no program or package changes the setting to its own yard.

Well, there's a command line tool to change the current setting, called

First of all, you need to figure out how the .desktop file is called
of the browser you want to set. For example, Debian's Iceweasel has
iceweasel.desktop. [*] If the software you want to use as your browser
deosn't have a .desktop file (I suspect all browsers packaged within
Debian do, but I don't know), then you need to create one - see the
man page of xdg-desktop-menu for details. All desktop files are found
in /usr/share/applications for programs installed via Debian packages.

I'll assume Iceweasel here and use 'iceweasel.desktop' in the following
example. Replace it by your browser of choice if appropriate.

The 'default browser' is actually not just a single setting. There are
four main settings that are typically related to the question of
'default browser': what program is associated with the HTTP and HTTPS
protocols and what program should open HTML and XHTML files. The
typical checkboxes in programs such as Chromium that change this
setting typically change all four (maybe some others as well), but you
can in fact change them individually if you like. (Iceweasel/Firefox
also includes text/xml for generic XML files in this list, but I'm
going to skip that here, because I don't think it's sensible to open
generic XML files in browsers.)

The MIME types for HTML and XHTML are text/html and
application/xhtml+xml. Change the defaults for these MIME types to make
local (X)HTML files open in the browser of your choice.

There are some 'special' MIME types for protocols, the dummy MIME
category for that is x-scheme-handler/, so for HTTP and HTTPS you
have x-scheme-handler/http and x-scheme-handler/https - these are the
MIME types used when a remote website is accessed.

The following example will set Iceweasel as the default browser by
setting all four MIME types (but as I said, you can pick and choose

xdg-mime default iceweasel.desktop text/html application/xhtml+xml \
    x-scheme-handler/http x-scheme-handler/https

After that all XDG compliant programs will use the browser you've set
here as their default browser - you may test it with xdg-open.

Note: this does not preclude some renegade program from changing this
setting back to something else - other than sandboxing such programs
don't think there's any possibility to stop this, because all these
settings are just a couple of files in your home directory, so any
program you run could in principle change them. I try to avoid programs
that mess up my configuration without asking.

Btw. you can also query the current default, e.g.

xdg-mime query default x-scheme-handler/http
(ignores any additional arguments, at least on my box, so only pass
a single MIME type to it per call)

You can also change your default file mananger via the special
inode/directory MIME type - this is the program executed when clicking
on "open containing folder" in Iceweasel - but also other programs use
it. It doesn't even have to be an X11-based program, mc also works
(and it comes with a .desktop file).

Feels like things that have been established in a sane way (alternatives
system and sensible-browser) are now reverted to the chaos we used to
manage in the nineties :-(

Well, there's some logic behind it. The alternatives system can only be
set globally by the administrator, so it doesn't help on multi-user
systems. sensible-* is a Debianism, other than derivatives I don't
think this has been adopted by anybody else (I may be wrong), so if I
were upstream to some project, I would not want to rely on these
things. (Also, I can't extract any inforamtion and e.g. show the user
with which program I was going to open something, which is something
you might want to do in certain circumstances.) Also, sensible-*
requires an environment variable per thing you want to configure it
as a user, which is fine if you restrict yourself to just a couple of
things (there are only sensible-{editor,pager,browser}), but there are
a lot of other things you might want to automatically start, such as
your favorite image manipulation program, your favorite PDF reader,

The basic idea that this should be coupled with MIME types is sound in
my eyes: it's also nothing new, the mailcap(5) file also follows that
idea. The reason why the major desktops on Linux developed a different
solution is that there are certain shortcomings of the mailcap format.
Among others, it only allows for one program to be recognized as
handling a given filetype and automated changes to the file are hugely
problematic. (Which is why the XDG specification was designed with
automatic changes in mind.)

That isn't to say that there aren't any shortcomings of the XDG
standards on this topic - I just want to explain that a lot of thought
has gone into these specifications and there is a good reason for why
most things are the way they are there. (Admittedly, if we were to
redesign the whole thing in today's time, there would probably not be
XML involved.)

I think the main problem of the XDG standards (and in my eyes this is a
HUGE issue) is the lack of documentation. It's not that there's no
documentation at all (there is), but I would argue that it's impossible
to understand how the system works fully without reading the specs
themselves - and since most specs are kind of interrelated, this can
take a while. (They are not terribly long, but still.) And since most
direct consumers of the XDG spec are either desktop environment
developers - or at least developers that work on the major toolkits,
there is little knowledge of the spec outside a small group of people,
especially since most application developers (even if they don't use
the same desktop environments) reuse one of the major toolkits that
already has built-in support for this, so they don't have to know about
any of it.

But apart from the documentation problem, I mostly like the XDG
specification and I understand why it's done the way it is and why most
of the complexity is necessary. You can of course start to nitpick the
entire things, and there sure are parts which I would design in a
different manner today (less XML ;-)), but I do think it is an
improvement over what was there before.


[*] Caveat: KDE4 applications have their .desktop files in a kde4/
subdirectory of /usr/share/applications. In order to properly address
them you need to prefix the .desktop file name with kde4-, e.g.
kde4-konqueror.desktop. Note that some programs will strip the kde4-
prefix when displaying this information. (I'm not completely sure
anymore, but older I think Wheezy's version of xdg-mime query did
that.) But setting with the prefix will work properly. Only in case
you use any KDE4 applications.

Reply to: