x11uri

The problem

When you click on a link or file in an application, the relevant resource is opened in your prefered program for viewing resources of that type (e.g. your default browser for a URL). This magic is handled, on Linux, by a program like xdg-open. The application calls xdg-open and magically, the resource is opened.

However, if the application is running on a remote machine over SSH, it will call xdg-open on the remote machine, meaning that, for instance, a URL will be opened in the remote machine's web browser rather than on your own desktop.

The solution

x11uri is a system which allows programs to open URIs across an X session. So if you click on a link on your remote machine, it'll open in your local browser.

How to use it

Download it here

x11uri consists of two parts (packaged into the same binary for convenience): a server, which runs on your local machine and waits for URIs to be sent to it, and a client, which is invoked the same way as xdg-open et al. when opening a URL/file.

On your desktop, run x11uri in server mode after your X server has started. On the remote machine, whenever you open a URL, make sure that the x11uri binary is called instead of xdg-open or whatever your system uses. This can be accomplished in one of 3 ways:

  1. Replace xdg-open with the x11uri binary.
  2. Create a new directory, copy the x11uri binary into it (with the name "xdg-open") and add that directory to your $PATH on startup.
  3. Edit your default programs on the remote machine to set the x11uri client as the default application for all URIs.
Of the three, I would recommend option 2.

How it works

x11uri communicates using X11's window properties feature. On startup, the x11uri server takes ownership of the "URI" selection. When invoked, the x11uri client gets the owner of the "URI" selection, creates a zero-sized window, sets the "URI" property on that window to the value of the given URL, and sends a PropertyNotify event to the owner of the "URI" selection. The x11uri server, upon receiving a PropertyNotify event, retrieves the data from the given property on the window and calls the appropriate URI handling application (xdg-open or kde-open or start etc.).

I'm not sure if this is the best way to go about this. I'm pretty sure that my use of the PropertyNotify event is wrong (it seems like it's intented to inform programs about changes to the properties of their own windows, not other windows) but I'm not sure what a better way would be. If any X11 experts have any suggestions, feel free.